Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if the tests actually pass under the current compiler #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
build
zig-cache
zig-out
35 changes: 35 additions & 0 deletions grammar/build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const std = @import("std");

const test_targets = [_]std.Target.Query{
.{},
};

pub fn build(b: *std.Build) !void {
const test_step = b.step("test", "Test the tests");

var files = std.ArrayList([]const u8).init(b.allocator);
defer files.deinit();

var dir = try std.fs.cwd().openDir("tests", .{ .iterate = true });
var it = dir.iterate();
while (try it.next()) |file| {
if (file.kind != .file) {
continue;
}
try files.append(b.dupe(file.name));
}

for (test_targets) |target| {
for (files.items) |file| {
const unit_test = b.addTest(.{
.root_source_file = .{ .path = file },
.target = b.resolveTargetQuery(target),
});

const run_unit_test = b.addRunArtifact(unit_test);
test_step.dependOn(&run_unit_test.step);
}
}

b.default_step.dependOn(test_step);
}
18 changes: 6 additions & 12 deletions grammar/tests/while.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,48 +137,42 @@ fn getNumberOrNull() ?i32 {
test "while on optional with else result follow else prong" {
const result = while (returnNull()) |value| {
break value;
} else
@as(i32, 2);
} else @as(i32, 2);
expect(result == 2);
}

test "while on optional with else result follow break prong" {
const result = while (returnOptional(10)) |value| {
break value;
} else
@as(i32, 2);
} else @as(i32, 2);
expect(result == 10);
}

test "while on error union with else result follow else prong" {
const result = while (returnError()) |value| {
break value;
} else |err|
@as(i32, 2);
} else |err| @as(i32, 2);
expect(result == 2);
}

test "while on error union with else result follow break prong" {
const result = while (returnSuccess(10)) |value| {
break value;
} else |err|
@as(i32, 2);
} else |err| @as(i32, 2);
expect(result == 10);
}

test "while on bool with else result follow else prong" {
const result = while (returnFalse()) {
break @as(i32, 10);
} else
@as(i32, 2);
} else @as(i32, 2);
expect(result == 2);
}

test "while on bool with else result follow break prong" {
const result = while (returnTrue()) {
break @as(i32, 10);
} else
@as(i32, 2);
} else @as(i32, 2);
expect(result == 10);
}

Expand Down