2017-04-19 18:00:12 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const debug = std.debug;
|
|
|
|
const build = std.build;
|
|
|
|
const os = std.os;
|
|
|
|
const StdIo = os.ChildProcess.StdIo;
|
|
|
|
const Term = os.ChildProcess.Term;
|
2017-05-04 18:05:06 +00:00
|
|
|
const Buffer = std.Buffer;
|
2017-04-19 18:00:12 +00:00
|
|
|
const io = std.io;
|
|
|
|
const mem = std.mem;
|
|
|
|
const fmt = std.fmt;
|
2017-05-04 18:05:06 +00:00
|
|
|
const ArrayList = std.ArrayList;
|
2017-08-30 18:55:26 +00:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
const Mode = builtin.Mode;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 20:59:20 +00:00
|
|
|
const compare_output = @import("compare_output.zig");
|
|
|
|
const build_examples = @import("build_examples.zig");
|
|
|
|
const compile_errors = @import("compile_errors.zig");
|
|
|
|
const assemble_and_link = @import("assemble_and_link.zig");
|
|
|
|
const debug_safety = @import("debug_safety.zig");
|
|
|
|
const parseh = @import("parseh.zig");
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-08-30 18:55:26 +00:00
|
|
|
const TestTarget = struct {
|
|
|
|
os: builtin.Os,
|
|
|
|
arch: builtin.Arch,
|
|
|
|
environ: builtin.Environ,
|
|
|
|
};
|
|
|
|
|
|
|
|
const test_targets = []TestTarget {
|
|
|
|
TestTarget {
|
|
|
|
.os = builtin.Os.linux,
|
|
|
|
.arch = builtin.Arch.x86_64,
|
|
|
|
.environ = builtin.Environ.gnu,
|
|
|
|
},
|
|
|
|
TestTarget {
|
|
|
|
.os = builtin.Os.macosx,
|
|
|
|
.arch = builtin.Arch.x86_64,
|
|
|
|
.environ = builtin.Environ.unknown,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-04-19 20:59:20 +00:00
|
|
|
error TestFailed;
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
|
|
|
const cases = %%b.allocator.create(CompareOutputContext);
|
|
|
|
*cases = CompareOutputContext {
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-compare-output", "Run the compare output tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
};
|
|
|
|
|
|
|
|
compare_output.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
|
|
|
const cases = %%b.allocator.create(CompareOutputContext);
|
|
|
|
*cases = CompareOutputContext {
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-debug-safety", "Run the debug safety tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
};
|
|
|
|
|
|
|
|
debug_safety.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
|
|
|
const cases = %%b.allocator.create(CompileErrorContext);
|
|
|
|
*cases = CompileErrorContext {
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-compile-errors", "Run the compile error tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
};
|
|
|
|
|
|
|
|
compile_errors.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
|
|
|
const cases = %%b.allocator.create(BuildExamplesContext);
|
|
|
|
*cases = BuildExamplesContext {
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-build-examples", "Build the examples"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
};
|
|
|
|
|
|
|
|
build_examples.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
|
|
|
const cases = %%b.allocator.create(CompareOutputContext);
|
|
|
|
*cases = CompareOutputContext {
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-asm-link", "Run the assemble and link tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
};
|
|
|
|
|
|
|
|
assemble_and_link.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2017-04-19 20:59:20 +00:00
|
|
|
pub fn addParseHTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
|
|
|
const cases = %%b.allocator.create(ParseHContext);
|
|
|
|
*cases = ParseHContext {
|
|
|
|
.b = b,
|
|
|
|
.step = b.step("test-parseh", "Run the C header file parsing tests"),
|
|
|
|
.test_index = 0,
|
|
|
|
.test_filter = test_filter,
|
|
|
|
};
|
|
|
|
|
|
|
|
parseh.addCases(cases);
|
|
|
|
|
|
|
|
return cases.step;
|
|
|
|
}
|
|
|
|
|
2017-04-20 06:26:36 +00:00
|
|
|
pub fn addPkgTests(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8,
|
|
|
|
name:[] const u8, desc: []const u8) -> &build.Step
|
|
|
|
{
|
2017-08-18 17:51:16 +00:00
|
|
|
return addPkgTestsRaw(b, test_filter, root_src, name, desc, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addPkgTestsAlwaysLibc(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8,
|
|
|
|
name:[] const u8, desc: []const u8) -> &build.Step
|
|
|
|
{
|
|
|
|
return addPkgTestsRaw(b, test_filter, root_src, name, desc, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addPkgTestsRaw(b: &build.Builder, test_filter: ?[]const u8, root_src: []const u8,
|
|
|
|
name:[] const u8, desc: []const u8, always_link_libc: bool) -> &build.Step
|
|
|
|
{
|
|
|
|
const libc_bools = if (always_link_libc) []bool{true} else []bool{false, true};
|
2017-04-20 06:26:36 +00:00
|
|
|
const step = b.step(b.fmt("test-{}", name), desc);
|
2017-08-30 18:55:26 +00:00
|
|
|
for (test_targets) |test_target| {
|
|
|
|
const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
|
|
|
|
for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
|
|
|
|
for (libc_bools) |link_libc| {
|
|
|
|
if (link_libc and !is_native) {
|
|
|
|
// don't assume we have a cross-compiling libc set up
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const these_tests = b.addTest(root_src);
|
|
|
|
these_tests.setNamePrefix(b.fmt("{}-{}-{}-{}-{} ", name, @enumTagName(test_target.os),
|
|
|
|
@enumTagName(test_target.arch), @enumTagName(mode), if (link_libc) "c" else "bare"));
|
|
|
|
these_tests.setFilter(test_filter);
|
|
|
|
these_tests.setBuildMode(mode);
|
|
|
|
if (!is_native) {
|
|
|
|
these_tests.setTarget(test_target.arch, test_target.os, test_target.environ);
|
|
|
|
}
|
|
|
|
if (link_libc) {
|
|
|
|
these_tests.linkSystemLibrary("c");
|
|
|
|
}
|
|
|
|
step.dependOn(&these_tests.step);
|
2017-04-20 06:26:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
pub const CompareOutputContext = struct {
|
|
|
|
b: &build.Builder,
|
|
|
|
step: &build.Step,
|
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
const Special = enum {
|
|
|
|
None,
|
|
|
|
Asm,
|
|
|
|
DebugSafety,
|
|
|
|
};
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
const TestCase = struct {
|
|
|
|
name: []const u8,
|
2017-05-04 18:05:06 +00:00
|
|
|
sources: ArrayList(SourceFile),
|
2017-04-19 18:00:12 +00:00
|
|
|
expected_output: []const u8,
|
|
|
|
link_libc: bool,
|
2017-04-19 18:41:59 +00:00
|
|
|
special: Special,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
const SourceFile = struct {
|
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
|
|
|
%%self.sources.append(SourceFile {
|
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const RunCompareOutputStep = struct {
|
|
|
|
step: build.Step,
|
|
|
|
context: &CompareOutputContext,
|
|
|
|
exe_path: []const u8,
|
|
|
|
name: []const u8,
|
|
|
|
expected_output: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
|
|
|
|
pub fn create(context: &CompareOutputContext, exe_path: []const u8,
|
|
|
|
name: []const u8, expected_output: []const u8) -> &RunCompareOutputStep
|
|
|
|
{
|
|
|
|
const allocator = context.b.allocator;
|
|
|
|
const ptr = %%allocator.create(RunCompareOutputStep);
|
|
|
|
*ptr = RunCompareOutputStep {
|
|
|
|
.context = context,
|
|
|
|
.exe_path = exe_path,
|
|
|
|
.name = name,
|
|
|
|
.expected_output = expected_output,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.step = build.Step.init("RunCompareOutput", allocator, make),
|
|
|
|
};
|
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: &build.Step) -> %void {
|
|
|
|
const self = @fieldParentPtr(RunCompareOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
|
|
|
const full_exe_path = b.pathFromRoot(self.exe_path);
|
|
|
|
|
|
|
|
%%io.stderr.printf("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
var child = os.ChildProcess.spawn(full_exe_path, [][]u8{}, null, &b.env_map,
|
2017-04-19 18:00:12 +00:00
|
|
|
StdIo.Ignore, StdIo.Pipe, StdIo.Pipe, b.allocator) %% |err|
|
|
|
|
{
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
|
|
|
};
|
|
|
|
|
2017-04-22 15:36:42 +00:00
|
|
|
var stdout = Buffer.initNull(b.allocator);
|
|
|
|
var stderr = Buffer.initNull(b.allocator);
|
|
|
|
|
|
|
|
%%(??child.stdout).readAll(&stdout);
|
|
|
|
%%(??child.stderr).readAll(&stderr);
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
const term = child.wait() %% |err| {
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
|
|
|
};
|
|
|
|
switch (term) {
|
|
|
|
Term.Clean => |code| {
|
|
|
|
if (code != 0) {
|
|
|
|
%%io.stderr.printf("Process {} exited with error code {}\n", full_exe_path, code);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
else => {
|
|
|
|
%%io.stderr.printf("Process {} terminated unexpectedly\n", full_exe_path);
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
|
|
|
|
%%io.stderr.printf(
|
|
|
|
\\
|
|
|
|
\\========= Expected this output: =========
|
|
|
|
\\{}
|
|
|
|
\\================================================
|
|
|
|
\\{}
|
|
|
|
\\
|
|
|
|
, self.expected_output, stdout.toSliceConst());
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
%%io.stderr.printf("OK\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
const DebugSafetyRunStep = struct {
|
|
|
|
step: build.Step,
|
|
|
|
context: &CompareOutputContext,
|
|
|
|
exe_path: []const u8,
|
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
|
|
|
|
pub fn create(context: &CompareOutputContext, exe_path: []const u8,
|
|
|
|
name: []const u8) -> &DebugSafetyRunStep
|
|
|
|
{
|
|
|
|
const allocator = context.b.allocator;
|
|
|
|
const ptr = %%allocator.create(DebugSafetyRunStep);
|
|
|
|
*ptr = DebugSafetyRunStep {
|
|
|
|
.context = context,
|
|
|
|
.exe_path = exe_path,
|
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.step = build.Step.init("DebugSafetyRun", allocator, make),
|
|
|
|
};
|
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: &build.Step) -> %void {
|
|
|
|
const self = @fieldParentPtr(DebugSafetyRunStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
|
|
|
const full_exe_path = b.pathFromRoot(self.exe_path);
|
|
|
|
|
|
|
|
%%io.stderr.printf("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
var child = os.ChildProcess.spawn(full_exe_path, [][]u8{}, null, &b.env_map,
|
2017-04-19 18:41:59 +00:00
|
|
|
StdIo.Ignore, StdIo.Pipe, StdIo.Pipe, b.allocator) %% |err|
|
|
|
|
{
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
const term = child.wait() %% |err| {
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
|
|
|
};
|
|
|
|
|
|
|
|
const debug_trap_signal: i32 = 5;
|
|
|
|
switch (term) {
|
|
|
|
Term.Clean => |code| {
|
|
|
|
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
|
|
|
|
"but exited with return code {}\n", debug_trap_signal, code);
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
Term.Signal => |sig| {
|
|
|
|
if (sig != debug_trap_signal) {
|
|
|
|
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
|
|
|
|
"but instead signaled {}\n", debug_trap_signal, sig);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
else => {
|
|
|
|
%%io.stderr.printf("\nProgram expected to hit debug trap (signal {}) " ++
|
|
|
|
" but exited in an unexpected way\n", debug_trap_signal);
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
%%io.stderr.printf("OK\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
pub fn createExtra(self: &CompareOutputContext, name: []const u8, source: []const u8,
|
2017-04-19 18:41:59 +00:00
|
|
|
expected_output: []const u8, special: Special) -> TestCase
|
2017-04-19 18:00:12 +00:00
|
|
|
{
|
|
|
|
var tc = TestCase {
|
|
|
|
.name = name,
|
2017-05-04 18:05:06 +00:00
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
2017-04-19 18:00:12 +00:00
|
|
|
.expected_output = expected_output,
|
|
|
|
.link_libc = false,
|
2017-04-19 18:41:59 +00:00
|
|
|
.special = special,
|
2017-04-19 18:00:12 +00:00
|
|
|
};
|
2017-04-19 18:41:59 +00:00
|
|
|
const root_src_name = if (special == Special.Asm) "source.s" else "source.zig";
|
2017-04-19 18:00:12 +00:00
|
|
|
tc.addSourceFile(root_src_name, source);
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create(self: &CompareOutputContext, name: []const u8, source: []const u8,
|
|
|
|
expected_output: []const u8) -> TestCase
|
|
|
|
{
|
2017-04-19 18:41:59 +00:00
|
|
|
return createExtra(self, name, source, expected_output, Special.None);
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addC(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) {
|
|
|
|
var tc = self.create(name, source, expected_output);
|
|
|
|
tc.link_libc = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) {
|
|
|
|
const tc = self.create(name, source, expected_output);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addAsm(self: &CompareOutputContext, name: []const u8, source: []const u8, expected_output: []const u8) {
|
2017-04-19 18:41:59 +00:00
|
|
|
const tc = self.createExtra(name, source, expected_output, Special.Asm);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addDebugSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) {
|
|
|
|
const tc = self.createExtra(name, source, undefined, Special.DebugSafety);
|
2017-04-19 18:00:12 +00:00
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCase(self: &CompareOutputContext, case: &const TestCase) {
|
|
|
|
const b = self.b;
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
const root_src = %%os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
switch (case.special) {
|
|
|
|
Special.Asm => {
|
|
|
|
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-19 18:41:59 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
|
|
|
return;
|
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-26 23:17:05 +00:00
|
|
|
const exe = b.addExecutable("test", null);
|
|
|
|
exe.addAssemblyFile(root_src);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2017-04-30 22:56:24 +00:00
|
|
|
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
2017-04-19 18:41:59 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
2017-04-26 23:17:05 +00:00
|
|
|
exe.step.dependOn(&write_src.step);
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-03 20:00:51 +00:00
|
|
|
const run_and_cmp_output = RunCompareOutputStep.create(self, exe.getOutputPath(), annotated_case_name,
|
2017-04-19 18:41:59 +00:00
|
|
|
case.expected_output);
|
|
|
|
run_and_cmp_output.step.dependOn(&exe.step);
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
self.step.dependOn(&run_and_cmp_output.step);
|
|
|
|
},
|
|
|
|
Special.None => {
|
2017-05-02 21:34:21 +00:00
|
|
|
for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
|
2017-04-19 19:38:12 +00:00
|
|
|
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})",
|
2017-05-02 21:34:21 +00:00
|
|
|
"compare-output", case.name, @enumTagName(mode));
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-19 18:41:59 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
|
|
|
continue;
|
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-04-19 18:41:59 +00:00
|
|
|
const exe = b.addExecutable("test", root_src);
|
2017-05-02 21:34:21 +00:00
|
|
|
exe.setBuildMode(mode);
|
2017-04-19 18:41:59 +00:00
|
|
|
if (case.link_libc) {
|
2017-04-21 05:56:12 +00:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 18:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2017-04-30 22:56:24 +00:00
|
|
|
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
2017-04-19 18:41:59 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
exe.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
|
2017-05-03 20:00:51 +00:00
|
|
|
const run_and_cmp_output = RunCompareOutputStep.create(self, exe.getOutputPath(),
|
|
|
|
annotated_case_name, case.expected_output);
|
2017-04-19 18:41:59 +00:00
|
|
|
run_and_cmp_output.step.dependOn(&exe.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&run_and_cmp_output.step);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Special.DebugSafety => {
|
2017-05-03 20:00:51 +00:00
|
|
|
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "safety {}", case.name);
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-19 18:00:12 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
2017-04-19 18:41:59 +00:00
|
|
|
return;
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test", root_src);
|
|
|
|
if (case.link_libc) {
|
2017-04-21 05:56:12 +00:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2017-04-30 22:56:24 +00:00
|
|
|
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
2017-04-19 18:00:12 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
exe.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
|
2017-05-03 20:00:51 +00:00
|
|
|
const run_and_cmp_output = DebugSafetyRunStep.create(self, exe.getOutputPath(), annotated_case_name);
|
2017-04-19 18:00:12 +00:00
|
|
|
run_and_cmp_output.step.dependOn(&exe.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&run_and_cmp_output.step);
|
2017-04-19 18:41:59 +00:00
|
|
|
},
|
|
|
|
}
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const CompileErrorContext = struct {
|
|
|
|
b: &build.Builder,
|
|
|
|
step: &build.Step,
|
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
|
|
|
const TestCase = struct {
|
|
|
|
name: []const u8,
|
2017-05-04 18:05:06 +00:00
|
|
|
sources: ArrayList(SourceFile),
|
|
|
|
expected_errors: ArrayList([]const u8),
|
2017-04-19 18:00:12 +00:00
|
|
|
link_libc: bool,
|
|
|
|
is_exe: bool,
|
|
|
|
|
|
|
|
const SourceFile = struct {
|
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
|
|
|
%%self.sources.append(SourceFile {
|
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addExpectedError(self: &TestCase, text: []const u8) {
|
|
|
|
%%self.expected_errors.append(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const CompileCmpOutputStep = struct {
|
|
|
|
step: build.Step,
|
|
|
|
context: &CompileErrorContext,
|
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
case: &const TestCase,
|
2017-05-02 21:34:21 +00:00
|
|
|
build_mode: Mode,
|
2017-04-19 18:00:12 +00:00
|
|
|
|
|
|
|
pub fn create(context: &CompileErrorContext, name: []const u8,
|
2017-05-02 21:34:21 +00:00
|
|
|
case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep
|
2017-04-19 18:00:12 +00:00
|
|
|
{
|
|
|
|
const allocator = context.b.allocator;
|
|
|
|
const ptr = %%allocator.create(CompileCmpOutputStep);
|
|
|
|
*ptr = CompileCmpOutputStep {
|
|
|
|
.step = build.Step.init("CompileCmpOutput", allocator, make),
|
|
|
|
.context = context,
|
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.case = case,
|
2017-05-02 21:34:21 +00:00
|
|
|
.build_mode = build_mode,
|
2017-04-19 18:00:12 +00:00
|
|
|
};
|
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: &build.Step) -> %void {
|
|
|
|
const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
|
|
|
const obj_path = %%os.path.join(b.allocator, b.cache_root, "test.o");
|
2017-04-19 18:00:12 +00:00
|
|
|
|
2017-05-04 18:05:06 +00:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2017-04-19 18:00:12 +00:00
|
|
|
%%zig_args.append(if (self.case.is_exe) "build_exe" else "build_obj");
|
|
|
|
%%zig_args.append(b.pathFromRoot(root_src));
|
|
|
|
|
|
|
|
%%zig_args.append("--name");
|
|
|
|
%%zig_args.append("test");
|
|
|
|
|
|
|
|
%%zig_args.append("--output");
|
|
|
|
%%zig_args.append(b.pathFromRoot(obj_path));
|
|
|
|
|
2017-05-02 21:34:21 +00:00
|
|
|
switch (self.build_mode) {
|
|
|
|
Mode.Debug => {},
|
|
|
|
Mode.ReleaseSafe => %%zig_args.append("--release-safe"),
|
|
|
|
Mode.ReleaseFast => %%zig_args.append("--release-fast"),
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%%io.stderr.printf("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
|
|
|
|
|
|
|
if (b.verbose) {
|
|
|
|
printInvocation(b.zig_exe, zig_args.toSliceConst());
|
|
|
|
}
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
var child = os.ChildProcess.spawn(b.zig_exe, zig_args.toSliceConst(), null, &b.env_map,
|
2017-04-19 18:00:12 +00:00
|
|
|
StdIo.Ignore, StdIo.Pipe, StdIo.Pipe, b.allocator) %% |err|
|
|
|
|
{
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
|
|
|
|
};
|
|
|
|
|
2017-04-22 15:36:42 +00:00
|
|
|
var stdout_buf = Buffer.initNull(b.allocator);
|
|
|
|
var stderr_buf = Buffer.initNull(b.allocator);
|
|
|
|
|
|
|
|
%%(??child.stdout).readAll(&stdout_buf);
|
|
|
|
%%(??child.stderr).readAll(&stderr_buf);
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
const term = child.wait() %% |err| {
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
|
|
|
|
};
|
|
|
|
switch (term) {
|
|
|
|
Term.Clean => |code| {
|
|
|
|
if (code == 0) {
|
|
|
|
%%io.stderr.printf("Compilation incorrectly succeeded\n");
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
else => {
|
|
|
|
%%io.stderr.printf("Process {} terminated unexpectedly\n", b.zig_exe);
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const stdout = stdout_buf.toSliceConst();
|
|
|
|
const stderr = stderr_buf.toSliceConst();
|
|
|
|
|
|
|
|
if (stdout.len != 0) {
|
|
|
|
%%io.stderr.printf(
|
|
|
|
\\
|
|
|
|
\\Expected empty stdout, instead found:
|
|
|
|
\\================================================
|
|
|
|
\\{}
|
|
|
|
\\================================================
|
|
|
|
\\
|
|
|
|
, stdout);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (self.case.expected_errors.toSliceConst()) |expected_error| {
|
|
|
|
if (mem.indexOf(u8, stderr, expected_error) == null) {
|
|
|
|
%%io.stderr.printf(
|
|
|
|
\\
|
|
|
|
\\========= Expected this compile error: =========
|
|
|
|
\\{}
|
|
|
|
\\================================================
|
|
|
|
\\{}
|
|
|
|
\\
|
|
|
|
, expected_error, stderr);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%%io.stderr.printf("OK\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fn printInvocation(exe_path: []const u8, args: []const []const u8) {
|
|
|
|
%%io.stderr.printf("{}", exe_path);
|
|
|
|
for (args) |arg| {
|
|
|
|
%%io.stderr.printf(" {}", arg);
|
|
|
|
}
|
|
|
|
%%io.stderr.printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8,
|
|
|
|
expected_lines: ...) -> &TestCase
|
|
|
|
{
|
|
|
|
const tc = %%self.b.allocator.create(TestCase);
|
|
|
|
*tc = TestCase {
|
|
|
|
.name = name,
|
2017-05-04 18:05:06 +00:00
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
|
|
|
.expected_errors = ArrayList([]const u8).init(self.b.allocator),
|
2017-04-19 18:00:12 +00:00
|
|
|
.link_libc = false,
|
|
|
|
.is_exe = false,
|
|
|
|
};
|
|
|
|
tc.addSourceFile(".tmp_source.zig", source);
|
|
|
|
comptime var arg_i = 0;
|
2017-05-03 22:12:07 +00:00
|
|
|
inline while (arg_i < expected_lines.len) : (arg_i += 1) {
|
2017-05-27 03:31:38 +00:00
|
|
|
tc.addExpectedError(expected_lines[arg_i]);
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addC(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
|
|
|
var tc = self.create(name, source, expected_lines);
|
|
|
|
tc.link_libc = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addExe(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
|
|
|
var tc = self.create(name, source, expected_lines);
|
|
|
|
tc.is_exe = true;
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(self: &CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
|
|
|
const tc = self.create(name, source, expected_lines);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCase(self: &CompileErrorContext, case: &const TestCase) {
|
|
|
|
const b = self.b;
|
|
|
|
|
2017-05-02 21:34:21 +00:00
|
|
|
for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
|
2017-04-19 18:00:12 +00:00
|
|
|
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})",
|
2017-05-02 21:34:21 +00:00
|
|
|
case.name, @enumTagName(mode));
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-19 18:00:12 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-02 21:34:21 +00:00
|
|
|
const compile_and_cmp_errors = CompileCmpOutputStep.create(self, annotated_case_name, case, mode);
|
2017-04-19 18:00:12 +00:00
|
|
|
self.step.dependOn(&compile_and_cmp_errors.step);
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2017-04-30 22:56:24 +00:00
|
|
|
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
2017-04-19 18:00:12 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
compile_and_cmp_errors.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const BuildExamplesContext = struct {
|
|
|
|
b: &build.Builder,
|
|
|
|
step: &build.Step,
|
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
|
|
|
pub fn addC(self: &BuildExamplesContext, root_src: []const u8) {
|
|
|
|
self.addAllArgs(root_src, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(self: &BuildExamplesContext, root_src: []const u8) {
|
|
|
|
self.addAllArgs(root_src, false);
|
|
|
|
}
|
|
|
|
|
2017-04-21 05:56:12 +00:00
|
|
|
pub fn addBuildFile(self: &BuildExamplesContext, build_file: []const u8) {
|
|
|
|
const b = self.b;
|
|
|
|
|
2017-05-02 21:34:21 +00:00
|
|
|
const annotated_case_name = b.fmt("build {} (Debug)", build_file);
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-21 05:56:12 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-04 18:05:06 +00:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2017-04-21 05:56:12 +00:00
|
|
|
%%zig_args.append("build");
|
|
|
|
|
|
|
|
%%zig_args.append("--build-file");
|
|
|
|
%%zig_args.append(b.pathFromRoot(build_file));
|
|
|
|
|
|
|
|
%%zig_args.append("test");
|
|
|
|
|
|
|
|
if (b.verbose) {
|
|
|
|
%%zig_args.append("--verbose");
|
|
|
|
}
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
const run_cmd = b.addCommand(null, b.env_map, b.zig_exe, zig_args.toSliceConst());
|
2017-04-21 05:56:12 +00:00
|
|
|
|
|
|
|
const log_step = b.addLog("PASS {}\n", annotated_case_name);
|
|
|
|
log_step.step.dependOn(&run_cmd.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&log_step.step);
|
|
|
|
}
|
|
|
|
|
2017-04-19 18:00:12 +00:00
|
|
|
pub fn addAllArgs(self: &BuildExamplesContext, root_src: []const u8, link_libc: bool) {
|
|
|
|
const b = self.b;
|
|
|
|
|
2017-05-02 21:34:21 +00:00
|
|
|
for ([]Mode{Mode.Debug, Mode.ReleaseFast}) |mode| {
|
2017-04-19 18:00:12 +00:00
|
|
|
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})",
|
2017-05-02 21:34:21 +00:00
|
|
|
root_src, @enumTagName(mode));
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-19 18:00:12 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const exe = b.addExecutable("test", root_src);
|
2017-05-02 21:34:21 +00:00
|
|
|
exe.setBuildMode(mode);
|
2017-04-19 18:00:12 +00:00
|
|
|
if (link_libc) {
|
2017-04-21 05:56:12 +00:00
|
|
|
exe.linkSystemLibrary("c");
|
2017-04-19 18:00:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const log_step = b.addLog("PASS {}\n", annotated_case_name);
|
|
|
|
log_step.step.dependOn(&exe.step);
|
|
|
|
|
|
|
|
self.step.dependOn(&log_step.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2017-04-19 20:59:20 +00:00
|
|
|
|
|
|
|
pub const ParseHContext = struct {
|
|
|
|
b: &build.Builder,
|
|
|
|
step: &build.Step,
|
|
|
|
test_index: usize,
|
|
|
|
test_filter: ?[]const u8,
|
|
|
|
|
|
|
|
const TestCase = struct {
|
|
|
|
name: []const u8,
|
2017-05-04 18:05:06 +00:00
|
|
|
sources: ArrayList(SourceFile),
|
|
|
|
expected_lines: ArrayList([]const u8),
|
2017-04-19 20:59:20 +00:00
|
|
|
allow_warnings: bool,
|
|
|
|
|
|
|
|
const SourceFile = struct {
|
|
|
|
filename: []const u8,
|
|
|
|
source: []const u8,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
|
|
|
%%self.sources.append(SourceFile {
|
|
|
|
.filename = filename,
|
|
|
|
.source = source,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addExpectedError(self: &TestCase, text: []const u8) {
|
|
|
|
%%self.expected_lines.append(text);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const ParseHCmpOutputStep = struct {
|
|
|
|
step: build.Step,
|
|
|
|
context: &ParseHContext,
|
|
|
|
name: []const u8,
|
|
|
|
test_index: usize,
|
|
|
|
case: &const TestCase,
|
|
|
|
|
|
|
|
pub fn create(context: &ParseHContext, name: []const u8, case: &const TestCase) -> &ParseHCmpOutputStep {
|
|
|
|
const allocator = context.b.allocator;
|
|
|
|
const ptr = %%allocator.create(ParseHCmpOutputStep);
|
|
|
|
*ptr = ParseHCmpOutputStep {
|
|
|
|
.step = build.Step.init("ParseHCmpOutput", allocator, make),
|
|
|
|
.context = context,
|
|
|
|
.name = name,
|
|
|
|
.test_index = context.test_index,
|
|
|
|
.case = case,
|
|
|
|
};
|
|
|
|
context.test_index += 1;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make(step: &build.Step) -> %void {
|
|
|
|
const self = @fieldParentPtr(ParseHCmpOutputStep, "step", step);
|
|
|
|
const b = self.context.b;
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
2017-04-19 20:59:20 +00:00
|
|
|
|
2017-05-04 18:05:06 +00:00
|
|
|
var zig_args = ArrayList([]const u8).init(b.allocator);
|
2017-04-19 20:59:20 +00:00
|
|
|
%%zig_args.append("parseh");
|
|
|
|
%%zig_args.append(b.pathFromRoot(root_src));
|
|
|
|
|
|
|
|
%%io.stderr.printf("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
|
|
|
|
|
|
|
if (b.verbose) {
|
|
|
|
printInvocation(b.zig_exe, zig_args.toSliceConst());
|
|
|
|
}
|
|
|
|
|
2017-04-30 22:56:24 +00:00
|
|
|
var child = os.ChildProcess.spawn(b.zig_exe, zig_args.toSliceConst(), null, &b.env_map,
|
2017-04-19 20:59:20 +00:00
|
|
|
StdIo.Ignore, StdIo.Pipe, StdIo.Pipe, b.allocator) %% |err|
|
|
|
|
{
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
|
|
|
|
};
|
|
|
|
|
2017-04-22 15:36:42 +00:00
|
|
|
var stdout_buf = Buffer.initNull(b.allocator);
|
|
|
|
var stderr_buf = Buffer.initNull(b.allocator);
|
|
|
|
|
|
|
|
%%(??child.stdout).readAll(&stdout_buf);
|
|
|
|
%%(??child.stderr).readAll(&stderr_buf);
|
|
|
|
|
2017-04-19 20:59:20 +00:00
|
|
|
const term = child.wait() %% |err| {
|
|
|
|
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
|
|
|
|
};
|
|
|
|
switch (term) {
|
|
|
|
Term.Clean => |code| {
|
|
|
|
if (code != 0) {
|
|
|
|
%%io.stderr.printf("Compilation failed with exit code {}\n", code);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Term.Signal => |code| {
|
|
|
|
%%io.stderr.printf("Compilation failed with signal {}\n", code);
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
else => {
|
|
|
|
%%io.stderr.printf("Compilation terminated unexpectedly\n");
|
|
|
|
return error.TestFailed;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const stdout = stdout_buf.toSliceConst();
|
|
|
|
const stderr = stderr_buf.toSliceConst();
|
|
|
|
|
|
|
|
if (stderr.len != 0 and !self.case.allow_warnings) {
|
|
|
|
%%io.stderr.printf(
|
|
|
|
\\====== parseh emitted warnings: ============
|
|
|
|
\\{}
|
|
|
|
\\============================================
|
|
|
|
\\
|
|
|
|
, stderr);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (self.case.expected_lines.toSliceConst()) |expected_line| {
|
|
|
|
if (mem.indexOf(u8, stdout, expected_line) == null) {
|
|
|
|
%%io.stderr.printf(
|
|
|
|
\\
|
|
|
|
\\========= Expected this output: ================
|
|
|
|
\\{}
|
|
|
|
\\================================================
|
|
|
|
\\{}
|
|
|
|
\\
|
|
|
|
, expected_line, stdout);
|
|
|
|
return error.TestFailed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%%io.stderr.printf("OK\n");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fn printInvocation(exe_path: []const u8, args: []const []const u8) {
|
|
|
|
%%io.stderr.printf("{}", exe_path);
|
|
|
|
for (args) |arg| {
|
|
|
|
%%io.stderr.printf(" {}", arg);
|
|
|
|
}
|
|
|
|
%%io.stderr.printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn create(self: &ParseHContext, allow_warnings: bool, name: []const u8,
|
|
|
|
source: []const u8, expected_lines: ...) -> &TestCase
|
|
|
|
{
|
|
|
|
const tc = %%self.b.allocator.create(TestCase);
|
|
|
|
*tc = TestCase {
|
|
|
|
.name = name,
|
2017-05-04 18:05:06 +00:00
|
|
|
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
|
|
|
.expected_lines = ArrayList([]const u8).init(self.b.allocator),
|
2017-04-19 20:59:20 +00:00
|
|
|
.allow_warnings = allow_warnings,
|
|
|
|
};
|
|
|
|
tc.addSourceFile("source.h", source);
|
|
|
|
comptime var arg_i = 0;
|
2017-05-03 22:12:07 +00:00
|
|
|
inline while (arg_i < expected_lines.len) : (arg_i += 1) {
|
2017-05-27 03:31:38 +00:00
|
|
|
tc.addExpectedError(expected_lines[arg_i]);
|
2017-04-19 20:59:20 +00:00
|
|
|
}
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(self: &ParseHContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
|
|
|
const tc = self.create(false, name, source, expected_lines);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addAllowWarnings(self: &ParseHContext, name: []const u8, source: []const u8, expected_lines: ...) {
|
|
|
|
const tc = self.create(true, name, source, expected_lines);
|
|
|
|
self.addCase(tc);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn addCase(self: &ParseHContext, case: &const TestCase) {
|
|
|
|
const b = self.b;
|
|
|
|
|
|
|
|
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "parseh {}", case.name);
|
2017-05-03 21:23:11 +00:00
|
|
|
if (self.test_filter) |filter| {
|
2017-04-19 20:59:20 +00:00
|
|
|
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const parseh_and_cmp = ParseHCmpOutputStep.create(self, annotated_case_name, case);
|
|
|
|
self.step.dependOn(&parseh_and_cmp.step);
|
|
|
|
|
|
|
|
for (case.sources.toSliceConst()) |src_file| {
|
2017-04-30 22:56:24 +00:00
|
|
|
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
2017-04-19 20:59:20 +00:00
|
|
|
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
|
|
|
parseh_and_cmp.step.dependOn(&write_src.step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|