rtk-ai/rtk · error

invalid ctest time regex

Error message

invalid ctest time regex

What it means

Panic from the .expect() on TIME_RE in src/cmds/system/ctest_cmd.rs, which reads the total duration from ctest's 'Total Test time (real) = N sec' line. The regex compiles lazily inside a LazyLock; invalid pattern syntax aborts with this message instead of returning an error. This is an internal invariant guard; the shipped pattern is valid, so it fires only when the source was modified incorrectly.

Solutions

  1. Fix the TIME_RE literal in src/cmds/system/ctest_cmd.rs (keep `(real)` escaped as \(real\))
  2. Run `cargo test ctest` to confirm the static compiles
  3. Work around with `rtk proxy ctest ...` for raw output
  4. Rebuild the binary after fixing

Example fix

// before (broken: real parens unescaped)
Regex::new(r"^\s*Total Test time (real)\s+=\s+([\d.]+)\s+sec").expect("invalid ctest time regex")
// after
Regex::new(r"^\s*Total Test time \(real\)\s+=\s+([\d.]+)\s+sec").expect("invalid ctest time regex")
Defensive patterns

Strategy: validation

Validate before calling

assert!(regex::Regex::new(r"^\s*Total Test time \(real\)\s+=\s+([\d.]+)\s+sec").is_ok(), "TIME_RE must compile");

Prevention

When it happens

Trigger: First access of TIME_RE during `rtk ctest` output filtering, when a source edit made the regex syntactically invalid (e.g. unescaped parenthesis removed from \(real\)).

Common situations: Hand-edit typo in the time regex; broken merge; building with a regex crate whose syntax rules reject the pattern.

Related errors


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

Appendix: source

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

    )
    .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")
});

#[derive(Debug, Clone)]
struct TestCase {
    number: u32,
    name: String,
    status: String,
    reason: Option<String>,
    duration: f64,
    line_index: usize,
    counter_total: Option<u32>,
}

#[derive(Debug)]
struct ParsedTests {
    tests: Vec<TestCase>,
    result_lines: Vec<usize>,
    run_total: Option<u32>,

View on GitHub (pinned to 0924356b4c)