Skip to content

Commit 09503ed

Browse files
committed
improve lit config
1 parent 5f1e5bb commit 09503ed

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

lit.cfg.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import lit.formats
55

6-
config.name = "chroma-compile-fail"
6+
config.name = "chroma-test"
77

88
repo_root = Path(__file__).parent
99
config.test_source_root = repo_root / "test"
@@ -16,18 +16,32 @@
1616
clang_flags = f"-std=c++26 -freflection-latest {include_path}"
1717
gcc_flags = f"-std=c++26 -freflection {include_path}"
1818

19-
filecheck_defines = ""
19+
replacements = {
20+
"STATIC_ASSERT": r"CHECK: error: static assertion failed{{.*}}",
21+
"ERROR_HERE": r"CHECK: NEXT_LINE error",
22+
"ERROR": r"CHECK: error",
23+
"NEXT_LINE": r"{{.*}}:[[@LINE+1]]:{{[0-9]+}}:",
24+
}
25+
26+
def sed_escape(s: str) -> str:
27+
# escape for sed replacement (delimiter |)
28+
return s.replace("\\", r"\\").replace("|", r"\|").replace("&", r"\&")
29+
30+
parts = []
31+
for k, v in replacements.items():
32+
parts.append(f"-e 's|{k}|{sed_escape(v)}|g'")
33+
diag_replacements = "sed " + " ".join(parts)
2034

2135

2236
compiler = lit_config.params.get("compiler")
2337
if compiler == "clang":
2438
config.available_features.add("clang")
25-
config.substitutions.append(("%verify", f"not clang++ {clang_flags} %s 2>&1 | FileCheck {filecheck_defines} %s"))
39+
config.substitutions.append(("%verify", f"not clang++ {clang_flags} %s 2>&1 | FileCheck <({diag_replacements} %s)"))
2640
config.substitutions.append(("%compile", f"clang++ {clang_flags} %s 2>&1"))
2741
elif compiler == "gcc":
2842
config.available_features.add("gcc")
29-
config.substitutions.append(("%verify", f"not g++ {gcc_flags} %s 2>&1 | FileCheck {filecheck_defines} %s"))
43+
config.substitutions.append(("%verify", f"not g++ {gcc_flags} %s 2>&1 | FileCheck <({diag_replacements} %s)"))
3044
config.substitutions.append(("%compile", f"g++ {gcc_flags} %s 2>&1"))
3145
else:
3246
print(f"Invalid compiler. Select a compiler with -Dcompiler={{gcc,clang}}")
33-
sys.exit(1)
47+
sys.exit(1)

test/simple.verify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include "simple.hpp"
44

55
int main(){
6-
// CHECK: not a red function
6+
// STATIC_ASSERT: not a red function
77
b();
8-
8+
99
b(unchecked);
1010
}

0 commit comments

Comments
 (0)