mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Address review comments
This commit is contained in:
parent
128e70ff3a
commit
28dbc58837
3 changed files with 15 additions and 5 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
test "zig fmt: noasync block" {
|
test "zig fmt: errdefer with payload" {
|
||||||
try testCanonical(
|
try testCanonical(
|
||||||
\\pub fn main() anyerror!void {
|
\\pub fn main() anyerror!void {
|
||||||
\\ errdefer |a| x += 1;
|
\\ errdefer |a| x += 1;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,18 @@ const tests = @import("tests.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||||
|
cases.addTest("unused variable error on errdefer",
|
||||||
|
\\fn foo() !void {
|
||||||
|
\\ errdefer |a| unreachable;
|
||||||
|
\\ return error.A;
|
||||||
|
\\}
|
||||||
|
\\export fn entry() void {
|
||||||
|
\\ foo() catch unreachable;
|
||||||
|
\\}
|
||||||
|
, &[_][]const u8{
|
||||||
|
"tmp.zig:2:15: error: unused variable: 'a'",
|
||||||
|
});
|
||||||
|
|
||||||
cases.addTest("shift on type with non-power-of-two size",
|
cases.addTest("shift on type with non-power-of-two size",
|
||||||
\\export fn entry() void {
|
\\export fn entry() void {
|
||||||
\\ const S = struct {
|
\\ const S = struct {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const expect = std.testing.expect;
|
const expect = std.testing.expect;
|
||||||
const expectEqual = std.testing.expectEqual;
|
const expectEqual = std.testing.expectEqual;
|
||||||
|
const expectError = std.testing.expectError;
|
||||||
|
|
||||||
var result: [3]u8 = undefined;
|
var result: [3]u8 = undefined;
|
||||||
var index: usize = undefined;
|
var index: usize = undefined;
|
||||||
|
|
@ -105,10 +106,7 @@ test "errdefer with payload" {
|
||||||
return error.One;
|
return error.One;
|
||||||
}
|
}
|
||||||
fn doTheTest() void {
|
fn doTheTest() void {
|
||||||
_ = foo() catch |err| switch (err) {
|
expectError(error.One, foo());
|
||||||
error.One => {},
|
|
||||||
else => unreachable,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
S.doTheTest();
|
S.doTheTest();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue