FileCheck

1.0.3 · active · verified Thu Apr 16

FileCheck is a Python-native clone of LLVM's FileCheck tool, designed for flexible and powerful pattern matching in text. It allows developers to define a sequence of regular expression-based checks against a source buffer, enabling robust testing of compiler outputs, log files, or any structured text. The current version is 1.0.3, and it maintains an active release cadence with regular bug fixes and new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `filecheck` library to validate text against a series of `CHECK` directives. It covers basic `CHECK`, `CHECK-NEXT`, `CHECK-NOT`, and `CHECK-LABEL` directives, error handling, and using custom `check_prefixes`.

import filecheck
from filecheck import FileCheck, FileCheckException

# 1. Define the buffer (the text to be checked)
my_buffer = """
Hello, World!
This is line 2.
    Another line.
Final line.
"""

# 2. Define the FileCheck directives (the checks to run)
my_checks = """
CHECK: Hello, World!
CHECK-NEXT: This is line 2.
CHECK-NOT: hidden_text
CHECK: Another line.
CHECK-LABEL: Final line.
"""

# 3. Instantiate and run FileCheck
try:
    checker = FileCheck(buffer=my_buffer, checks=my_checks)
    checker.run()
    print("FileCheck passed successfully!")
except FileCheckException as e:
    print(f"FileCheck failed: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

# Example with specific prefixes
my_checks_with_prefix = """
MYPREFIX: Hello, World!
MYPREFIX-NEXT: This is line 2.
"""
try:
    checker_prefix = FileCheck(buffer=my_buffer, checks=my_checks_with_prefix, check_prefixes=["MYPREFIX"])
    checker_prefix.run()
    print("FileCheck with custom prefix passed successfully!")
except FileCheckException as e:
    print(f"FileCheck with custom prefix failed: {e}")

view raw JSON →