more test regression fixes

This commit is contained in:
Andrew Kelley 2019-11-29 23:04:19 -05:00
parent d87b13f2f7
commit b220be7a33
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
10 changed files with 28 additions and 22 deletions

View File

@ -609,7 +609,7 @@ pub const Dir = struct {
const name_utf16le = @ptrCast([*]u16, &dir_info.FileName)[0 .. dir_info.FileNameLength / 2];
if (mem.eql(u16, name_utf16le, [_]u16{'.'}) or mem.eql(u16, name_utf16le, [_]u16{ '.', '.' }))
if (mem.eql(u16, name_utf16le, &[_]u16{'.'}) or mem.eql(u16, name_utf16le, &[_]u16{ '.', '.' }))
continue;
// Trust that Windows gives us valid UTF-16LE
const name_utf8_len = std.unicode.utf16leToUtf8(self.name_data[0..], name_utf16le) catch unreachable;

View File

@ -2633,7 +2633,7 @@ pub fn realpathW(pathname: [*:0]const u16, out_buffer: *[MAX_PATH_BYTES]u8) Real
// Windows returns \\?\ prepended to the path.
// We strip it to make this function consistent across platforms.
const prefix = [_]u16{ '\\', '\\', '?', '\\' };
const start_index = if (mem.startsWith(u16, wide_slice, prefix)) prefix.len else 0;
const start_index = if (mem.startsWith(u16, wide_slice, &prefix)) prefix.len else 0;
// Trust that Windows gives us valid UTF-16LE.
const end_index = std.unicode.utf16leToUtf8(out_buffer, wide_slice[start_index..]) catch unreachable;

View File

@ -26,9 +26,9 @@ pub fn main() !void {
std.debug.warn("Expected second argument to be cache root directory path\n");
return error.InvalidArgs;
});
const zig_exe = try fs.path.resolve(a, [_][]const u8{zig_exe_rel});
const zig_exe = try fs.path.resolve(a, &[_][]const u8{zig_exe_rel});
const dir_path = try fs.path.join(a, [_][]const u8{ cache_root, "clitest" });
const dir_path = try fs.path.join(a, &[_][]const u8{ cache_root, "clitest" });
const TestFn = fn ([]const u8, []const u8) anyerror!void;
const test_fns = [_]TestFn{
testZigInitLib,
@ -85,22 +85,22 @@ 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, &[_][]const u8{ zig_exe, "init-lib" });
const test_result = try exec(dir_path, &[_][]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, &[_][]const u8{ zig_exe, "init-exe" });
const run_result = try exec(dir_path, &[_][]const u8{ zig_exe, "build", "run" });
testing.expect(std.mem.eql(u8, run_result.stderr, "All your base are belong to us.\n"));
}
fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
if (builtin.os != .linux or builtin.arch != .x86_64) return;
const example_zig_path = try fs.path.join(a, [_][]const u8{ dir_path, "example.zig" });
const example_s_path = try fs.path.join(a, [_][]const u8{ dir_path, "example.s" });
const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" });
const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });
try std.io.writeFile(example_zig_path,
\\// Type your code here, or load an example.
@ -123,7 +123,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
"--strip", "--release-fast",
example_zig_path, "--disable-gen-h",
};
_ = try exec(dir_path, args);
_ = try exec(dir_path, &args);
const out_asm = try std.io.readFileAlloc(a, example_s_path);
testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
@ -132,10 +132,10 @@ 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" });
const source_path = try fs.path.join(a, [_][]const u8{ "src", "main.zig" });
_ = try exec(dir_path, [_][]const u8{
_ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" });
const output_path = try fs.path.join(a, &[_][]const u8{ "does", "not", "exist" });
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,
});
}

View File

@ -261,7 +261,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\}
\\pub fn main() void {
\\ const a = [_]i32{1, 2, 3, 4};
\\ baz(bar(a));
\\ baz(bar(&a));
\\}
\\fn bar(a: []const i32) i32 {
\\ return a[4];
@ -471,7 +471,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
\\ @import("std").os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = widenSlice([_]u8{1, 2, 3, 4, 5});
\\ const x = widenSlice(&[_]u8{1, 2, 3, 4, 5});
\\ if (x.len == 0) return error.Whatever;
\\}
\\fn widenSlice(slice: []align(1) const u8) []align(1) const i32 {

View File

@ -360,3 +360,9 @@ test "access the null element of a null terminated array" {
S.doTheTest();
comptime S.doTheTest();
}
test "type coerce sentinel-terminated array to non-sentinel-terminated array" {
var array: [2]u8 = [_:255]u8{1, 2};
expect(array[0] == 1);
expect(array[1] == 2);
}

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const rel_opts = b.standardReleaseOptions();
const c_obj = b.addObject("cfuncs", null);
c_obj.addCSourceFile("cfuncs.c", [_][]const u8{"-std=c99"});
c_obj.addCSourceFile("cfuncs.c", &[_][]const u8{"-std=c99"});
c_obj.setBuildMode(rel_opts);
c_obj.linkSystemLibrary("c");

View File

@ -124,7 +124,7 @@ test "C ABI array" {
}
export fn zig_array(x: [10]u8) void {
expect(std.mem.eql(u8, x, "1234567890"));
expect(std.mem.eql(u8, &x, "1234567890"));
}
const BigStruct = extern struct {

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const obj = b.addObject("base64", "base64.zig");
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
exe.addObject(obj);
exe.linkSystemLibrary("c");

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", [_][]const u8{"-std=c99"});
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");

View File

@ -4,7 +4,7 @@ pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const foo = b.addStaticLibrary("foo", null);
foo.addCSourceFile("foo.c", [_][]const u8{});
foo.addCSourceFile("foo.c", &[_][]const u8{});
foo.setBuildMode(mode);
foo.addIncludeDir(".");