aboutsummaryrefslogtreecommitdiff
path: root/test/cli.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-09-26 12:42:07 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-09-26 12:42:07 -0700
commit26f2f9bf1c774caf246317b3fc032449e982a150 (patch)
tree43bc4d4b19cea9a245d87f105841d075ab75f5ab /test/cli.zig
parent9b83112a1f6af758a1a995ea8838a2319d2fbc1e (diff)
downloadzig-26f2f9bf1c774caf246317b3fc032449e982a150.tar.gz
zig-26f2f9bf1c774caf246317b3fc032449e982a150.zip
stage2: implement -fno-emit-bin
we are now passing the cli tests
Diffstat (limited to 'test/cli.zig')
-rw-r--r--test/cli.zig32
1 files changed, 16 insertions, 16 deletions
diff --git a/test/cli.zig b/test/cli.zig
index c92636fb3c..edb87cc750 100644
--- a/test/cli.zig
+++ b/test/cli.zig
@@ -58,7 +58,7 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void {
std.debug.warn("\n", .{});
}
-fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
+fn exec(cwd: []const u8, expect_0: bool, argv: []const []const u8) !ChildProcess.ExecResult {
const max_output_size = 100 * 1024;
const result = ChildProcess.exec(.{
.allocator = a,
@@ -72,7 +72,7 @@ fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
};
switch (result.term) {
.Exited => |code| {
- if (code != 0) {
+ if ((code != 0) == expect_0) {
std.debug.warn("The following command exited with error code {}:\n", .{code});
printCmd(cwd, argv);
std.debug.warn("stderr:\n{}\n", .{result.stderr});
@@ -90,14 +90,14 @@ fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
}
fn testZigInitLib(zig_exe: []const u8, dir_path: []const u8) !void {
- _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-lib" });
- const test_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "test" });
+ _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-lib" });
+ const test_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "test" });
testing.expect(std.mem.endsWith(u8, test_result.stderr, "All 1 tests passed.\n"));
}
fn testZigInitExe(zig_exe: []const u8, dir_path: []const u8) !void {
- _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" });
- const run_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "run" });
+ _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });
+ const run_result = try exec(dir_path, true, &[_][]const u8{ zig_exe, "build", "run" });
testing.expect(std.mem.eql(u8, run_result.stderr, "info: All your codebase are belong to us.\n"));
}
@@ -131,7 +131,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
const emit_asm_arg = try std.fmt.allocPrint(a, "-femit-asm={s}", .{example_s_path});
try args.append(emit_asm_arg);
- _ = try exec(dir_path, args.items);
+ _ = try exec(dir_path, true, args.items);
const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize));
testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
@@ -140,23 +140,23 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
}
fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void {
- _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" });
- const output_path = try fs.path.join(a, &[_][]const u8{ "does", "not", "exist" });
+ _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });
+ const output_path = try fs.path.join(a, &[_][]const u8{ "does", "not", "exist", "foo.exe" });
+ const output_arg = try std.fmt.allocPrint(a, "-femit-bin={s}", .{output_path});
const source_path = try fs.path.join(a, &[_][]const u8{ "src", "main.zig" });
- _ = try exec(dir_path, &[_][]const u8{
- zig_exe, "build-exe", source_path, "--output-dir", output_path,
- });
+ const result = try exec(dir_path, false, &[_][]const u8{ zig_exe, "build-exe", source_path, output_arg });
+ testing.expect(std.mem.eql(u8, result.stderr, "error: unable to open output directory 'does/not/exist': FileNotFound\n"));
}
fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
- _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" });
+ _ = try exec(dir_path, true, &[_][]const u8{ zig_exe, "init-exe" });
const unformatted_code = " // no reason for indent";
const fmt1_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt1.zig" });
try fs.cwd().writeFile(fmt1_zig_path, unformatted_code);
- const run_result1 = try exec(dir_path, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
+ const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
// stderr should be file path + \n
testing.expect(std.mem.startsWith(u8, run_result1.stderr, fmt1_zig_path));
testing.expect(run_result1.stderr.len == fmt1_zig_path.len + 1 and run_result1.stderr[run_result1.stderr.len - 1] == '\n');
@@ -164,12 +164,12 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
- const run_result2 = try exec(dir_path, &[_][]const u8{ zig_exe, "fmt", dir_path });
+ const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
// running it on the dir, only the new file should be changed
testing.expect(std.mem.startsWith(u8, run_result2.stderr, fmt2_zig_path));
testing.expect(run_result2.stderr.len == fmt2_zig_path.len + 1 and run_result2.stderr[run_result2.stderr.len - 1] == '\n');
- const run_result3 = try exec(dir_path, &[_][]const u8{ zig_exe, "fmt", dir_path });
+ const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
// both files have been formatted, nothing should change now
testing.expect(run_result3.stderr.len == 0);
}