From 14acc65675a35f838b5e73aeaca595ced0c10a0c Mon Sep 17 00:00:00 2001 From: Vexu Date: Thu, 18 Jun 2020 21:03:08 +0300 Subject: [PATCH] add tests for `@src` --- test/compile_errors.zig | 8 ++++++++ test/stage1/behavior.zig | 1 + test/stage1/behavior/src.zig | 15 +++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 test/stage1/behavior/src.zig diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 278d66ab9f1a365424687947b19f9e8cf7282731..3f898cc337730baf5acbf02b90f39e980be18283 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,14 @@ const tests = @import("tests.zig"); const std = @import("std"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add("@src outside function", + \\comptime { + \\ @src(); + \\} + , &[_][]const u8{ + "tmp.zig:2:5: error: @src outside function", + }); + cases.add("call assigned to constant", \\const Foo = struct { \\ x: i32, diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 1620aa52df2f2021f9d8412f5efff12ae86d0f7c..8c567fa99f57e0aa9fd437c09ca0997ad82fc00f 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -131,4 +131,5 @@ comptime { } _ = @import("behavior/while.zig"); _ = @import("behavior/widening.zig"); + _ = @import("behavior/src.zig"); } diff --git a/test/stage1/behavior/src.zig b/test/stage1/behavior/src.zig new file mode 100644 index 0000000000000000000000000000000000000000..eec11543745040da7a5d8511bbd01f98e52b56e5 --- /dev/null +++ b/test/stage1/behavior/src.zig @@ -0,0 +1,15 @@ +const std = @import("std"); +const expect = std.testing.expect; + +test "@src" { + doTheTest(); +} + +fn doTheTest() void { + const src = @src(); + + expect(src.line == 9); + expect(src.column == 17); + expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); + expect(std.mem.endsWith(u8, src.file, "src.zig")); +} -- 2.54.0