test harness: show annotated case name when translate-c test fails

This commit is contained in:
Andrew Kelley 2020-01-07 13:40:17 -05:00
parent 2933a8241a
commit 4e4ba6c3e1
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
4 changed files with 15 additions and 4 deletions

View File

@ -957,7 +957,7 @@ pub const Builder = struct {
}
}
pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
pub fn execFromStep(self: *Builder, argv: []const []const u8, src_step: ?*Step) ![]u8 {
assert(argv.len != 0);
if (self.verbose) {
@ -967,16 +967,19 @@ pub const Builder = struct {
var code: u8 = undefined;
return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
error.FileNotFound => {
if (src_step) |s| warn("{}...", .{s.name});
warn("Unable to spawn the following command: file not found\n", .{});
printCmd(null, argv);
std.os.exit(@truncate(u8, code));
},
error.ExitCodeFailure => {
if (src_step) |s| warn("{}...", .{s.name});
warn("The following command exited with error code {}:\n", .{code});
printCmd(null, argv);
std.os.exit(@truncate(u8, code));
},
error.ProcessTerminated => {
if (src_step) |s| warn("{}...", .{s.name});
warn("The following command terminated unexpectedly:\n", .{});
printCmd(null, argv);
std.os.exit(@truncate(u8, code));
@ -985,6 +988,10 @@ pub const Builder = struct {
};
}
pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
return self.execFromStep(argv, null);
}
pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {
self.search_prefixes.append(search_prefix) catch unreachable;
}
@ -2133,7 +2140,7 @@ pub const LibExeObjStep = struct {
try zig_args.append("--cache");
try zig_args.append("on");
const output_path_nl = try builder.exec(zig_args.toSliceConst());
const output_path_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step);
const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
if (self.output_dir) |output_dir| {

View File

@ -19,7 +19,7 @@ pub const TranslateCStep = struct {
pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
const self = builder.allocator.create(TranslateCStep) catch unreachable;
self.* = TranslateCStep{
.step = Step.init("zig translate-c", builder.allocator, make),
.step = Step.init("translate-c", builder.allocator, make),
.builder = builder,
.source = source,
.output_dir = null,
@ -73,7 +73,7 @@ pub const TranslateCStep = struct {
try argv_list.append(self.source.getPath(self.builder));
const output_path_nl = try self.builder.exec(argv_list.toSliceConst());
const output_path_nl = try self.builder.execFromStep(argv_list.toSliceConst(), &self.step);
const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
self.out_basename = fs.path.basename(output_path);

View File

@ -91,9 +91,12 @@ pub const RunTranslatedCContext = struct {
.basename = case.sources.toSliceConst()[0].filename,
},
});
translate_c.step.name = b.fmt("{} translate-c", .{annotated_case_name});
const exe = translate_c.addExecutable();
exe.step.name = b.fmt("{} build-exe", .{annotated_case_name});
exe.linkLibC();
const run = exe.run();
run.step.name = b.fmt("{} run", .{annotated_case_name});
if (!case.allow_warnings) {
run.expectStdErrEqual("");
}

View File

@ -114,6 +114,7 @@ pub const TranslateCContext = struct {
.basename = case.sources.toSliceConst()[0].filename,
},
});
translate_c.step.name = annotated_case_name;
translate_c.setTarget(case.target);
const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());