authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-01 07:55:38+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-01 12:10:57+01:00
log493e37fa50e59b6fb8db086ea8b2f896d455314f
tree150c38eca4ce17d9e519ad792bbfb405809efeb9
parentc1a5caa4545264b476951e844818f2abe103f41c
signaturelock-open Commit is signed but in an unrecognized format.

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`.

1 files changed, 17 insertions(+), 3 deletions(-)

test/src/Cases.zig+17-3
......@@ -400,7 +400,7 @@ fn addFromDirInner(
400400 for (targets) |target_query| {
401401 const output = try manifest.trailingLinesSplit(ctx.arena);
402402 try ctx.translate.append(.{
403 .name = std.fs.path.stem(filename),
403 .name = try caseNameFromPath(ctx.arena, filename),
404404 .c_frontend = c_frontend,
405405 .target = b.resolveTargetQuery(target_query),
406406 .link_libc = link_libc,
......@@ -416,7 +416,7 @@ fn addFromDirInner(
416416 for (targets) |target_query| {
417417 const output = try manifest.trailingSplit(ctx.arena);
418418 try ctx.translate.append(.{
419 .name = std.fs.path.stem(filename),
419 .name = try caseNameFromPath(ctx.arena, filename),
420420 .c_frontend = c_frontend,
421421 .target = b.resolveTargetQuery(target_query),
422422 .link_libc = link_libc,
......@@ -454,7 +454,7 @@ fn addFromDirInner(
454454
455455 const next = ctx.cases.items.len;
456456 try ctx.cases.append(.{
457 .name = std.fs.path.stem(filename),
457 .name = try caseNameFromPath(ctx.arena, filename),
458458 .import_path = std.fs.path.dirname(filename),
459459 .backend = backend,
460460 .files = .init(ctx.arena),
......@@ -1138,3 +1138,17 @@ fn knownFileExtension(filename: []const u8) bool {
11381138 if (it.next() != null) return false;
11391139 return false;
11401140}
1141
1142/// `path` is a path relative to the root case directory.
1143/// e.g. `compile_errors/undeclared_identifier.zig`
1144/// The case name is computed by removing the extension and substituting path separators for dots.
1145/// e.g. `compile_errors.undeclared_identifier`
1146/// Including the directory components makes `-Dtest-filter` more useful, because you can filter
1147/// based on subdirectory; e.g. `-Dtest-filter=compile_errors` to run the compile error tets.
1148fn caseNameFromPath(arena: Allocator, path: []const u8) Allocator.Error![]const u8 {
1149 const ext_len = std.fs.path.extension(path).len;
1150 const path_sans_ext = path[0 .. path.len - ext_len];
1151 const result = try arena.dupe(u8, path_sans_ext);
1152 std.mem.replaceScalar(u8, result, std.fs.path.sep, '.');
1153 return result;
1154}