Skip to content

assertions

Modules:

Classes:

Functions:

AssertionFailureReport dataclass

AssertionFailureReport(
    source: str, line: int, col: int, message: str
)

build_assertions_runtime_feature

build_assertions_runtime_feature() -> RuntimeFeature
Source code in src/irx/builder/runtime/assertions/feature.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@typechecked
def build_assertions_runtime_feature() -> RuntimeFeature:
    """
    title: Build the assertion runtime feature specification.
    returns:
      type: RuntimeFeature
    """
    runtime_root = Path(__file__).resolve().parent
    native_root = runtime_root / "native"
    return RuntimeFeature(
        name=ASSERT_RUNTIME_FEATURE_NAME,
        symbols={
            ASSERT_FAILURE_SYMBOL_NAME: ExternalSymbolSpec(
                ASSERT_FAILURE_SYMBOL_NAME,
                _declare_assert_failure,
            ),
        },
        artifacts=(
            NativeArtifact(
                kind="c_source",
                path=native_root / "irx_assert_runtime.c",
                include_dirs=(native_root,),
                compile_flags=("-std=c99",),
            ),
        ),
    )

parse_assert_failure_line

parse_assert_failure_line(
    line: str,
) -> AssertionFailureReport | None
Source code in src/irx/builder/runtime/assertions/reporting.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@public
@typechecked
def parse_assert_failure_line(line: str) -> AssertionFailureReport | None:
    """
    title: Parse one machine-readable assertion failure line.
    parameters:
      line:
        type: str
    returns:
      type: AssertionFailureReport | None
    """
    stripped = line.strip()
    prefix = f"{ASSERT_FAILURE_PREFIX}|"
    if not stripped.startswith(prefix):
        return None

    parts = stripped.split("|", ASSERT_FAILURE_FIELD_COUNT - 1)
    if len(parts) != ASSERT_FAILURE_FIELD_COUNT:
        return None

    _, source, line_text, col_text, message = parts
    try:
        line_number = int(line_text)
        col_number = int(col_text)
    except ValueError:
        return None

    return AssertionFailureReport(
        source=_decode_assert_failure_field(source),
        line=line_number,
        col=col_number,
        message=_decode_assert_failure_field(message),
    )

parse_assert_failure_output

parse_assert_failure_output(
    stderr: str,
) -> AssertionFailureReport | None
Source code in src/irx/builder/runtime/assertions/reporting.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@public
@typechecked
def parse_assert_failure_output(stderr: str) -> AssertionFailureReport | None:
    """
    title: Parse the first machine-readable assertion failure from stderr.
    parameters:
      stderr:
        type: str
    returns:
      type: AssertionFailureReport | None
    """
    for line in stderr.splitlines():
        parsed = parse_assert_failure_line(line)
        if parsed is not None:
            return parsed
    return None