mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
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`.
This commit is contained in:
parent
c1a5caa454
commit
493e37fa50
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user