### Basic Python Test with littlecheck Source: https://github.com/ridiculousfish/littlecheck/blob/master/README.md This example demonstrates a basic test for the Python interpreter using littlecheck. It shows how to specify a run command and verify standard output lines. The `%s` placeholder is substituted with the path to the test file. ```python # RUN: /usr/bin/python3 %s print("abc") # CHECK: abc print("%x"%(16**3)) # CHECK: 1000 for i in range(3): print(i) # CHECK: 0 # CHECK: 1 # CHECK: 2 ``` -------------------------------- ### Makefile Integration for littlecheck Tests Source: https://context7.com/ridiculousfish/littlecheck/llms.txt Provides examples of how to integrate littlecheck tests into a Makefile. It shows targets for running tests with default progress and with forced color output. ```makefile PYTHON ?= python3 LITTLECHECK = ./littlecheck/littlecheck.py test: $(PYTHON) $(LITTLECHECK) --progress test/files/*.py test-verbose: $(PYTHON) $(LITTLECHECK) --progress --force-color test/files/*.py .PHONY: test test-verbose ``` -------------------------------- ### Ruby Test Capturing Stdout and Stderr with littlecheck Source: https://github.com/ridiculousfish/littlecheck/blob/master/README.md This Ruby example demonstrates how littlecheck can capture and verify output from both standard output (`stdout`) and standard error (`stderr`) streams. It uses `# CHECK` for stdout and `# CHECKERR` for stderr. ```ruby # RUN: /usr/bin/ruby %s $stdout.puts "this goes to stdout" $stderr.puts "this goes to stderr" # CHECK: this goes to stdout # CHECKERR: this goes to stderr ``` -------------------------------- ### Custom Substitutions with -s Option (Bash) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The `-s` or `--substitute` option allows defining custom substitutions used in RUN lines within test files. Multiple substitutions can be specified. This example shows defining 'bash' and 'python' substitutions. ```bash # Define custom substitutions ./littlecheck/littlecheck.py -s bash=/bin/bash -s python=/usr/bin/python3 test.py # Use substitution in test file: # RUN: %bash -c "echo hello" # RUN: %python %s ``` -------------------------------- ### Conditional Test Execution with REQUIRES Directive (Shell) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The REQUIRES directive executes shell commands to check preconditions. If any REQUIRES command returns a non-zero exit code, the test is skipped. This example shows how to conditionally run a test on macOS and only if git is installed. ```shell # RUN: /bin/sh %s # Only run this test on macOS: # REQUIRES: test $(uname) = Darwin # Only run if git is installed: # REQUIRES: command -v git echo "Running macOS-specific test with git" # CHECK: Running macOS-specific test with git ``` -------------------------------- ### Specify Commands to Execute with RUN Directive (Python) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The RUN directive specifies the shell command to execute for testing. The `%s` placeholder is replaced with the test file's path. If no RUN directive is present, the file's shebang is used. This example demonstrates a basic Python script execution. ```python # RUN: /usr/bin/python3 %s from __future__ import print_function print("Hello, World!") # CHECK: Hello, World! print("The answer is 42") # CHECK: The answer is 42 ``` -------------------------------- ### Test a Single File with Python API (check_path) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The `check_path` function in the littlecheck Python API tests a single file. It accepts a file path, a dictionary of substitutions, a configuration object, and a callback function to handle failures. This example demonstrates configuring the checker and processing results. ```python import littlecheck # Configure the checker config = littlecheck.Config() config.colorize = True config.progress = True # Define substitutions (%s is the file path, %% escapes to %) subs = {"%": "%", "s": "test.py"} # Collect failures failures = [] # Run the test success = littlecheck.check_path( "test.py", subs, config, failures.append # Failure handler callback ) # Process results if success: print("All tests passed!") else: for failure in failures: print(failure.message()) ``` -------------------------------- ### Flexible Matching with Regular Expressions (Python) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt littlecheck supports regular expressions for flexible pattern matching within CHECK directives. Patterns are enclosed in `{{` and `}}` and follow Python's `re` module syntax. This example demonstrates matching numeric and formatted strings. ```python # RUN: /usr/bin/python3 %s import sys print(str(3 ** 64)) # CHECK: {{}}\d+ print("Process ID: 12345") # CHECK: Process ID: {{}}\d+ print("Timestamp: 2024-01-15 14:30:00") # CHECK: Timestamp: {{}}\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}} ``` -------------------------------- ### Shebang Fallback for Execution (Python) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt When no RUN directive is specified in a test file, littlecheck automatically uses the file's shebang line to determine how to execute the script. This example demonstrates a Python script using a shebang. ```python #!/usr/bin/python3 print("Using shebang for execution") # CHECK: Using shebang for execution print("No RUN directive needed") # CHECK: No RUN directive needed ``` -------------------------------- ### Test from File Object with Python API (check_file) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The `check_file` function in the littlecheck Python API allows testing from an open file object. This is useful for testing dynamically generated content or input from stdin. This example shows its basic usage with an `io.StringIO` object. ```python import io import littlecheck # Example usage with io.StringIO (not a complete test, just demonstrating the function signature) # file_obj = io.StringIO("# RUN: echo hello\n# CHECK: hello") # config = littlecheck.Config() # failures = [] # success = littlecheck.check_file(file_obj, {}, config, failures.append) ``` -------------------------------- ### Verify stdout Output with CHECK Directive (Python) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The CHECK directive asserts expected lines on standard output. Each CHECK must match a line sequentially. Empty output lines are ignored. This example shows multiple CHECK directives verifying sequential output. ```python # RUN: /usr/bin/python3 %s import sys print("abc") # CHECK: abc print("%x" % (16 ** 3)) # CHECK: 1000 for i in range(3): print(i) # CHECK: 0 # CHECK: 1 # CHECK: 2 ``` -------------------------------- ### Verify stderr Output with CHECKERR Directive (Ruby) Source: https://context7.com/ridiculousfish/littlecheck/llms.txt The CHECKERR directive functions similarly to CHECK but verifies output on standard error. This is useful for testing programs that produce output on both stdout and stderr streams. This example uses Ruby. ```ruby # RUN: /usr/bin/ruby %s $stdout.puts "this goes to stdout" $stderr.puts "this goes to stderr" # CHECK: this goes to stdout # CHECKERR: this goes to stderr ``` -------------------------------- ### Python Test with Regular Expressions using littlecheck Source: https://github.com/ridiculousfish/littlecheck/blob/master/README.md This Python example showcases littlecheck's support for regular expressions within `# CHECK` directives. It uses Python's `re` syntax, enclosed in double curly braces, to match patterns in the output, such as a sequence of digits. ```python # RUN: /usr/bin/python3 %s print("A big number: ", 2**64) # CHECK: A big number: {{\d+L}} ``` -------------------------------- ### Shell Script with Conditional Test Execution using littlecheck Source: https://github.com/ridiculousfish/littlecheck/blob/master/README.md This shell script example illustrates how to use the `# REQUIRES` directive in littlecheck to conditionally skip tests. It shows how to check for specific operating system conditions (e.g., macOS) or the presence of commands (e.g., `git`). ```shell # RUN: /bin/sh %s # Only run this test on macOS: # REQUIRES: test $(uname) = Darwin # Only run it if git is installed # REQUIRES: command -v git ``` -------------------------------- ### Basic Command Line Usage of littlecheck Source: https://context7.com/ridiculousfish/littlecheck/llms.txt This section outlines the basic command-line interface for running littlecheck against test files. It covers running single or multiple files, and options for progress output and forcing color. ```bash # Run a single test file ./littlecheck/littlecheck.py test.py # Run multiple test files ./littlecheck/littlecheck.py test1.py test2.py test3.py # Show progress output with timing information ./littlecheck/littlecheck.py --progress test.py # Force color output even when not connected to a terminal ./littlecheck/littlecheck.py --force-color test.py ``` -------------------------------- ### Run and Check File Content with littlecheck Source: https://context7.com/ridiculousfish/littlecheck/llms.txt This snippet demonstrates how to use the littlecheck.check_file function to test content within a file-like object. It defines test content, creates a StringIO object, and then calls check_file with specific substitutions and configuration. ```python import io import littlecheck # Create test content test_content = """# RUN: /usr/bin/python3 -c \"print('hello')\"\n# CHECK: hello\n""" # Create file-like object test_file = io.StringIO(test_content) config = littlecheck.Config() subs = {"%": "%", "s": "inline_test"} failures = [] success = littlecheck.check_file( test_file, "inline_test", subs, config, failures.append ) print(f"Test {'passed' if success else 'failed'}") ``` -------------------------------- ### Configure littlecheck Test Behavior with Config Class Source: https://context7.com/ridiculousfish/littlecheck/llms.txt Demonstrates configuring littlecheck's behavior using the Config class. Options include enabling verbose output, ANSI color codes, progress indicators, and accessing color dictionaries for custom formatting. ```python import littlecheck config = littlecheck.Config() # Enable verbose output (prints executed commands) config.verbose = True # Enable ANSI color codes in output config.colorize = True # Show file names being tested config.progress = True # Get color dictionary for custom formatting colors = config.colors() print(f"{colors['GREEN']}Success{colors['RESET']}") print(f"{colors['RED']}Failure{colors['RESET']}") ``` -------------------------------- ### Concurrent Testing with littlecheck Async API Source: https://context7.com/ridiculousfish/littlecheck/llms.txt Shows how to use the asynchronous API of littlecheck for concurrent test execution. It utilizes asyncio to run multiple tests defined by file paths in parallel and gathers their results. ```python import asyncio import littlecheck async def run_tests(): config = littlecheck.Config() subs = {"%": "%"} failures = [] # Run multiple tests concurrently tasks = [] for test_file in ["test1.py", "test2.py", "test3.py"]: subs_copy = subs.copy() subs_copy["s"] = test_file tasks.append( littlecheck.check_path_async( test_file, subs_copy, config, failures.append ) ) results = await asyncio.gather(*tasks) return all(results) # Run the async tests success = asyncio.run(run_tests()) ``` -------------------------------- ### pytest Integration for littlecheck Tests Source: https://context7.com/ridiculousfish/littlecheck/llms.txt Demonstrates creating a pytest wrapper class to run littlecheck tests within a pytest test suite. It includes a helper method `run_test` to execute individual littlecheck tests and assert their success or expected skips. ```python import unittest import io import littlecheck class LittlecheckTest(unittest.TestCase): def run_test(self, name, expect_skip=False): """Run a single littlecheck test.""" test_path = f"{name}.py" subs = {"%": "%", "s": test_path} conf = littlecheck.Config() failures = [] success = littlecheck.check_path( test_path, subs, conf, failures.append ) if expect_skip: self.assertEqual(success, littlecheck.SKIP) else: self.assertTrue( success, msg="\n".join(f.message() for f in failures) ) def test_basic_output(self): self.run_test("python_ok") def test_conditional_skip(self): self.run_test("skip", expect_skip=True) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.