rtk-ai/rtk · error

invalid ctest result regex

Error message

invalid ctest result regex

What it means

Panic from `.expect("invalid ctest result regex")` in a `LazyLock<Regex>` initializer in src/cmds/system/ctest_cmd.rs:28. The ctest filter compiles its per-test result-line regex once; if the pattern is syntactically invalid, the regex crate returns `Err`, the expect panics, and the module fails during first use (module-init failure) before any ctest output can be filtered.

Solutions

  1. Fix the regex literal — verify `(?s)` is at the start, all groups `(?: ... )` are balanced, and escapes like `\.` and `\s` are intact.
  2. Keep it in LazyLock (correct per repo rules) but validate the pattern with a unit test that touches the static so CI catches it before release.
  3. For resilience, prefer `Regex::new(...).unwrap_or_else(|e| panic!("invalid ctest result regex: {e}"))` so the syntax error message is preserved.

Example fix

// before
.expect("invalid ctest result regex")
// after
.unwrap_or_else(|e| panic!("invalid ctest result regex: {e} in pattern: {PAT}"))
Defensive patterns

Strategy: try-catch

Validate before calling

// force static init in a test so bad regexes fail CI
#[test]
fn ctest_regexes_initialize() {
    LazyLock::force(&TEST_RE);
    LazyLock::force(&RESULT_PREFIX_RE);
    LazyLock::force(&RESULT_TERMINATOR_RE);
}

Try / catch

Regex::new(PAT).unwrap_or_else(|e| panic!("invalid ctest result regex: {e}"))

Prevention

When it happens

Trigger: A syntax error in the hardcoded multi-line result pattern — e.g. the `(?s)` flag position, the `(?:\*{3})?` optional group, or a `\.{2,}` repetition escape being corrupted — triggers the panic at static initialization.

Common situations: Editing the pattern to match a new CMake/ctest result-line format and misplacing `(?s)` or a quantifier; because these are LazyLock statics, the failure manifests as an instant crash on the first filter call rather than at compile time.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/f422ae579c39bec6. Report an issue: GitHub.

Appendix: source

Thrown at src/cmds/system/ctest_cmd.rs:28

use crate::core::runner::{self, RunOptions};
use crate::core::truncate::{self, CAP_LIST, CAP_WARNINGS};
use crate::core::utils::{resolved_command, strip_ansi};

const MAX_SLOWEST: usize = 3;
const MAX_FAILURE_LINES: usize = CAP_WARNINGS;
const MAX_FAILURE_HEAD_LINES: usize = 2;
const MAX_FAILED_LIST_LINES: usize = CAP_LIST;
const MAX_DETECT_PREAMBLE_LINES: usize = 4;
// Failure entries carry a header plus up to `MAX_FAILURE_LINES` detail lines each,
// so this list deviates below `CAP_LIST`; the single-line skipped and raw-trailer
// lists keep the full cap.
const MAX_FAILED_BLOCK_ENTRIES: usize = truncate::reduced(CAP_LIST, 5);

static TEST_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(
        r"(?s)^\s*(?:\d+/(\d+)\s+)?Test\s+#(\d+):\s+(.+?)\s+\.{2,}\s*(?:\*{3})?\s*(.+?)\s+([\d.]+)\s+sec\s*$",
    )
    .expect("invalid ctest result regex")
});
static RESULT_PREFIX_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*(?:\d+/\d+\s+)?Test\s+#\d+:").expect("invalid ctest result prefix regex")
});
static RESULT_TERMINATOR_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"[\d.]+\s+sec\s*$").expect("invalid ctest result terminator regex")
});
static START_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*Start\s+(\d+):\s*(.*?)\s*$").expect("invalid ctest start regex")
});
static SUMMARY_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*\d+%\s+tests passed,\s+(\d+)\s+tests failed out of\s+(\d+)")
        .expect("invalid ctest summary regex")
});
static TIME_RE: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"^\s*Total Test time \(real\)\s+=\s+([\d.]+)\s+sec")
        .expect("invalid ctest time regex")
});

View on GitHub (pinned to 0924356b4c)