mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
re-enable test-cases and get them all passing
Instead of using `zig test` to build a special version of the compiler that runs all the test-cases, the zig build system is now used as much as possible - all with the basic steps found in the standard library. For incremental compilation tests (the ones that look like foo.0.zig, foo.1.zig, foo.2.zig, etc.), a special version of the compiler is compiled into a utility executable called "check-case" which checks exactly one sequence of incremental updates in an independent subprocess. Previously, all incremental and non-incremental test cases were done in the same test runner process. The compile error checking code is now simpler, but also a bit rudimentary, and so it additionally makes sure that the actual compile errors do not include *extra* messages, and it makes sure that the actual compile errors output in the same order as expected. It is also based on the "ends-with" property of each line rather than the previous logic, which frankly I didn't want to touch with a ten-meter pole. The compile error test cases have been updated to pass in light of these differences. Previously, 'error' mode with 0 compile errors was used to shoehorn in a different kind of test-case - one that only checks if a piece of code compiles without errors. Now there is a 'compile' mode of test-cases, and 'error' must be only used when there are greater than 0 errors. link test cases are updated to omit the target object format argument when calling checkObject since that is no longer needed. The test/stage2 directory is removed; the 2 files within are moved to be directly in the test/ directory.
This commit is contained in:
+25
-199
@@ -1,146 +1,10 @@
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const TestContext = @import("../src/test.zig").TestContext;
|
||||
|
||||
pub fn addCases(ctx: *TestContext) !void {
|
||||
{
|
||||
const case = ctx.obj("wrong same named struct", .{});
|
||||
case.backend = .stage1;
|
||||
|
||||
case.addSourceFile("a.zig",
|
||||
\\pub const Foo = struct {
|
||||
\\ x: i32,
|
||||
\\};
|
||||
);
|
||||
|
||||
case.addSourceFile("b.zig",
|
||||
\\pub const Foo = struct {
|
||||
\\ z: f64,
|
||||
\\};
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\const a = @import("a.zig");
|
||||
\\const b = @import("b.zig");
|
||||
\\
|
||||
\\export fn entry() void {
|
||||
\\ var a1: a.Foo = undefined;
|
||||
\\ bar(&a1);
|
||||
\\}
|
||||
\\
|
||||
\\fn bar(x: *b.Foo) void {_ = x;}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
|
||||
"tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
|
||||
"a.zig:1:17: note: a.Foo declared here",
|
||||
"b.zig:1:17: note: b.Foo declared here",
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const case = ctx.obj("multiple files with private function error", .{});
|
||||
case.backend = .stage1;
|
||||
|
||||
case.addSourceFile("foo.zig",
|
||||
\\fn privateFunction() void { }
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\const foo = @import("foo.zig",);
|
||||
\\
|
||||
\\export fn callPrivFunction() void {
|
||||
\\ foo.privateFunction();
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:4:8: error: 'privateFunction' is private",
|
||||
"foo.zig:1:1: note: declared here",
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const case = ctx.obj("multiple files with private member instance function (canonical invocation) error", .{});
|
||||
case.backend = .stage1;
|
||||
|
||||
case.addSourceFile("foo.zig",
|
||||
\\pub const Foo = struct {
|
||||
\\ fn privateFunction(self: *Foo) void { _ = self; }
|
||||
\\};
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\const Foo = @import("foo.zig",).Foo;
|
||||
\\
|
||||
\\export fn callPrivFunction() void {
|
||||
\\ var foo = Foo{};
|
||||
\\ Foo.privateFunction(foo);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:5:8: error: 'privateFunction' is private",
|
||||
"foo.zig:2:5: note: declared here",
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const case = ctx.obj("multiple files with private member instance function error", .{});
|
||||
case.backend = .stage1;
|
||||
|
||||
case.addSourceFile("foo.zig",
|
||||
\\pub const Foo = struct {
|
||||
\\ fn privateFunction(self: *Foo) void { _ = self; }
|
||||
\\};
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\const Foo = @import("foo.zig",).Foo;
|
||||
\\
|
||||
\\export fn callPrivFunction() void {
|
||||
\\ var foo = Foo{};
|
||||
\\ foo.privateFunction();
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:5:8: error: 'privateFunction' is private",
|
||||
"foo.zig:2:5: note: declared here",
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const case = ctx.obj("export collision", .{});
|
||||
case.backend = .stage1;
|
||||
|
||||
case.addSourceFile("foo.zig",
|
||||
\\export fn bar() void {}
|
||||
\\pub const baz = 1234;
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\const foo = @import("foo.zig",);
|
||||
\\
|
||||
\\export fn bar() usize {
|
||||
\\ return foo.baz;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"foo.zig:1:1: error: exported symbol collision: 'bar'",
|
||||
"tmp.zig:3:1: note: other symbol here",
|
||||
});
|
||||
}
|
||||
|
||||
ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++
|
||||
"fn foo() bool {\r\n" ++
|
||||
" return true;\r\n" ++
|
||||
"}\r\n", &[_][]const u8{
|
||||
"tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'",
|
||||
"tmp.zig:1:1: note: invalid byte: '\\xff'",
|
||||
});
|
||||
|
||||
ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++
|
||||
"\treturn true;\n" ++
|
||||
"}\n", &[_][]const u8{
|
||||
"tmp.zig:2:1: error: invalid character: '\\t'",
|
||||
});
|
||||
const Cases = @import("src/Cases.zig");
|
||||
|
||||
pub fn addCases(ctx: *Cases) !void {
|
||||
{
|
||||
const case = ctx.obj("multiline error messages", .{});
|
||||
case.backend = .stage2;
|
||||
|
||||
case.addError(
|
||||
\\comptime {
|
||||
@@ -176,7 +40,6 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
|
||||
{
|
||||
const case = ctx.obj("isolated carriage return in multiline string literal", .{});
|
||||
case.backend = .stage2;
|
||||
|
||||
case.addError("const foo = \\\\\test\r\r rogue carriage return\n;", &[_][]const u8{
|
||||
":1:19: error: expected ';' after declaration",
|
||||
@@ -195,16 +58,6 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
|
||||
{
|
||||
const case = ctx.obj("argument causes error", .{});
|
||||
case.backend = .stage2;
|
||||
|
||||
case.addSourceFile("b.zig",
|
||||
\\pub const ElfDynLib = struct {
|
||||
\\ pub fn lookup(self: *ElfDynLib, comptime T: type) ?T {
|
||||
\\ _ = self;
|
||||
\\ return undefined;
|
||||
\\ }
|
||||
\\};
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\pub export fn entry() void {
|
||||
@@ -216,15 +69,18 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
":3:12: note: argument to function being called at comptime must be comptime-known",
|
||||
":2:55: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type",
|
||||
});
|
||||
case.addSourceFile("b.zig",
|
||||
\\pub const ElfDynLib = struct {
|
||||
\\ pub fn lookup(self: *ElfDynLib, comptime T: type) ?T {
|
||||
\\ _ = self;
|
||||
\\ return undefined;
|
||||
\\ }
|
||||
\\};
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const case = ctx.obj("astgen failure in file struct", .{});
|
||||
case.backend = .stage2;
|
||||
|
||||
case.addSourceFile("b.zig",
|
||||
\\+
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\pub export fn entry() void {
|
||||
@@ -233,21 +89,13 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
, &[_][]const u8{
|
||||
":1:1: error: expected type expression, found '+'",
|
||||
});
|
||||
case.addSourceFile("b.zig",
|
||||
\\+
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
const case = ctx.obj("invalid store to comptime field", .{});
|
||||
case.backend = .stage2;
|
||||
|
||||
case.addSourceFile("a.zig",
|
||||
\\pub const S = struct {
|
||||
\\ comptime foo: u32 = 1,
|
||||
\\ bar: u32,
|
||||
\\ pub fn foo(x: @This()) void {
|
||||
\\ _ = x;
|
||||
\\ }
|
||||
\\};
|
||||
);
|
||||
|
||||
case.addError(
|
||||
\\const a = @import("a.zig");
|
||||
@@ -259,44 +107,19 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
":4:23: error: value stored in comptime field does not match the default value of the field",
|
||||
":2:25: note: default value set here",
|
||||
});
|
||||
case.addSourceFile("a.zig",
|
||||
\\pub const S = struct {
|
||||
\\ comptime foo: u32 = 1,
|
||||
\\ bar: u32,
|
||||
\\ pub fn foo(x: @This()) void {
|
||||
\\ _ = x;
|
||||
\\ }
|
||||
\\};
|
||||
);
|
||||
}
|
||||
|
||||
// TODO test this in stage2, but we won't even try in stage1
|
||||
//ctx.objErrStage1("inline fn calls itself indirectly",
|
||||
// \\export fn foo() void {
|
||||
// \\ bar();
|
||||
// \\}
|
||||
// \\fn bar() callconv(.Inline) void {
|
||||
// \\ baz();
|
||||
// \\ quux();
|
||||
// \\}
|
||||
// \\fn baz() callconv(.Inline) void {
|
||||
// \\ bar();
|
||||
// \\ quux();
|
||||
// \\}
|
||||
// \\extern fn quux() void;
|
||||
//, &[_][]const u8{
|
||||
// "tmp.zig:4:1: error: unable to inline function",
|
||||
//});
|
||||
|
||||
//ctx.objErrStage1("save reference to inline function",
|
||||
// \\export fn foo() void {
|
||||
// \\ quux(@ptrToInt(bar));
|
||||
// \\}
|
||||
// \\fn bar() callconv(.Inline) void { }
|
||||
// \\extern fn quux(usize) void;
|
||||
//, &[_][]const u8{
|
||||
// "tmp.zig:4:1: error: unable to inline function",
|
||||
//});
|
||||
|
||||
{
|
||||
const case = ctx.obj("file in multiple modules", .{});
|
||||
case.backend = .stage2;
|
||||
|
||||
case.addSourceFile("foo.zig",
|
||||
\\const dummy = 0;
|
||||
);
|
||||
|
||||
case.addDepModule("foo", "foo.zig");
|
||||
|
||||
case.addError(
|
||||
@@ -309,5 +132,8 @@ pub fn addCases(ctx: *TestContext) !void {
|
||||
":1:1: note: root of module root.foo",
|
||||
":3:17: note: imported from module root",
|
||||
});
|
||||
case.addSourceFile("foo.zig",
|
||||
\\const dummy = 0;
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user