aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/src.zig
blob: 61c0467eb7fa2574829ed55d69148381f5107587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fn doTheTest() !void {
    const src = @src(); // do not move

    try expect(src.line == 2);
    try expect(src.column == 17);
    try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest"));
    try expect(std.mem.endsWith(u8, src.file, "src.zig"));
    try expect(src.fn_name[src.fn_name.len] == 0);
    try expect(src.file[src.file.len] == 0);
    if (!std.mem.eql(u8, src.module, "test") and !std.mem.eql(u8, src.module, "root")) return error.TestFailure;
}

const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const expectEqualStrings = std.testing.expectEqualStrings;

test "@src" {
    if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;

    try doTheTest();
}

test "@src used as a comptime parameter" {
    const S = struct {
        fn Foo(comptime src: std.builtin.SourceLocation) type {
            return struct {
                comptime {
                    _ = src;
                }
            };
        }
    };
    const T1 = S.Foo(@src());
    const T2 = S.Foo(@src());
    try expect(T1 != T2);
}

test "@src in tuple passed to anytype function" {
    if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; // TODO

    const S = struct {
        fn Foo(a: anytype) u32 {
            return a[0].line;
        }
    };
    const l1 = S.Foo(.{@src()});
    const l2 = S.Foo(.{@src()});
    try expect(l1 != l2);
}