aboutsummaryrefslogtreecommitdiff
path: root/lib/std/testing.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-18 00:12:22 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-18 00:12:22 -0700
commitf3f5a5d05b7056aceb408b701613242d053019ab (patch)
treeacb912950d734b0c25b38c1ae82a8558d1313057 /lib/std/testing.zig
parent69d78bdae4a5d0ec5877add5936ae8e9daf09140 (diff)
downloadzig-f3f5a5d05b7056aceb408b701613242d053019ab.tar.gz
zig-f3f5a5d05b7056aceb408b701613242d053019ab.zip
stage2: improve `@typeName`
* make it always return a fully qualified name. stage1 is inconsistent about this. * AstGen: fix anon_name_strategy to correctly be `func` when anon type creation happens in the operand of the return expression. * Sema: implement type names for the "function" naming strategy. * Put "enum", "union", "opaque", or "struct" in place of "anon" when creating respective anonymous Decl names. * std.testing: add `expectStringStartsWith`. Didn't end up using it after all. Also this enables the real test runner for stage2 LLVM backend (sans wasm32) since it works now.
Diffstat (limited to 'lib/std/testing.zig')
-rw-r--r--lib/std/testing.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index c35de990ef..5049218c90 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -445,6 +445,26 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void {
}
}
+pub fn expectStringStartsWith(actual: []const u8, expected_starts_with: []const u8) !void {
+ if (std.mem.startsWith(u8, actual, expected_starts_with))
+ return;
+
+ const shortened_actual = if (actual.len >= expected_starts_with.len)
+ actual[0..expected_starts_with.len]
+ else
+ actual;
+
+ print("\n====== expected to start with: =========\n", .{});
+ printWithVisibleNewlines(expected_starts_with);
+ print("\n====== instead ended with: ===========\n", .{});
+ printWithVisibleNewlines(shortened_actual);
+ print("\n========= full output: ==============\n", .{});
+ printWithVisibleNewlines(actual);
+ print("\n======================================\n", .{});
+
+ return error.TestExpectedStartsWith;
+}
+
pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void {
if (std.mem.endsWith(u8, actual, expected_ends_with))
return;