plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
343f2e1
— Peter John
2026-11-10T20:17:00+05:30
Errors in a loop lifted out of a test name the test too
compiler/checker/tests/checker/review_tests.rs
CHANGED
|
@@ -179,6 +179,21 @@ fn a_lowered_tests_errors_name_the_test() {
|
|
|
179
179
|
assert!(!m.contains("__"), "{m}");
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
/// The same for an error in a loop lifted out of a test into a fn of its own.
|
|
183
|
+
#[test]
|
|
184
|
+
fn an_error_in_a_tests_loop_names_the_test() {
|
|
185
|
+
let source = plum_test_support::load(
|
|
186
|
+
"test_loop_names",
|
|
187
|
+
"import std/Int\nimport std/Str\nimport std/Option\n\nstruct Cell<T>(mut v: Option<T>)\n\ntest \"loops\"\n c := Cell(v: None)\n for i := range 3\n c.v = Some(i)\n for i := range 3\n c.v = Some(\"x\")\n assert c.v.isSome()\n",
|
|
188
|
+
)
|
|
189
|
+
.expect("loads");
|
|
190
|
+
let program = plum_core::tests_lower::lowerTests(&source);
|
|
191
|
+
let es = plum_checker::checkProgram(&program.source).0.expect_err("a type error");
|
|
192
|
+
let m = &es[0].message;
|
|
193
|
+
assert!(m.contains("test \"loops\""), "{m}");
|
|
194
|
+
assert!(!m.contains("__"), "{m}");
|
|
195
|
+
}
|
|
196
|
+
|
|
182
197
|
#[test]
|
|
183
198
|
fn an_enum_or_unknown_name_with_fields_is_no_constructor() {
|
|
184
199
|
errorWith("enum E =\n | A(n: Int)\n | B(s: Int)\n\nfun k(e: E) -> E = E(..e, n: 3)", "'E' is an enum: build one of its variants (A, B)");
|
compiler/core/src/diag.rs
CHANGED
|
@@ -82,7 +82,8 @@ fn testNames(text: &str) -> String {
|
|
|
82
82
|
while let Some(at) = out.find("fn '__test_") {
|
|
83
83
|
let name_start = at + "fn '".len();
|
|
84
84
|
let Some(len) = out[name_start..].find('\'') else { break };
|
|
85
|
+
// A loop lifted out of a test is named after it (`__test_0` + a mark + a suffix).
|
|
85
|
-
let internal = out[name_start..name_start + len].
|
|
86
|
+
let internal: String = out[name_start..name_start + len].chars().take_while(|c| c.is_alphanumeric() || *c == '_').collect();
|
|
86
87
|
let Some(shown) = crate::tests_lower::testDisplayName(&internal) else { break };
|
|
87
88
|
out.replace_range(at..name_start + len + 1, &shown);
|
|
88
89
|
}
|