diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-06-01 07:55:38 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-06-01 12:10:57 +0100 |
| commit | 493e37fa50e59b6fb8db086ea8b2f896d455314f (patch) | |
| tree | 150c38eca4ce17d9e519ad792bbfb405809efeb9 /test/src/Cases.zig | |
| parent | c1a5caa4545264b476951e844818f2abe103f41c (diff) | |
| download | zig-493e37fa50e59b6fb8db086ea8b2f896d455314f.tar.gz zig-493e37fa50e59b6fb8db086ea8b2f896d455314f.zip | |
cases: include dirname in case names
For instance, the file 'cases/compile_errors/undeclared_identifier.zig'
now corresponds to test name 'compile_errors.undeclared_identifier'.
This is useful because you can now filter based on the case dirname
using `-Dtest-filter`.
Diffstat (limited to 'test/src/Cases.zig')
| -rw-r--r-- | test/src/Cases.zig | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/test/src/Cases.zig b/test/src/Cases.zig index aeb71ce95b..a36f4f3f7c 100644 --- a/test/src/Cases.zig +++ b/test/src/Cases.zig @@ -400,7 +400,7 @@ fn addFromDirInner( for (targets) |target_query| { const output = try manifest.trailingLinesSplit(ctx.arena); try ctx.translate.append(.{ - .name = std.fs.path.stem(filename), + .name = try caseNameFromPath(ctx.arena, filename), .c_frontend = c_frontend, .target = b.resolveTargetQuery(target_query), .link_libc = link_libc, @@ -416,7 +416,7 @@ fn addFromDirInner( for (targets) |target_query| { const output = try manifest.trailingSplit(ctx.arena); try ctx.translate.append(.{ - .name = std.fs.path.stem(filename), + .name = try caseNameFromPath(ctx.arena, filename), .c_frontend = c_frontend, .target = b.resolveTargetQuery(target_query), .link_libc = link_libc, @@ -454,7 +454,7 @@ fn addFromDirInner( const next = ctx.cases.items.len; try ctx.cases.append(.{ - .name = std.fs.path.stem(filename), + .name = try caseNameFromPath(ctx.arena, filename), .import_path = std.fs.path.dirname(filename), .backend = backend, .files = .init(ctx.arena), @@ -1138,3 +1138,17 @@ fn knownFileExtension(filename: []const u8) bool { if (it.next() != null) return false; return false; } + +/// `path` is a path relative to the root case directory. +/// e.g. `compile_errors/undeclared_identifier.zig` +/// The case name is computed by removing the extension and substituting path separators for dots. +/// e.g. `compile_errors.undeclared_identifier` +/// Including the directory components makes `-Dtest-filter` more useful, because you can filter +/// based on subdirectory; e.g. `-Dtest-filter=compile_errors` to run the compile error tets. +fn caseNameFromPath(arena: Allocator, path: []const u8) Allocator.Error![]const u8 { + const ext_len = std.fs.path.extension(path).len; + const path_sans_ext = path[0 .. path.len - ext_len]; + const result = try arena.dupe(u8, path_sans_ext); + std.mem.replaceScalar(u8, result, std.fs.path.sep, '.'); + return result; +} |
