mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
remove %% prefix operator
See #632 closes #545 closes #510 this makes #651 higher priority
This commit is contained in:
parent
98a95cc698
commit
3c094116aa
34
build.zig
34
build.zig
@ -18,14 +18,14 @@ pub fn build(b: &Builder) {
|
||||
var docgen_cmd = b.addCommand(null, b.env_map, [][]const u8 {
|
||||
docgen_exe.getOutputPath(),
|
||||
"doc/langref.html.in",
|
||||
%%os.path.join(b.allocator, b.cache_root, "langref.html"),
|
||||
os.path.join(b.allocator, b.cache_root, "langref.html") catch unreachable,
|
||||
});
|
||||
docgen_cmd.step.dependOn(&docgen_exe.step);
|
||||
|
||||
var docgen_home_cmd = b.addCommand(null, b.env_map, [][]const u8 {
|
||||
docgen_exe.getOutputPath(),
|
||||
"doc/home.html.in",
|
||||
%%os.path.join(b.allocator, b.cache_root, "home.html"),
|
||||
os.path.join(b.allocator, b.cache_root, "home.html") catch unreachable,
|
||||
});
|
||||
docgen_home_cmd.step.dependOn(&docgen_exe.step);
|
||||
|
||||
@ -47,7 +47,7 @@ pub fn build(b: &Builder) {
|
||||
const c_header_files = nextValue(&index, build_info);
|
||||
const dia_guids_lib = nextValue(&index, build_info);
|
||||
|
||||
const llvm = findLLVM(b, llvm_config_exe);
|
||||
const llvm = findLLVM(b, llvm_config_exe) catch unreachable;
|
||||
|
||||
var exe = b.addExecutable("zig", "src-self-hosted/main.zig");
|
||||
exe.setBuildMode(mode);
|
||||
@ -143,8 +143,8 @@ fn dependOnLib(lib_exe_obj: &std.build.LibExeObjStep, dep: &const LibraryDep) {
|
||||
|
||||
fn addCppLib(b: &Builder, lib_exe_obj: &std.build.LibExeObjStep, cmake_binary_dir: []const u8, lib_name: []const u8) {
|
||||
const lib_prefix = if (lib_exe_obj.target.isWindows()) "" else "lib";
|
||||
lib_exe_obj.addObjectFile(%%os.path.join(b.allocator, cmake_binary_dir, "zig_cpp",
|
||||
b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())));
|
||||
lib_exe_obj.addObjectFile(os.path.join(b.allocator, cmake_binary_dir, "zig_cpp",
|
||||
b.fmt("{}{}{}", lib_prefix, lib_name, lib_exe_obj.target.libFileExt())) catch unreachable);
|
||||
}
|
||||
|
||||
const LibraryDep = struct {
|
||||
@ -154,7 +154,7 @@ const LibraryDep = struct {
|
||||
includes: ArrayList([]const u8),
|
||||
};
|
||||
|
||||
fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> %LibraryDep {
|
||||
const libs_output = b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
|
||||
const includes_output = b.exec([][]const u8{llvm_config_exe, "--includedir"});
|
||||
const libdir_output = b.exec([][]const u8{llvm_config_exe, "--libdir"});
|
||||
@ -169,12 +169,12 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
var it = mem.split(libs_output, " \r\n");
|
||||
while (it.next()) |lib_arg| {
|
||||
if (mem.startsWith(u8, lib_arg, "-l")) {
|
||||
%%result.system_libs.append(lib_arg[2..]);
|
||||
try result.system_libs.append(lib_arg[2..]);
|
||||
} else {
|
||||
if (os.path.isAbsolute(lib_arg)) {
|
||||
%%result.libs.append(lib_arg);
|
||||
try result.libs.append(lib_arg);
|
||||
} else {
|
||||
%%result.system_libs.append(lib_arg);
|
||||
try result.system_libs.append(lib_arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,9 +183,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
var it = mem.split(includes_output, " \r\n");
|
||||
while (it.next()) |include_arg| {
|
||||
if (mem.startsWith(u8, include_arg, "-I")) {
|
||||
%%result.includes.append(include_arg[2..]);
|
||||
try result.includes.append(include_arg[2..]);
|
||||
} else {
|
||||
%%result.includes.append(include_arg);
|
||||
try result.includes.append(include_arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -193,9 +193,9 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
var it = mem.split(libdir_output, " \r\n");
|
||||
while (it.next()) |libdir| {
|
||||
if (mem.startsWith(u8, libdir, "-L")) {
|
||||
%%result.libdirs.append(libdir[2..]);
|
||||
try result.libdirs.append(libdir[2..]);
|
||||
} else {
|
||||
%%result.libdirs.append(libdir);
|
||||
try result.libdirs.append(libdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -205,8 +205,8 @@ fn findLLVM(b: &Builder, llvm_config_exe: []const u8) -> LibraryDep {
|
||||
pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {
|
||||
var it = mem.split(stdlib_files, ";");
|
||||
while (it.next()) |stdlib_file| {
|
||||
const src_path = %%os.path.join(b.allocator, "std", stdlib_file);
|
||||
const dest_path = %%os.path.join(b.allocator, "lib", "zig", "std", stdlib_file);
|
||||
const src_path = os.path.join(b.allocator, "std", stdlib_file) catch unreachable;
|
||||
const dest_path = os.path.join(b.allocator, "lib", "zig", "std", stdlib_file) catch unreachable;
|
||||
b.installFile(src_path, dest_path);
|
||||
}
|
||||
}
|
||||
@ -214,8 +214,8 @@ pub fn installStdLib(b: &Builder, stdlib_files: []const u8) {
|
||||
pub fn installCHeaders(b: &Builder, c_header_files: []const u8) {
|
||||
var it = mem.split(c_header_files, ";");
|
||||
while (it.next()) |c_header_file| {
|
||||
const src_path = %%os.path.join(b.allocator, "c_headers", c_header_file);
|
||||
const dest_path = %%os.path.join(b.allocator, "lib", "zig", "include", c_header_file);
|
||||
const src_path = os.path.join(b.allocator, "c_headers", c_header_file) catch unreachable;
|
||||
const dest_path = os.path.join(b.allocator, "lib", "zig", "include", c_header_file) catch unreachable;
|
||||
b.installFile(src_path, dest_path);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ const os = std.os;
|
||||
|
||||
pub fn main() -> %void {
|
||||
// TODO use a more general purpose allocator here
|
||||
var inc_allocator = %%std.heap.IncrementingAllocator.init(5 * 1024 * 1024);
|
||||
var inc_allocator = try std.heap.IncrementingAllocator.init(5 * 1024 * 1024);
|
||||
defer inc_allocator.deinit();
|
||||
const allocator = &inc_allocator.allocator;
|
||||
|
||||
@ -12,16 +12,16 @@ pub fn main() -> %void {
|
||||
|
||||
if (!args_it.skip()) @panic("expected self arg");
|
||||
|
||||
const in_file_name = %%(args_it.next(allocator) ?? @panic("expected input arg"));
|
||||
const in_file_name = try (args_it.next(allocator) ?? @panic("expected input arg"));
|
||||
defer allocator.free(in_file_name);
|
||||
|
||||
const out_file_name = %%(args_it.next(allocator) ?? @panic("expected output arg"));
|
||||
const out_file_name = try (args_it.next(allocator) ?? @panic("expected output arg"));
|
||||
defer allocator.free(out_file_name);
|
||||
|
||||
var in_file = %%io.File.openRead(in_file_name, allocator);
|
||||
var in_file = try io.File.openRead(in_file_name, allocator);
|
||||
defer in_file.close();
|
||||
|
||||
var out_file = %%io.File.openWrite(out_file_name, allocator);
|
||||
var out_file = try io.File.openWrite(out_file_name, allocator);
|
||||
defer out_file.close();
|
||||
|
||||
var file_in_stream = io.FileInStream.init(&in_file);
|
||||
@ -31,7 +31,7 @@ pub fn main() -> %void {
|
||||
var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);
|
||||
|
||||
gen(&buffered_in_stream.stream, &buffered_out_stream.stream);
|
||||
%%buffered_out_stream.flush();
|
||||
try buffered_out_stream.flush();
|
||||
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) {
|
||||
switch (state) {
|
||||
State.Start => switch (byte) {
|
||||
else => {
|
||||
%%out.writeByte(byte);
|
||||
out.writeByte(byte) catch unreachable;
|
||||
},
|
||||
},
|
||||
State.Derp => unreachable,
|
||||
|
@ -5989,7 +5989,7 @@ ContainerInitBody = list(StructLiteralField, ",") | list(Expression, ",")
|
||||
|
||||
StructLiteralField = "." Symbol "=" Expression
|
||||
|
||||
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%" | "try"
|
||||
PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "??" | "-%" | "try"
|
||||
|
||||
PrimaryExpression = Integer | Float | String | CharLiteral | KeywordLiteral | GroupedExpression | BlockExpression(BlockOrExpression) | Symbol | ("@" Symbol FnCallExpression) | ArrayType | FnProto | AsmExpression | ("error" "." Symbol) | ContainerDecl | ("continue" option(":" Symbol))
|
||||
|
||||
|
@ -15,7 +15,10 @@ pub fn main() -> %void {
|
||||
try stdout.print("Welcome to the Guess Number Game in Zig.\n");
|
||||
|
||||
var seed_bytes: [@sizeOf(usize)]u8 = undefined;
|
||||
%%os.getRandomBytes(seed_bytes[0..]);
|
||||
os.getRandomBytes(seed_bytes[0..]) catch |err| {
|
||||
std.debug.warn("unable to seed random number generator: {}", err);
|
||||
return err;
|
||||
};
|
||||
const seed = std.mem.readInt(seed_bytes, usize, builtin.Endian.Big);
|
||||
var rand = Rand.init(seed);
|
||||
|
||||
|
@ -594,7 +594,6 @@ enum PrefixOp {
|
||||
PrefixOpDereference,
|
||||
PrefixOpMaybe,
|
||||
PrefixOpError,
|
||||
PrefixOpUnwrapError,
|
||||
PrefixOpUnwrapMaybe,
|
||||
};
|
||||
|
||||
|
@ -2587,7 +2587,7 @@ TypeTableEntry *get_test_fn_type(CodeGen *g) {
|
||||
return g->test_fn_type;
|
||||
|
||||
FnTypeId fn_type_id = {0};
|
||||
fn_type_id.return_type = g->builtin_types.entry_void;
|
||||
fn_type_id.return_type = get_error_type(g, g->builtin_types.entry_void);
|
||||
g->test_fn_type = get_fn_type(g, &fn_type_id);
|
||||
return g->test_fn_type;
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
|
||||
case PrefixOpDereference: return "*";
|
||||
case PrefixOpMaybe: return "?";
|
||||
case PrefixOpError: return "%";
|
||||
case PrefixOpUnwrapError: return "catch";
|
||||
case PrefixOpUnwrapMaybe: return "??";
|
||||
}
|
||||
zig_unreachable();
|
||||
|
@ -3963,8 +3963,6 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
|
||||
return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpMaybe), lval);
|
||||
case PrefixOpError:
|
||||
return ir_lval_wrap(irb, scope, ir_gen_prefix_op_id(irb, scope, node, IrUnOpError), lval);
|
||||
case PrefixOpUnwrapError:
|
||||
return ir_gen_err_assert_ok(irb, scope, node, node->data.prefix_op_expr.primary_expr, lval);
|
||||
case PrefixOpUnwrapMaybe:
|
||||
return ir_gen_maybe_assert_ok(irb, scope, node, lval);
|
||||
}
|
||||
|
@ -956,7 +956,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {
|
||||
case TokenIdStar: return PrefixOpDereference;
|
||||
case TokenIdMaybe: return PrefixOpMaybe;
|
||||
case TokenIdPercent: return PrefixOpError;
|
||||
case TokenIdPercentPercent: return PrefixOpUnwrapError;
|
||||
case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
|
||||
case TokenIdStarStar: return PrefixOpDereference;
|
||||
default: return PrefixOpInvalid;
|
||||
|
@ -816,11 +816,6 @@ void tokenize(Buf *buf, Tokenization *out) {
|
||||
end_token(&t);
|
||||
t.state = TokenizeStateStart;
|
||||
break;
|
||||
case '%':
|
||||
set_token_id(&t, t.cur_tok, TokenIdPercentPercent);
|
||||
end_token(&t);
|
||||
t.state = TokenizeStateStart;
|
||||
break;
|
||||
default:
|
||||
t.pos -= 1;
|
||||
end_token(&t);
|
||||
@ -1564,7 +1559,6 @@ const char * token_name(TokenId id) {
|
||||
case TokenIdNumberSign: return "#";
|
||||
case TokenIdPercent: return "%";
|
||||
case TokenIdPercentDot: return "%.";
|
||||
case TokenIdPercentPercent: return "%%";
|
||||
case TokenIdPlus: return "+";
|
||||
case TokenIdPlusEq: return "+=";
|
||||
case TokenIdPlusPercent: return "+%";
|
||||
|
@ -101,7 +101,6 @@ enum TokenId {
|
||||
TokenIdNumberSign,
|
||||
TokenIdPercent,
|
||||
TokenIdPercentDot,
|
||||
TokenIdPercentPercent,
|
||||
TokenIdPlus,
|
||||
TokenIdPlusEq,
|
||||
TokenIdPlusPercent,
|
||||
|
@ -116,7 +116,7 @@ test "basic ArrayList test" {
|
||||
defer list.deinit();
|
||||
|
||||
{var i: usize = 0; while (i < 10) : (i += 1) {
|
||||
%%list.append(i32(i + 1));
|
||||
list.append(i32(i + 1)) catch unreachable;
|
||||
}}
|
||||
|
||||
{var i: usize = 0; while (i < 10) : (i += 1) {
|
||||
@ -126,13 +126,13 @@ test "basic ArrayList test" {
|
||||
assert(list.pop() == 10);
|
||||
assert(list.len == 9);
|
||||
|
||||
%%list.appendSlice([]const i32 { 1, 2, 3 });
|
||||
list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable;
|
||||
assert(list.len == 12);
|
||||
assert(list.pop() == 3);
|
||||
assert(list.pop() == 2);
|
||||
assert(list.pop() == 1);
|
||||
assert(list.len == 9);
|
||||
|
||||
%%list.appendSlice([]const i32 {});
|
||||
list.appendSlice([]const i32 {}) catch unreachable;
|
||||
assert(list.len == 9);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ pub const Base64Decoder = struct {
|
||||
/// invalid characters result in error.InvalidCharacter.
|
||||
/// invalid padding results in error.InvalidPadding.
|
||||
pub fn decode(decoder: &const Base64Decoder, dest: []u8, source: []const u8) -> %void {
|
||||
assert(dest.len == %%decoder.calcSize(source));
|
||||
assert(dest.len == (decoder.calcSize(source) catch unreachable));
|
||||
assert(source.len % 4 == 0);
|
||||
|
||||
var src_cursor: usize = 0;
|
||||
@ -374,8 +374,8 @@ fn calcDecodedSizeExactUnsafe(source: []const u8, pad_char: u8) -> usize {
|
||||
|
||||
test "base64" {
|
||||
@setEvalBranchQuota(5000);
|
||||
%%testBase64();
|
||||
comptime %%testBase64();
|
||||
testBase64() catch unreachable;
|
||||
comptime (testBase64() catch unreachable);
|
||||
}
|
||||
|
||||
fn testBase64() -> %void {
|
||||
|
@ -151,20 +151,20 @@ pub const Buffer = struct {
|
||||
test "simple Buffer" {
|
||||
const cstr = @import("cstr.zig");
|
||||
|
||||
var buf = %%Buffer.init(debug.global_allocator, "");
|
||||
var buf = try Buffer.init(debug.global_allocator, "");
|
||||
assert(buf.len() == 0);
|
||||
%%buf.append("hello");
|
||||
%%buf.appendByte(' ');
|
||||
%%buf.append("world");
|
||||
try buf.append("hello");
|
||||
try buf.appendByte(' ');
|
||||
try buf.append("world");
|
||||
assert(buf.eql("hello world"));
|
||||
assert(mem.eql(u8, cstr.toSliceConst(buf.toSliceConst().ptr), buf.toSliceConst()));
|
||||
|
||||
var buf2 = %%Buffer.initFromBuffer(&buf);
|
||||
var buf2 = try Buffer.initFromBuffer(&buf);
|
||||
assert(buf.eql(buf2.toSliceConst()));
|
||||
|
||||
assert(buf.startsWith("hell"));
|
||||
assert(buf.endsWith("orld"));
|
||||
|
||||
%%buf2.resize(4);
|
||||
try buf2.resize(4);
|
||||
assert(buf.startsWith(buf2.toSliceConst()));
|
||||
}
|
||||
|
498
std/build.zig
498
std/build.zig
File diff suppressed because it is too large
Load Diff
@ -123,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
|
||||
},
|
||||
State.IntegerWidth => switch (c) {
|
||||
'}' => {
|
||||
width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
|
||||
width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
|
||||
try formatInt(args[next_arg], radix, uppercase, width, context, output);
|
||||
next_arg += 1;
|
||||
state = State.Start;
|
||||
@ -147,7 +147,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
|
||||
},
|
||||
State.FloatWidth => switch (c) {
|
||||
'}' => {
|
||||
width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
|
||||
width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
|
||||
try formatFloatDecimal(args[next_arg], width, context, output);
|
||||
next_arg += 1;
|
||||
state = State.Start;
|
||||
@ -158,7 +158,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->%void,
|
||||
},
|
||||
State.BufWidth => switch (c) {
|
||||
'}' => {
|
||||
width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
|
||||
width = comptime (parseUnsigned(usize, fmt[width_start..i], 10) catch unreachable);
|
||||
try formatBuf(args[next_arg], width, context, output);
|
||||
next_arg += 1;
|
||||
state = State.Start;
|
||||
@ -410,7 +410,7 @@ pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width:
|
||||
.out_buf = out_buf,
|
||||
.index = 0,
|
||||
};
|
||||
%%formatInt(value, base, uppercase, width, &context, formatIntCallback);
|
||||
formatInt(value, base, uppercase, width, &context, formatIntCallback) catch unreachable;
|
||||
return context.index;
|
||||
}
|
||||
const FormatIntBuf = struct {
|
||||
@ -437,12 +437,12 @@ pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) -> %T {
|
||||
}
|
||||
|
||||
test "fmt.parseInt" {
|
||||
assert(%%parseInt(i32, "-10", 10) == -10);
|
||||
assert(%%parseInt(i32, "+10", 10) == 10);
|
||||
assert((parseInt(i32, "-10", 10) catch unreachable) == -10);
|
||||
assert((parseInt(i32, "+10", 10) catch unreachable) == 10);
|
||||
assert(if (parseInt(i32, " 10", 10)) |_| false else |err| err == error.InvalidChar);
|
||||
assert(if (parseInt(i32, "10 ", 10)) |_| false else |err| err == error.InvalidChar);
|
||||
assert(if (parseInt(u32, "-10", 10)) |_| false else |err| err == error.InvalidChar);
|
||||
assert(%%parseInt(u8, "255", 10) == 255);
|
||||
assert((parseInt(u8, "255", 10) catch unreachable) == 255);
|
||||
assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
|
||||
}
|
||||
|
||||
@ -501,7 +501,7 @@ pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> %[]u8 {
|
||||
pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {
|
||||
var size: usize = 0;
|
||||
// Cannot fail because `countSize` cannot fail.
|
||||
%%format(&size, countSize, fmt, args);
|
||||
format(&size, countSize, fmt, args) catch unreachable;
|
||||
const buf = try allocator.alloc(u8, size);
|
||||
return bufPrint(buf, fmt, args);
|
||||
}
|
||||
@ -542,7 +542,7 @@ test "parse u64 digit too big" {
|
||||
|
||||
test "parse unsigned comptime" {
|
||||
comptime {
|
||||
assert(%%parseUnsigned(usize, "2", 10) == 2);
|
||||
assert((try parseUnsigned(usize, "2", 10)) == 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -550,31 +550,31 @@ test "fmt.format" {
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: ?i32 = 1234;
|
||||
const result = %%bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
assert(mem.eql(u8, result, "nullable: 1234\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: ?i32 = null;
|
||||
const result = %%bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "nullable: {}\n", value);
|
||||
assert(mem.eql(u8, result, "nullable: null\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: %i32 = 1234;
|
||||
const result = %%bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
assert(mem.eql(u8, result, "error union: 1234\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: %i32 = error.InvalidChar;
|
||||
const result = %%bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "error union: {}\n", value);
|
||||
assert(mem.eql(u8, result, "error union: error.InvalidChar\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: u3 = 0b101;
|
||||
const result = %%bufPrint(buf1[0..], "u3: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "u3: {}\n", value);
|
||||
assert(mem.eql(u8, result, "u3: 5\n"));
|
||||
}
|
||||
|
||||
@ -584,46 +584,46 @@ test "fmt.format" {
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 12.34;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 1.23400001e1\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f64 = -12.34e10;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", value);
|
||||
assert(mem.eql(u8, result, "f64: -1.234e11\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", math.nan_f64);
|
||||
assert(mem.eql(u8, result, "f64: NaN\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", math.inf_f64);
|
||||
assert(mem.eql(u8, result, "f64: Infinity\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);
|
||||
const result = try bufPrint(buf1[0..], "f64: {}\n", -math.inf_f64);
|
||||
assert(mem.eql(u8, result, "f64: -Infinity\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 1.1234;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.1}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.1}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 1.1\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 1234.567;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.2}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.2}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 1234.56\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = -11.1234;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.4}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.4}\n", value);
|
||||
// -11.1234 is converted to f64 -11.12339... internally (errol3() function takes f64).
|
||||
// -11.12339... is truncated to -11.1233
|
||||
assert(mem.eql(u8, result, "f32: -11.1233\n"));
|
||||
@ -631,13 +631,13 @@ test "fmt.format" {
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f32 = 91.12345;
|
||||
const result = %%bufPrint(buf1[0..], "f32: {.}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f32: {.}\n", value);
|
||||
assert(mem.eql(u8, result, "f32: 91.12345\n"));
|
||||
}
|
||||
{
|
||||
var buf1: [32]u8 = undefined;
|
||||
const value: f64 = 91.12345678901235;
|
||||
const result = %%bufPrint(buf1[0..], "f64: {.10}\n", value);
|
||||
const result = try bufPrint(buf1[0..], "f64: {.10}\n", value);
|
||||
assert(mem.eql(u8, result, "f64: 91.1234567890\n"));
|
||||
}
|
||||
|
||||
|
@ -236,14 +236,14 @@ test "basicHashMapTest" {
|
||||
var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator);
|
||||
defer map.deinit();
|
||||
|
||||
assert(%%map.put(1, 11) == null);
|
||||
assert(%%map.put(2, 22) == null);
|
||||
assert(%%map.put(3, 33) == null);
|
||||
assert(%%map.put(4, 44) == null);
|
||||
assert(%%map.put(5, 55) == null);
|
||||
assert((map.put(1, 11) catch unreachable) == null);
|
||||
assert((map.put(2, 22) catch unreachable) == null);
|
||||
assert((map.put(3, 33) catch unreachable) == null);
|
||||
assert((map.put(4, 44) catch unreachable) == null);
|
||||
assert((map.put(5, 55) catch unreachable) == null);
|
||||
|
||||
assert(??%%map.put(5, 66) == 55);
|
||||
assert(??%%map.put(5, 55) == 66);
|
||||
assert(??(map.put(5, 66) catch unreachable) == 55);
|
||||
assert(??(map.put(5, 55) catch unreachable) == 66);
|
||||
|
||||
assert((??map.get(2)).value == 22);
|
||||
_ = map.remove(2);
|
||||
|
@ -145,14 +145,14 @@ test "c_allocator" {
|
||||
|
||||
test "IncrementingAllocator" {
|
||||
const total_bytes = 100 * 1024 * 1024;
|
||||
var inc_allocator = %%IncrementingAllocator.init(total_bytes);
|
||||
var inc_allocator = try IncrementingAllocator.init(total_bytes);
|
||||
defer inc_allocator.deinit();
|
||||
|
||||
const allocator = &inc_allocator.allocator;
|
||||
const slice = %%allocator.alloc(&i32, 100);
|
||||
const slice = try allocator.alloc(&i32, 100);
|
||||
|
||||
for (slice) |*item, i| {
|
||||
*item = %%allocator.create(i32);
|
||||
*item = try allocator.create(i32);
|
||||
**item = i32(i);
|
||||
}
|
||||
|
||||
|
@ -18,34 +18,34 @@ test "write a file, read it, then delete it" {
|
||||
rng.fillBytes(data[0..]);
|
||||
const tmp_file_name = "temp_test_file.txt";
|
||||
{
|
||||
var file = %%io.File.openWrite(tmp_file_name, allocator);
|
||||
var file = try io.File.openWrite(tmp_file_name, allocator);
|
||||
defer file.close();
|
||||
|
||||
var file_out_stream = io.FileOutStream.init(&file);
|
||||
var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream);
|
||||
const st = &buf_stream.stream;
|
||||
%%st.print("begin");
|
||||
%%st.write(data[0..]);
|
||||
%%st.print("end");
|
||||
%%buf_stream.flush();
|
||||
try st.print("begin");
|
||||
try st.write(data[0..]);
|
||||
try st.print("end");
|
||||
try buf_stream.flush();
|
||||
}
|
||||
{
|
||||
var file = %%io.File.openRead(tmp_file_name, allocator);
|
||||
var file = try io.File.openRead(tmp_file_name, allocator);
|
||||
defer file.close();
|
||||
|
||||
const file_size = %%file.getEndPos();
|
||||
const file_size = try file.getEndPos();
|
||||
const expected_file_size = "begin".len + data.len + "end".len;
|
||||
assert(file_size == expected_file_size);
|
||||
|
||||
var file_in_stream = io.FileInStream.init(&file);
|
||||
var buf_stream = io.BufferedInStream.init(&file_in_stream.stream);
|
||||
const st = &buf_stream.stream;
|
||||
const contents = %%st.readAllAlloc(allocator, 2 * 1024);
|
||||
const contents = try st.readAllAlloc(allocator, 2 * 1024);
|
||||
defer allocator.free(contents);
|
||||
|
||||
assert(mem.eql(u8, contents[0.."begin".len], "begin"));
|
||||
assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data));
|
||||
assert(mem.eql(u8, contents[contents.len - "end".len ..], "end"));
|
||||
}
|
||||
%%os.deleteFile(allocator, tmp_file_name);
|
||||
try os.deleteFile(allocator, tmp_file_name);
|
||||
}
|
||||
|
@ -199,11 +199,11 @@ test "basic linked list test" {
|
||||
const allocator = debug.global_allocator;
|
||||
var list = LinkedList(u32).init();
|
||||
|
||||
var one = %%list.createNode(1, allocator);
|
||||
var two = %%list.createNode(2, allocator);
|
||||
var three = %%list.createNode(3, allocator);
|
||||
var four = %%list.createNode(4, allocator);
|
||||
var five = %%list.createNode(5, allocator);
|
||||
var one = list.createNode(1, allocator) catch unreachable;
|
||||
var two = list.createNode(2, allocator) catch unreachable;
|
||||
var three = list.createNode(3, allocator) catch unreachable;
|
||||
var four = list.createNode(4, allocator) catch unreachable;
|
||||
var five = list.createNode(5, allocator) catch unreachable;
|
||||
defer {
|
||||
list.destroyNode(one, allocator);
|
||||
list.destroyNode(two, allocator);
|
||||
|
@ -277,10 +277,10 @@ test "math overflow functions" {
|
||||
}
|
||||
|
||||
fn testOverflow() {
|
||||
assert(%%mul(i32, 3, 4) == 12);
|
||||
assert(%%add(i32, 3, 4) == 7);
|
||||
assert(%%sub(i32, 3, 4) == -1);
|
||||
assert(%%shlExact(i32, 0b11, 4) == 0b110000);
|
||||
assert((mul(i32, 3, 4) catch unreachable) == 12);
|
||||
assert((add(i32, 3, 4) catch unreachable) == 7);
|
||||
assert((sub(i32, 3, 4) catch unreachable) == -1);
|
||||
assert((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
|
||||
}
|
||||
|
||||
|
||||
@ -302,8 +302,8 @@ test "math.absInt" {
|
||||
comptime testAbsInt();
|
||||
}
|
||||
fn testAbsInt() {
|
||||
assert(%%absInt(i32(-10)) == 10);
|
||||
assert(%%absInt(i32(10)) == 10);
|
||||
assert((absInt(i32(-10)) catch unreachable) == 10);
|
||||
assert((absInt(i32(10)) catch unreachable) == 10);
|
||||
}
|
||||
|
||||
pub const absFloat = @import("fabs.zig").fabs;
|
||||
@ -329,13 +329,13 @@ test "math.divTrunc" {
|
||||
comptime testDivTrunc();
|
||||
}
|
||||
fn testDivTrunc() {
|
||||
assert(%%divTrunc(i32, 5, 3) == 1);
|
||||
assert(%%divTrunc(i32, -5, 3) == -1);
|
||||
assert((divTrunc(i32, 5, 3) catch unreachable) == 1);
|
||||
assert((divTrunc(i32, -5, 3) catch unreachable) == -1);
|
||||
if (divTrunc(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
if (divTrunc(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
|
||||
assert(%%divTrunc(f32, 5.0, 3.0) == 1.0);
|
||||
assert(%%divTrunc(f32, -5.0, 3.0) == -1.0);
|
||||
assert((divTrunc(f32, 5.0, 3.0) catch unreachable) == 1.0);
|
||||
assert((divTrunc(f32, -5.0, 3.0) catch unreachable) == -1.0);
|
||||
}
|
||||
|
||||
error DivisionByZero;
|
||||
@ -359,13 +359,13 @@ test "math.divFloor" {
|
||||
comptime testDivFloor();
|
||||
}
|
||||
fn testDivFloor() {
|
||||
assert(%%divFloor(i32, 5, 3) == 1);
|
||||
assert(%%divFloor(i32, -5, 3) == -2);
|
||||
assert((divFloor(i32, 5, 3) catch unreachable) == 1);
|
||||
assert((divFloor(i32, -5, 3) catch unreachable) == -2);
|
||||
if (divFloor(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
if (divFloor(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
|
||||
assert(%%divFloor(f32, 5.0, 3.0) == 1.0);
|
||||
assert(%%divFloor(f32, -5.0, 3.0) == -2.0);
|
||||
assert((divFloor(f32, 5.0, 3.0) catch unreachable) == 1.0);
|
||||
assert((divFloor(f32, -5.0, 3.0) catch unreachable) == -2.0);
|
||||
}
|
||||
|
||||
error DivisionByZero;
|
||||
@ -393,14 +393,14 @@ test "math.divExact" {
|
||||
comptime testDivExact();
|
||||
}
|
||||
fn testDivExact() {
|
||||
assert(%%divExact(i32, 10, 5) == 2);
|
||||
assert(%%divExact(i32, -10, 5) == -2);
|
||||
assert((divExact(i32, 10, 5) catch unreachable) == 2);
|
||||
assert((divExact(i32, -10, 5) catch unreachable) == -2);
|
||||
if (divExact(i8, -5, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
if (divExact(i8, -128, -1)) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
if (divExact(i32, 5, 2)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
|
||||
|
||||
assert(%%divExact(f32, 10.0, 5.0) == 2.0);
|
||||
assert(%%divExact(f32, -10.0, 5.0) == -2.0);
|
||||
assert((divExact(f32, 10.0, 5.0) catch unreachable) == 2.0);
|
||||
assert((divExact(f32, -10.0, 5.0) catch unreachable) == -2.0);
|
||||
if (divExact(f32, 5.0, 2.0)) |_| unreachable else |err| assert(err == error.UnexpectedRemainder);
|
||||
}
|
||||
|
||||
@ -420,13 +420,13 @@ test "math.mod" {
|
||||
comptime testMod();
|
||||
}
|
||||
fn testMod() {
|
||||
assert(%%mod(i32, -5, 3) == 1);
|
||||
assert(%%mod(i32, 5, 3) == 2);
|
||||
assert((mod(i32, -5, 3) catch unreachable) == 1);
|
||||
assert((mod(i32, 5, 3) catch unreachable) == 2);
|
||||
if (mod(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (mod(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
|
||||
assert(%%mod(f32, -5, 3) == 1);
|
||||
assert(%%mod(f32, 5, 3) == 2);
|
||||
assert((mod(f32, -5, 3) catch unreachable) == 1);
|
||||
assert((mod(f32, 5, 3) catch unreachable) == 2);
|
||||
if (mod(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (mod(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
}
|
||||
@ -447,13 +447,13 @@ test "math.rem" {
|
||||
comptime testRem();
|
||||
}
|
||||
fn testRem() {
|
||||
assert(%%rem(i32, -5, 3) == -2);
|
||||
assert(%%rem(i32, 5, 3) == 2);
|
||||
assert((rem(i32, -5, 3) catch unreachable) == -2);
|
||||
assert((rem(i32, 5, 3) catch unreachable) == 2);
|
||||
if (rem(i32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (rem(i32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
|
||||
assert(%%rem(f32, -5, 3) == -2);
|
||||
assert(%%rem(f32, 5, 3) == 2);
|
||||
assert((rem(f32, -5, 3) catch unreachable) == -2);
|
||||
assert((rem(f32, 5, 3) catch unreachable) == 2);
|
||||
if (rem(f32, 10, -1)) |_| unreachable else |err| assert(err == error.NegativeDenominator);
|
||||
if (rem(f32, 10, 0)) |_| unreachable else |err| assert(err == error.DivisionByZero);
|
||||
}
|
||||
@ -497,11 +497,11 @@ pub fn negateCast(x: var) -> %@IntType(true, @typeOf(x).bit_count) {
|
||||
}
|
||||
|
||||
test "math.negateCast" {
|
||||
assert(%%negateCast(u32(999)) == -999);
|
||||
assert(@typeOf(%%negateCast(u32(999))) == i32);
|
||||
assert((negateCast(u32(999)) catch unreachable) == -999);
|
||||
assert(@typeOf(negateCast(u32(999)) catch unreachable) == i32);
|
||||
|
||||
assert(%%negateCast(u32(-@minValue(i32))) == @minValue(i32));
|
||||
assert(@typeOf(%%negateCast(u32(-@minValue(i32)))) == i32);
|
||||
assert((negateCast(u32(-@minValue(i32))) catch unreachable) == @minValue(i32));
|
||||
assert(@typeOf(negateCast(u32(-@minValue(i32))) catch unreachable) == i32);
|
||||
|
||||
if (negateCast(u32(@maxValue(i32) + 10))) |_| unreachable else |err| assert(err == error.Overflow);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ pub const Allocator = struct {
|
||||
// n <= old_mem.len and the multiplication didn't overflow for that operation.
|
||||
const byte_count = @sizeOf(T) * n;
|
||||
|
||||
const byte_slice = %%self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment);
|
||||
const byte_slice = self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment) catch unreachable;
|
||||
return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
|
||||
}
|
||||
|
||||
@ -446,8 +446,8 @@ pub fn join(allocator: &Allocator, sep: u8, strings: ...) -> %[]u8 {
|
||||
}
|
||||
|
||||
test "mem.join" {
|
||||
assert(eql(u8, %%join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c"));
|
||||
assert(eql(u8, %%join(debug.global_allocator, ',', "a"), "a"));
|
||||
assert(eql(u8, try join(debug.global_allocator, ',', "a", "b", "c"), "a,b,c"));
|
||||
assert(eql(u8, try join(debug.global_allocator, ',', "a"), "a"));
|
||||
}
|
||||
|
||||
test "testStringEquality" {
|
||||
|
89
std/net.zig
89
std/net.zig
@ -3,6 +3,8 @@ const linux = std.os.linux;
|
||||
const assert = std.debug.assert;
|
||||
const endian = std.endian;
|
||||
|
||||
// TODO don't trust this file, it bit rotted. start over
|
||||
|
||||
error SigInterrupt;
|
||||
error Io;
|
||||
error TimedOut;
|
||||
@ -67,24 +69,9 @@ const Address = struct {
|
||||
pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
|
||||
if (hostname.len == 0) {
|
||||
|
||||
//
|
||||
// if (family != AF_INET6)
|
||||
// buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } };
|
||||
// if (family != AF_INET)
|
||||
// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
|
||||
//
|
||||
unreachable; // TODO
|
||||
}
|
||||
|
||||
// TODO
|
||||
//switch (parseIpLiteral(hostname)) {
|
||||
// Ok => |addr| {
|
||||
// out_addrs[0] = addr;
|
||||
// return out_addrs[0..1];
|
||||
// },
|
||||
// else => {},
|
||||
//};
|
||||
|
||||
unreachable; // TODO
|
||||
}
|
||||
|
||||
@ -142,23 +129,6 @@ pub fn connect(hostname: []const u8, port: u16) -> %Connection {
|
||||
error InvalidIpLiteral;
|
||||
|
||||
pub fn parseIpLiteral(buf: []const u8) -> %Address {
|
||||
// TODO
|
||||
//switch (parseIp4(buf)) {
|
||||
// Ok => |ip4| {
|
||||
// var result: Address = undefined;
|
||||
// @memcpy(&result.addr[0], (&u8)(&ip4), @sizeOf(u32));
|
||||
// result.family = linux.AF_INET;
|
||||
// result.scope_id = 0;
|
||||
// return result;
|
||||
// },
|
||||
// else => {},
|
||||
//}
|
||||
//switch (parseIp6(buf)) {
|
||||
// Ok => |addr| {
|
||||
// return addr;
|
||||
// },
|
||||
// else => {},
|
||||
//}
|
||||
|
||||
return error.InvalidIpLiteral;
|
||||
}
|
||||
@ -249,21 +219,6 @@ fn parseIp6(buf: []const u8) -> %Address {
|
||||
return error.Incomplete;
|
||||
}
|
||||
|
||||
//
|
||||
// if (p) {
|
||||
// if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
|
||||
// else z = p-1;
|
||||
// if (*z) {
|
||||
// if (!IN6_IS_ADDR_LINKLOCAL(&a6) and
|
||||
// !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
|
||||
// return EAI_NONAME;
|
||||
// scopeid = if_nametoindex(p);
|
||||
// if (!scopeid) return EAI_NONAME;
|
||||
// }
|
||||
// if (scopeid > UINT_MAX) return EAI_NONAME;
|
||||
// }
|
||||
//
|
||||
|
||||
if (scope_id) {
|
||||
return result;
|
||||
}
|
||||
@ -316,43 +271,3 @@ fn parseIp4(buf: []const u8) -> %u32 {
|
||||
|
||||
return error.Incomplete;
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
//fn testParseIp4() {
|
||||
// @setFnTest(this);
|
||||
//
|
||||
// assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));
|
||||
// switch (parseIp4("256.0.0.1")) { Overflow => {}, else => unreachable, }
|
||||
// switch (parseIp4("x.0.0.1")) { InvalidChar => {}, else => unreachable, }
|
||||
// switch (parseIp4("127.0.0.1.1")) { JunkAtEnd => {}, else => unreachable, }
|
||||
// switch (parseIp4("127.0.0.")) { Incomplete => {}, else => unreachable, }
|
||||
// switch (parseIp4("100..0.1")) { InvalidChar => {}, else => unreachable, }
|
||||
//}
|
||||
//
|
||||
//fn testParseIp6() {
|
||||
// @setFnTest(this);
|
||||
//
|
||||
// {
|
||||
// const addr = %%parseIp6("FF01:0:0:0:0:0:0:FB");
|
||||
// assert(addr.addr[0] == 0xff);
|
||||
// assert(addr.addr[1] == 0x01);
|
||||
// assert(addr.addr[2] == 0x00);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//fn testLookupSimpleIp() {
|
||||
// @setFnTest(this);
|
||||
//
|
||||
// {
|
||||
// var addrs_buf: [5]Address = undefined;
|
||||
// const addrs = %%lookup("192.168.1.1", addrs_buf);
|
||||
// assert(addrs.len == 1);
|
||||
// const addr = addrs[0];
|
||||
// assert(addr.family == linux.AF_INET);
|
||||
// assert(addr.addr[0] == 192);
|
||||
// assert(addr.addr[1] == 168);
|
||||
// assert(addr.addr[2] == 1);
|
||||
// assert(addr.addr[3] == 1);
|
||||
// }
|
||||
//}
|
||||
|
@ -191,7 +191,7 @@ pub const ChildProcess = struct {
|
||||
pub fn exec(allocator: &mem.Allocator, argv: []const []const u8, cwd: ?[]const u8,
|
||||
env_map: ?&const BufMap, max_output_size: usize) -> %ExecResult
|
||||
{
|
||||
const child = %%ChildProcess.init(argv, allocator);
|
||||
const child = try ChildProcess.init(argv, allocator);
|
||||
defer child.deinit();
|
||||
|
||||
child.stdin_behavior = ChildProcess.StdIo.Ignore;
|
||||
|
@ -121,7 +121,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
|
||||
|
||||
test "os.getRandomBytes" {
|
||||
var buf: [50]u8 = undefined;
|
||||
%%getRandomBytes(buf[0..]);
|
||||
try getRandomBytes(buf[0..]);
|
||||
}
|
||||
|
||||
/// Raises a signal in the current kernel thread, ending its execution.
|
||||
@ -1489,7 +1489,7 @@ test "windows arg parsing" {
|
||||
fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const u8) {
|
||||
var it = ArgIteratorWindows.initWithCmdLine(input_cmd_line);
|
||||
for (expected_args) |expected_arg| {
|
||||
const arg = %%??it.next(debug.global_allocator);
|
||||
const arg = ??it.next(debug.global_allocator) catch unreachable;
|
||||
assert(mem.eql(u8, arg, expected_arg));
|
||||
}
|
||||
assert(it.next(debug.global_allocator) == null);
|
||||
|
@ -49,23 +49,23 @@ pub fn joinPosix(allocator: &Allocator, paths: ...) -> %[]u8 {
|
||||
}
|
||||
|
||||
test "os.path.join" {
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\b\\", "c"), "c:\\a\\b\\c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\", "a", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator, "c:\\a\\", "b\\", "c"), "c:\\a\\b\\c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinWindows(debug.global_allocator,
|
||||
assert(mem.eql(u8, try joinWindows(debug.global_allocator,
|
||||
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig"),
|
||||
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig"));
|
||||
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/b/", "c"), "/a/b/c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/", "a", "b/", "c"), "/a/b/c"));
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/a/", "b/", "c"), "/a/b/c"));
|
||||
|
||||
assert(mem.eql(u8, %%joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"),
|
||||
assert(mem.eql(u8, try joinPosix(debug.global_allocator, "/home/andy/dev/zig/build/lib/zig/std", "io.zig"),
|
||||
"/home/andy/dev/zig/build/lib/zig/std/io.zig"));
|
||||
}
|
||||
|
||||
@ -584,7 +584,7 @@ pub fn resolvePosix(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
|
||||
}
|
||||
|
||||
test "os.path.resolve" {
|
||||
const cwd = %%os.getCwd(debug.global_allocator);
|
||||
const cwd = try os.getCwd(debug.global_allocator);
|
||||
if (is_windows) {
|
||||
if (windowsParsePath(cwd).kind == WindowsPath.Kind.Drive) {
|
||||
cwd[0] = asciiUpper(cwd[0]);
|
||||
@ -598,11 +598,11 @@ test "os.path.resolve" {
|
||||
|
||||
test "os.path.resolveWindows" {
|
||||
if (is_windows) {
|
||||
const cwd = %%os.getCwd(debug.global_allocator);
|
||||
const cwd = try os.getCwd(debug.global_allocator);
|
||||
const parsed_cwd = windowsParsePath(cwd);
|
||||
{
|
||||
const result = testResolveWindows([][]const u8{"/usr/local", "lib\\zig\\std\\array_list.zig"});
|
||||
const expected = %%join(debug.global_allocator,
|
||||
const expected = try join(debug.global_allocator,
|
||||
parsed_cwd.disk_designator, "usr\\local\\lib\\zig\\std\\array_list.zig");
|
||||
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
|
||||
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
|
||||
@ -611,7 +611,7 @@ test "os.path.resolveWindows" {
|
||||
}
|
||||
{
|
||||
const result = testResolveWindows([][]const u8{"usr/local", "lib\\zig"});
|
||||
const expected = %%join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
|
||||
const expected = try join(debug.global_allocator, cwd, "usr\\local\\lib\\zig");
|
||||
if (parsed_cwd.kind == WindowsPath.Kind.Drive) {
|
||||
expected[0] = asciiUpper(parsed_cwd.disk_designator[0]);
|
||||
}
|
||||
@ -649,11 +649,11 @@ test "os.path.resolvePosix" {
|
||||
}
|
||||
|
||||
fn testResolveWindows(paths: []const []const u8) -> []u8 {
|
||||
return %%resolveWindows(debug.global_allocator, paths);
|
||||
return resolveWindows(debug.global_allocator, paths) catch unreachable;
|
||||
}
|
||||
|
||||
fn testResolvePosix(paths: []const []const u8) -> []u8 {
|
||||
return %%resolvePosix(debug.global_allocator, paths);
|
||||
return resolvePosix(debug.global_allocator, paths) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn dirname(path: []const u8) -> []const u8 {
|
||||
@ -1057,12 +1057,12 @@ test "os.path.relative" {
|
||||
}
|
||||
|
||||
fn testRelativePosix(from: []const u8, to: []const u8, expected_output: []const u8) {
|
||||
const result = %%relativePosix(debug.global_allocator, from, to);
|
||||
const result = relativePosix(debug.global_allocator, from, to) catch unreachable;
|
||||
assert(mem.eql(u8, result, expected_output));
|
||||
}
|
||||
|
||||
fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []const u8) {
|
||||
const result = %%relativeWindows(debug.global_allocator, from, to);
|
||||
const result = relativeWindows(debug.global_allocator, from, to) catch unreachable;
|
||||
assert(mem.eql(u8, result, expected_output));
|
||||
}
|
||||
|
||||
@ -1172,7 +1172,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
|
||||
defer os.close(fd);
|
||||
|
||||
var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;
|
||||
const proc_path = %%fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd);
|
||||
const proc_path = fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd) catch unreachable;
|
||||
|
||||
return os.readLink(allocator, proc_path);
|
||||
},
|
||||
|
@ -74,7 +74,7 @@ pub const Rand = struct {
|
||||
return T(r.range(uint, uint(start), uint(end)));
|
||||
} else if (start < 0 and end < 0) {
|
||||
// Can't overflow because the range is over signed ints
|
||||
return %%math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1);
|
||||
return math.negateCast(r.range(uint, math.absCast(end), math.absCast(start)) + 1) catch unreachable;
|
||||
} else if (start < 0 and end >= 0) {
|
||||
const end_uint = uint(end);
|
||||
const total_range = math.absCast(start) + end_uint;
|
||||
@ -85,7 +85,7 @@ pub const Rand = struct {
|
||||
break :x start;
|
||||
} else x: {
|
||||
// Can't overflow because the range is over signed ints
|
||||
break :x %%math.negateCast(value - end_uint);
|
||||
break :x math.negateCast(value - end_uint) catch unreachable;
|
||||
};
|
||||
return result;
|
||||
} else {
|
||||
|
@ -1115,7 +1115,7 @@ var fixed_buffer_mem: [100 * 1024]u8 = undefined;
|
||||
fn fuzzTest(rng: &std.rand.Rand) {
|
||||
const array_size = rng.range(usize, 0, 1000);
|
||||
var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
|
||||
var array = %%fixed_allocator.allocator.alloc(IdAndValue, array_size);
|
||||
var array = fixed_allocator.allocator.alloc(IdAndValue, array_size) catch unreachable;
|
||||
// populate with random data
|
||||
for (array) |*item, index| {
|
||||
item.id = index;
|
||||
|
@ -14,7 +14,7 @@ pub fn main() -> %void {
|
||||
var arg_it = os.args();
|
||||
|
||||
// TODO use a more general purpose allocator here
|
||||
var inc_allocator = %%std.heap.IncrementingAllocator.init(40 * 1024 * 1024);
|
||||
var inc_allocator = std.heap.IncrementingAllocator.init(40 * 1024 * 1024) catch unreachable;
|
||||
defer inc_allocator.deinit();
|
||||
|
||||
const allocator = &inc_allocator.allocator;
|
||||
@ -107,7 +107,7 @@ pub fn main() -> %void {
|
||||
return usageAndErr(&builder, false, try stderr_stream);
|
||||
}
|
||||
} else {
|
||||
%%targets.append(arg);
|
||||
targets.append(arg) catch unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,10 @@ pub fn main() -> %void {
|
||||
for (test_fn_list) |test_fn, i| {
|
||||
warn("Test {}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
|
||||
|
||||
test_fn.func();
|
||||
test_fn.func() catch |err| {
|
||||
warn("{}\n", err);
|
||||
return err;
|
||||
};
|
||||
|
||||
warn("OK\n");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ error Utf8EncodesSurrogateHalf;
|
||||
error Utf8CodepointTooLarge;
|
||||
|
||||
/// Decodes the UTF-8 codepoint encoded in the given slice of bytes.
|
||||
/// bytes.len must be equal to %%utf8ByteSequenceLength(bytes[0]).
|
||||
/// bytes.len must be equal to utf8ByteSequenceLength(bytes[0]) catch unreachable.
|
||||
/// If you already know the length at comptime, you can call one of
|
||||
/// utf8Decode2,utf8Decode3,utf8Decode4 directly instead of this function.
|
||||
pub fn utf8Decode(bytes: []const u8) -> %u32 {
|
||||
@ -158,7 +158,7 @@ fn testError(bytes: []const u8, expected_err: error) {
|
||||
}
|
||||
|
||||
fn testValid(bytes: []const u8, expected_codepoint: u32) {
|
||||
std.debug.assert(%%testDecode(bytes) == expected_codepoint);
|
||||
std.debug.assert((testDecode(bytes) catch unreachable) == expected_codepoint);
|
||||
}
|
||||
|
||||
fn testDecode(bytes: []const u8) -> %u32 {
|
||||
|
@ -85,14 +85,14 @@ const A = struct {
|
||||
fn castToMaybeTypeError(z: i32) {
|
||||
const x = i32(1);
|
||||
const y: %?i32 = x;
|
||||
assert(??%%y == 1);
|
||||
assert(??(try y) == 1);
|
||||
|
||||
const f = z;
|
||||
const g: %?i32 = f;
|
||||
|
||||
const a = A{ .a = z };
|
||||
const b: %?A = a;
|
||||
assert((??%%b).a == 1);
|
||||
assert((??(b catch unreachable)).a == 1);
|
||||
}
|
||||
|
||||
test "implicitly cast from int to %?T" {
|
||||
@ -108,7 +108,7 @@ fn implicitIntLitToMaybe() {
|
||||
test "return null from fn() -> %?&T" {
|
||||
const a = returnNullFromMaybeTypeErrorRef();
|
||||
const b = returnNullLitFromMaybeTypeErrorRef();
|
||||
assert(%%a == null and %%b == null);
|
||||
assert((try a) == null and (try b) == null);
|
||||
}
|
||||
fn returnNullFromMaybeTypeErrorRef() -> %?&A {
|
||||
const a: ?&A = null;
|
||||
@ -167,7 +167,7 @@ test "implicitly cast from [0]T to %[]T" {
|
||||
}
|
||||
|
||||
fn testCastZeroArrayToErrSliceMut() {
|
||||
assert((%%gimmeErrOrSlice()).len == 0);
|
||||
assert((gimmeErrOrSlice() catch unreachable).len == 0);
|
||||
}
|
||||
|
||||
fn gimmeErrOrSlice() -> %[]u8 {
|
||||
@ -178,14 +178,14 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" {
|
||||
{
|
||||
var data = "hi";
|
||||
const slice = data[0..];
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
}
|
||||
comptime {
|
||||
var data = "hi";
|
||||
const slice = data[0..];
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
|
||||
assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
|
||||
}
|
||||
}
|
||||
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
|
||||
@ -231,11 +231,11 @@ fn foo(args: ...) {
|
||||
|
||||
test "peer type resolution: error and [N]T" {
|
||||
// TODO: implicit %T to %U where T can implicitly cast to U
|
||||
//assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK"));
|
||||
//comptime assert(mem.eql(u8, %%testPeerErrorAndArray(0), "OK"));
|
||||
//assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
|
||||
//comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK"));
|
||||
|
||||
assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK"));
|
||||
comptime assert(mem.eql(u8, %%testPeerErrorAndArray2(1), "OKK"));
|
||||
assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
|
||||
comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK"));
|
||||
}
|
||||
|
||||
error BadValue;
|
||||
|
@ -21,7 +21,7 @@ fn foo(args: [][]const u8) {
|
||||
}
|
||||
|
||||
fn bar(argc: usize) {
|
||||
const args = %%debug.global_allocator.alloc([]const u8, argc);
|
||||
const args = debug.global_allocator.alloc([]const u8, argc) catch unreachable;
|
||||
for (args) |_, i| {
|
||||
const ptr = argv[i];
|
||||
args[i] = ptr[0..strlen(ptr)];
|
||||
|
@ -14,7 +14,7 @@ fn runSomeErrorDefers(x: bool) -> %bool {
|
||||
}
|
||||
|
||||
test "mixing normal and error defers" {
|
||||
assert(%%runSomeErrorDefers(true));
|
||||
assert(runSomeErrorDefers(true) catch unreachable);
|
||||
assert(result[0] == 'c');
|
||||
assert(result[1] == 'a');
|
||||
|
||||
|
@ -19,9 +19,9 @@ test "enum with members" {
|
||||
const b = ET { .UINT = 42 };
|
||||
var buf: [20]u8 = undefined;
|
||||
|
||||
assert(%%a.print(buf[0..]) == 3);
|
||||
assert((a.print(buf[0..]) catch unreachable) == 3);
|
||||
assert(mem.eql(u8, buf[0..3], "-42"));
|
||||
|
||||
assert(%%b.print(buf[0..]) == 2);
|
||||
assert((b.print(buf[0..]) catch unreachable) == 2);
|
||||
assert(mem.eql(u8, buf[0..2], "42"));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub fn baz() -> %i32 {
|
||||
}
|
||||
|
||||
test "error wrapping" {
|
||||
assert(%%baz() == 15);
|
||||
assert((baz() catch unreachable) == 15);
|
||||
}
|
||||
|
||||
error ItBroke;
|
||||
@ -65,14 +65,14 @@ fn errBinaryOperatorG(x: bool) -> %isize {
|
||||
|
||||
|
||||
test "unwrap simple value from error" {
|
||||
const i = %%unwrapSimpleValueFromErrorDo();
|
||||
const i = unwrapSimpleValueFromErrorDo() catch unreachable;
|
||||
assert(i == 13);
|
||||
}
|
||||
fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }
|
||||
|
||||
|
||||
test "error return in assignment" {
|
||||
%%doErrReturnInAssignment();
|
||||
doErrReturnInAssignment() catch unreachable;
|
||||
}
|
||||
|
||||
fn doErrReturnInAssignment() -> %void {
|
||||
|
@ -16,6 +16,6 @@ fn getErrInt() -> %i32 { return 0; }
|
||||
error ItBroke;
|
||||
|
||||
test "ir block deps" {
|
||||
assert(%%foo(1) == 0);
|
||||
assert(%%foo(2) == 0);
|
||||
assert((foo(1) catch unreachable) == 0);
|
||||
assert((foo(2) catch unreachable) == 0);
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ test "explicit cast maybe pointers" {
|
||||
}
|
||||
|
||||
test "generic malloc free" {
|
||||
const a = %%memAlloc(u8, 10);
|
||||
const a = memAlloc(u8, 10) catch unreachable;
|
||||
memFree(u8, a);
|
||||
}
|
||||
const some_mem : [100]u8 = undefined;
|
||||
@ -417,7 +417,7 @@ test "cast slice to u8 slice" {
|
||||
}
|
||||
|
||||
test "pointer to void return type" {
|
||||
%%testPointerToVoidReturnType();
|
||||
testPointerToVoidReturnType() catch unreachable;
|
||||
}
|
||||
fn testPointerToVoidReturnType() -> %void {
|
||||
const a = testPointerToVoidReturnType2();
|
||||
|
@ -22,7 +22,7 @@ fn doThing(form_id: u64) -> %FormValue {
|
||||
}
|
||||
|
||||
test "switch prong returns error enum" {
|
||||
switch (%%doThing(17)) {
|
||||
switch (doThing(17) catch unreachable) {
|
||||
FormValue.Address => |payload| { assert(payload == 1); },
|
||||
else => unreachable,
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ fn foo(id: u64) -> %FormValue {
|
||||
}
|
||||
|
||||
test "switch prong implicit cast" {
|
||||
const result = switch (%%foo(2)) {
|
||||
const result = switch (foo(2) catch unreachable) {
|
||||
FormValue.One => false,
|
||||
FormValue.Two => |x| x,
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ test "unions embedded in aggregate types" {
|
||||
Value.Array => |arr| assert(arr[4] == 3),
|
||||
else => unreachable,
|
||||
}
|
||||
switch((%%err).val1) {
|
||||
switch((err catch unreachable).val1) {
|
||||
Value.Int => |x| assert(x == 1234),
|
||||
else => unreachable,
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ fn runContinueAndBreakTest() {
|
||||
}
|
||||
|
||||
test "return with implicit cast from while loop" {
|
||||
%%returnWithImplicitCastFromWhileLoopTest();
|
||||
returnWithImplicitCastFromWhileLoopTest() catch unreachable;
|
||||
}
|
||||
fn returnWithImplicitCastFromWhileLoopTest() -> %void {
|
||||
while (true) {
|
||||
|
@ -17,8 +17,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\
|
||||
\\pub fn main() -> %void {
|
||||
\\ privateFunction();
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK 2\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK 2\n") catch unreachable;
|
||||
\\}
|
||||
\\
|
||||
\\fn privateFunction() {
|
||||
@ -32,8 +32,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\// purposefully conflicting function with main.zig
|
||||
\\// but it's private so it should be OK
|
||||
\\fn privateFunction() {
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK 1\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK 1\n") catch unreachable;
|
||||
\\}
|
||||
\\
|
||||
\\pub fn printText() {
|
||||
@ -58,8 +58,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
tc.addSourceFile("foo.zig",
|
||||
\\use @import("std").io;
|
||||
\\pub fn foo_function() {
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\}
|
||||
);
|
||||
|
||||
@ -69,8 +69,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\
|
||||
\\pub fn bar_function() {
|
||||
\\ if (foo_function()) {
|
||||
\\ const stdout = &(FileOutStream.init(&%%getStdOut()).stream);
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ const stdout = &(FileOutStream.init(&(getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\ }
|
||||
\\}
|
||||
);
|
||||
@ -101,8 +101,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\pub const a_text = "OK\n";
|
||||
\\
|
||||
\\pub fn ok() {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print(b_text);
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print(b_text) catch unreachable;
|
||||
\\}
|
||||
);
|
||||
|
||||
@ -119,8 +119,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\const io = @import("std").io;
|
||||
\\
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a'));
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("Hello, world!\n{d4} {x3} {c}\n", u32(12), u16(0x12), u8('a')) catch unreachable;
|
||||
\\}
|
||||
, "Hello, world!\n0012 012 a\n");
|
||||
|
||||
@ -272,8 +272,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\ var x_local : i32 = print_ok(x);
|
||||
\\}
|
||||
\\fn print_ok(val: @typeOf(x)) -> @typeOf(foo) {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\ return 0;
|
||||
\\}
|
||||
\\const foo : i32 = 0;
|
||||
@ -354,26 +354,26 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\pub fn main() -> %void {
|
||||
\\ const bar = Bar {.field2 = 13,};
|
||||
\\ const foo = Foo {.field1 = bar,};
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ if (!foo.method()) {
|
||||
\\ %%stdout.print("BAD\n");
|
||||
\\ stdout.print("BAD\n") catch unreachable;
|
||||
\\ }
|
||||
\\ if (!bar.method()) {
|
||||
\\ %%stdout.print("BAD\n");
|
||||
\\ stdout.print("BAD\n") catch unreachable;
|
||||
\\ }
|
||||
\\ %%stdout.print("OK\n");
|
||||
\\ stdout.print("OK\n") catch unreachable;
|
||||
\\}
|
||||
, "OK\n");
|
||||
|
||||
cases.add("defer with only fallthrough",
|
||||
\\const io = @import("std").io;
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ defer %%stdout.print("defer2\n");
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ defer stdout.print("defer2\n") catch unreachable;
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
, "before\nafter\ndefer3\ndefer2\ndefer1\n");
|
||||
|
||||
@ -381,14 +381,14 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\const io = @import("std").io;
|
||||
\\const os = @import("std").os;
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ defer %%stdout.print("defer2\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ defer stdout.print("defer2\n") catch unreachable;
|
||||
\\ var args_it = @import("std").os.args();
|
||||
\\ if (args_it.skip() and !args_it.skip()) return;
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
, "before\ndefer2\ndefer1\n");
|
||||
|
||||
@ -398,13 +398,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\ do_test() catch return;
|
||||
\\}
|
||||
\\fn do_test() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ %defer %%stdout.print("deferErr\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ %defer stdout.print("deferErr\n") catch unreachable;
|
||||
\\ try its_gonna_fail();
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
\\error IToldYouItWouldFail;
|
||||
\\fn its_gonna_fail() -> %void {
|
||||
@ -418,13 +418,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\ do_test() catch return;
|
||||
\\}
|
||||
\\fn do_test() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print("before\n");
|
||||
\\ defer %%stdout.print("defer1\n");
|
||||
\\ %defer %%stdout.print("deferErr\n");
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print("before\n") catch unreachable;
|
||||
\\ defer stdout.print("defer1\n") catch unreachable;
|
||||
\\ %defer stdout.print("deferErr\n") catch unreachable;
|
||||
\\ try its_gonna_pass();
|
||||
\\ defer %%stdout.print("defer3\n");
|
||||
\\ %%stdout.print("after\n");
|
||||
\\ defer stdout.print("defer3\n") catch unreachable;
|
||||
\\ stdout.print("after\n") catch unreachable;
|
||||
\\}
|
||||
\\fn its_gonna_pass() -> %void { }
|
||||
, "before\nafter\ndefer3\ndefer1\n");
|
||||
@ -435,8 +435,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
|
||||
\\const io = @import("std").io;
|
||||
\\
|
||||
\\pub fn main() -> %void {
|
||||
\\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
|
||||
\\ %%stdout.print(foo_txt);
|
||||
\\ const stdout = &(io.FileOutStream.init(&(io.getStdOut() catch unreachable)).stream);
|
||||
\\ stdout.print(foo_txt) catch unreachable;
|
||||
\\}
|
||||
, "1234\nabcd\n");
|
||||
|
||||
|
@ -1423,10 +1423,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
|
||||
|
||||
cases.add("ignored assert-err-ok return value",
|
||||
\\export fn foo() {
|
||||
\\ %%bar();
|
||||
\\ bar() catch unreachable;
|
||||
\\}
|
||||
\\fn bar() -> %i32 { return 0; }
|
||||
, ".tmp_source.zig:2:5: error: expression value is ignored");
|
||||
, ".tmp_source.zig:2:11: error: expression value is ignored");
|
||||
|
||||
cases.add("ignored statement value",
|
||||
\\export fn foo() {
|
||||
|
@ -3,5 +3,5 @@ pub fn panic(msg: []const u8) -> noreturn { @breakpoint(); while (true) {} }
|
||||
fn bar() -> %void {}
|
||||
|
||||
export fn foo() {
|
||||
%%bar();
|
||||
bar() catch unreachable;
|
||||
}
|
||||
|
138
test/tests.zig
138
test/tests.zig
@ -54,7 +54,7 @@ error TestFailed;
|
||||
const max_stdout_size = 1 * 1024 * 1024; // 1 MB
|
||||
|
||||
pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompareOutputContext);
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
*cases = CompareOutputContext {
|
||||
.b = b,
|
||||
.step = b.step("test-compare-output", "Run the compare output tests"),
|
||||
@ -68,7 +68,7 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
|
||||
}
|
||||
|
||||
pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompareOutputContext);
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
*cases = CompareOutputContext {
|
||||
.b = b,
|
||||
.step = b.step("test-debug-safety", "Run the debug safety tests"),
|
||||
@ -82,7 +82,7 @@ pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &buil
|
||||
}
|
||||
|
||||
pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompileErrorContext);
|
||||
const cases = b.allocator.create(CompileErrorContext) catch unreachable;
|
||||
*cases = CompileErrorContext {
|
||||
.b = b,
|
||||
.step = b.step("test-compile-errors", "Run the compile error tests"),
|
||||
@ -96,7 +96,7 @@ pub fn addCompileErrorTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
|
||||
}
|
||||
|
||||
pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(BuildExamplesContext);
|
||||
const cases = b.allocator.create(BuildExamplesContext) catch unreachable;
|
||||
*cases = BuildExamplesContext {
|
||||
.b = b,
|
||||
.step = b.step("test-build-examples", "Build the examples"),
|
||||
@ -110,7 +110,7 @@ pub fn addBuildExampleTests(b: &build.Builder, test_filter: ?[]const u8) -> &bui
|
||||
}
|
||||
|
||||
pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(CompareOutputContext);
|
||||
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
|
||||
*cases = CompareOutputContext {
|
||||
.b = b,
|
||||
.step = b.step("test-asm-link", "Run the assemble and link tests"),
|
||||
@ -124,7 +124,7 @@ pub fn addAssembleAndLinkTests(b: &build.Builder, test_filter: ?[]const u8) -> &
|
||||
}
|
||||
|
||||
pub fn addTranslateCTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
|
||||
const cases = %%b.allocator.create(TranslateCContext);
|
||||
const cases = b.allocator.create(TranslateCContext) catch unreachable;
|
||||
*cases = TranslateCContext {
|
||||
.b = b,
|
||||
.step = b.step("test-translate-c", "Run the C header file parsing tests"),
|
||||
@ -197,10 +197,10 @@ pub const CompareOutputContext = struct {
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
||||
%%self.sources.append(SourceFile {
|
||||
self.sources.append(SourceFile {
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn setCommandLineArgs(self: &TestCase, args: []const []const u8) {
|
||||
@ -222,7 +222,7 @@ pub const CompareOutputContext = struct {
|
||||
cli_args: []const []const u8) -> &RunCompareOutputStep
|
||||
{
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(RunCompareOutputStep);
|
||||
const ptr = allocator.create(RunCompareOutputStep) catch unreachable;
|
||||
*ptr = RunCompareOutputStep {
|
||||
.context = context,
|
||||
.exe_path = exe_path,
|
||||
@ -244,14 +244,14 @@ pub const CompareOutputContext = struct {
|
||||
var args = ArrayList([]const u8).init(b.allocator);
|
||||
defer args.deinit();
|
||||
|
||||
%%args.append(full_exe_path);
|
||||
args.append(full_exe_path) catch unreachable;
|
||||
for (self.cli_args) |arg| {
|
||||
%%args.append(arg);
|
||||
args.append(arg) catch unreachable;
|
||||
}
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
||||
const child = %%os.ChildProcess.init(args.toSliceConst(), b.allocator);
|
||||
const child = os.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.stdin_behavior = StdIo.Ignore;
|
||||
@ -267,8 +267,8 @@ pub const CompareOutputContext = struct {
|
||||
var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
|
||||
var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
|
||||
|
||||
%%stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size);
|
||||
%%stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size);
|
||||
stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
|
||||
@ -313,7 +313,7 @@ pub const CompareOutputContext = struct {
|
||||
name: []const u8) -> &DebugSafetyRunStep
|
||||
{
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(DebugSafetyRunStep);
|
||||
const ptr = allocator.create(DebugSafetyRunStep) catch unreachable;
|
||||
*ptr = DebugSafetyRunStep {
|
||||
.context = context,
|
||||
.exe_path = exe_path,
|
||||
@ -333,7 +333,7 @@ pub const CompareOutputContext = struct {
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
||||
const child = %%os.ChildProcess.init([][]u8{full_exe_path}, b.allocator);
|
||||
const child = os.ChildProcess.init([][]u8{full_exe_path}, b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.env_map = &b.env_map;
|
||||
@ -416,11 +416,11 @@ pub const CompareOutputContext = struct {
|
||||
pub fn addCase(self: &CompareOutputContext, case: &const TestCase) {
|
||||
const b = self.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename);
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, case.sources.items[0].filename) catch unreachable;
|
||||
|
||||
switch (case.special) {
|
||||
Special.Asm => {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name);
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "assemble-and-link {}", case.name) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
@ -430,7 +430,7 @@ pub const CompareOutputContext = struct {
|
||||
exe.addAssemblyFile(root_src);
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
exe.step.dependOn(&write_src.step);
|
||||
}
|
||||
@ -443,8 +443,8 @@ pub const CompareOutputContext = struct {
|
||||
},
|
||||
Special.None => {
|
||||
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "{} {} ({})",
|
||||
"compare-output", case.name, @tagName(mode));
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})",
|
||||
"compare-output", case.name, @tagName(mode)) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
continue;
|
||||
@ -457,7 +457,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
exe.step.dependOn(&write_src.step);
|
||||
}
|
||||
@ -470,7 +470,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
},
|
||||
Special.DebugSafety => {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "safety {}", case.name);
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
@ -482,7 +482,7 @@ pub const CompareOutputContext = struct {
|
||||
}
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
exe.step.dependOn(&write_src.step);
|
||||
}
|
||||
@ -515,14 +515,14 @@ pub const CompileErrorContext = struct {
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
||||
%%self.sources.append(SourceFile {
|
||||
self.sources.append(SourceFile {
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedError(self: &TestCase, text: []const u8) {
|
||||
%%self.expected_errors.append(text);
|
||||
self.expected_errors.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
@ -538,7 +538,7 @@ pub const CompileErrorContext = struct {
|
||||
case: &const TestCase, build_mode: Mode) -> &CompileCmpOutputStep
|
||||
{
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(CompileCmpOutputStep);
|
||||
const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
|
||||
*ptr = CompileCmpOutputStep {
|
||||
.step = build.Step.init("CompileCmpOutput", allocator, make),
|
||||
.context = context,
|
||||
@ -555,25 +555,25 @@ pub const CompileErrorContext = struct {
|
||||
const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
||||
const obj_path = %%os.path.join(b.allocator, b.cache_root, "test.o");
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
|
||||
const obj_path = os.path.join(b.allocator, b.cache_root, "test.o") catch unreachable;
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
%%zig_args.append(b.zig_exe);
|
||||
zig_args.append(b.zig_exe) catch unreachable;
|
||||
|
||||
%%zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj");
|
||||
%%zig_args.append(b.pathFromRoot(root_src));
|
||||
zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
||||
|
||||
%%zig_args.append("--name");
|
||||
%%zig_args.append("test");
|
||||
zig_args.append("--name") catch unreachable;
|
||||
zig_args.append("test") catch unreachable;
|
||||
|
||||
%%zig_args.append("--output");
|
||||
%%zig_args.append(b.pathFromRoot(obj_path));
|
||||
zig_args.append("--output") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(obj_path)) catch unreachable;
|
||||
|
||||
switch (self.build_mode) {
|
||||
Mode.Debug => {},
|
||||
Mode.ReleaseSafe => %%zig_args.append("--release-safe"),
|
||||
Mode.ReleaseFast => %%zig_args.append("--release-fast"),
|
||||
Mode.ReleaseSafe => zig_args.append("--release-safe") catch unreachable,
|
||||
Mode.ReleaseFast => zig_args.append("--release-fast") catch unreachable,
|
||||
}
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
@ -582,7 +582,7 @@ pub const CompileErrorContext = struct {
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
}
|
||||
|
||||
const child = %%os.ChildProcess.init(zig_args.toSliceConst(), b.allocator);
|
||||
const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.env_map = &b.env_map;
|
||||
@ -598,8 +598,8 @@ pub const CompileErrorContext = struct {
|
||||
var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
|
||||
var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
|
||||
|
||||
%%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size);
|
||||
%%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size);
|
||||
stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
|
||||
@ -660,7 +660,7 @@ pub const CompileErrorContext = struct {
|
||||
pub fn create(self: &CompileErrorContext, name: []const u8, source: []const u8,
|
||||
expected_lines: ...) -> &TestCase
|
||||
{
|
||||
const tc = %%self.b.allocator.create(TestCase);
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
*tc = TestCase {
|
||||
.name = name,
|
||||
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
||||
@ -697,8 +697,8 @@ pub const CompileErrorContext = struct {
|
||||
const b = self.b;
|
||||
|
||||
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "compile-error {} ({})",
|
||||
case.name, @tagName(mode));
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "compile-error {} ({})",
|
||||
case.name, @tagName(mode)) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
continue;
|
||||
@ -708,7 +708,7 @@ pub const CompileErrorContext = struct {
|
||||
self.step.dependOn(&compile_and_cmp_errors.step);
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
compile_and_cmp_errors.step.dependOn(&write_src.step);
|
||||
}
|
||||
@ -740,17 +740,17 @@ pub const BuildExamplesContext = struct {
|
||||
}
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
const rel_zig_exe = %%os.path.relative(b.allocator, b.build_root, b.zig_exe);
|
||||
%%zig_args.append(rel_zig_exe);
|
||||
%%zig_args.append("build");
|
||||
const rel_zig_exe = os.path.relative(b.allocator, b.build_root, b.zig_exe) catch unreachable;
|
||||
zig_args.append(rel_zig_exe) catch unreachable;
|
||||
zig_args.append("build") catch unreachable;
|
||||
|
||||
%%zig_args.append("--build-file");
|
||||
%%zig_args.append(b.pathFromRoot(build_file));
|
||||
zig_args.append("--build-file") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(build_file)) catch unreachable;
|
||||
|
||||
%%zig_args.append("test");
|
||||
zig_args.append("test") catch unreachable;
|
||||
|
||||
if (b.verbose) {
|
||||
%%zig_args.append("--verbose");
|
||||
zig_args.append("--verbose") catch unreachable;
|
||||
}
|
||||
|
||||
const run_cmd = b.addCommand(null, b.env_map, zig_args.toSliceConst());
|
||||
@ -765,8 +765,8 @@ pub const BuildExamplesContext = struct {
|
||||
const b = self.b;
|
||||
|
||||
for ([]Mode{Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast}) |mode| {
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "build {} ({})",
|
||||
root_src, @tagName(mode));
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "build {} ({})",
|
||||
root_src, @tagName(mode)) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
continue;
|
||||
@ -804,14 +804,14 @@ pub const TranslateCContext = struct {
|
||||
};
|
||||
|
||||
pub fn addSourceFile(self: &TestCase, filename: []const u8, source: []const u8) {
|
||||
%%self.sources.append(SourceFile {
|
||||
self.sources.append(SourceFile {
|
||||
.filename = filename,
|
||||
.source = source,
|
||||
});
|
||||
}) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn addExpectedLine(self: &TestCase, text: []const u8) {
|
||||
%%self.expected_lines.append(text);
|
||||
self.expected_lines.append(text) catch unreachable;
|
||||
}
|
||||
};
|
||||
|
||||
@ -824,7 +824,7 @@ pub const TranslateCContext = struct {
|
||||
|
||||
pub fn create(context: &TranslateCContext, name: []const u8, case: &const TestCase) -> &TranslateCCmpOutputStep {
|
||||
const allocator = context.b.allocator;
|
||||
const ptr = %%allocator.create(TranslateCCmpOutputStep);
|
||||
const ptr = allocator.create(TranslateCCmpOutputStep) catch unreachable;
|
||||
*ptr = TranslateCCmpOutputStep {
|
||||
.step = build.Step.init("ParseCCmpOutput", allocator, make),
|
||||
.context = context,
|
||||
@ -840,13 +840,13 @@ pub const TranslateCContext = struct {
|
||||
const self = @fieldParentPtr(TranslateCCmpOutputStep, "step", step);
|
||||
const b = self.context.b;
|
||||
|
||||
const root_src = %%os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename);
|
||||
const root_src = os.path.join(b.allocator, b.cache_root, self.case.sources.items[0].filename) catch unreachable;
|
||||
|
||||
var zig_args = ArrayList([]const u8).init(b.allocator);
|
||||
%%zig_args.append(b.zig_exe);
|
||||
zig_args.append(b.zig_exe) catch unreachable;
|
||||
|
||||
%%zig_args.append("translate-c");
|
||||
%%zig_args.append(b.pathFromRoot(root_src));
|
||||
zig_args.append("translate-c") catch unreachable;
|
||||
zig_args.append(b.pathFromRoot(root_src)) catch unreachable;
|
||||
|
||||
warn("Test {}/{} {}...", self.test_index+1, self.context.test_index, self.name);
|
||||
|
||||
@ -854,7 +854,7 @@ pub const TranslateCContext = struct {
|
||||
printInvocation(zig_args.toSliceConst());
|
||||
}
|
||||
|
||||
const child = %%os.ChildProcess.init(zig_args.toSliceConst(), b.allocator);
|
||||
const child = os.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
|
||||
defer child.deinit();
|
||||
|
||||
child.env_map = &b.env_map;
|
||||
@ -870,8 +870,8 @@ pub const TranslateCContext = struct {
|
||||
var stdout_file_in_stream = io.FileInStream.init(&??child.stdout);
|
||||
var stderr_file_in_stream = io.FileInStream.init(&??child.stderr);
|
||||
|
||||
%%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size);
|
||||
%%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size);
|
||||
stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
|
||||
stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
|
||||
|
||||
const term = child.wait() catch |err| {
|
||||
debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
|
||||
@ -933,7 +933,7 @@ pub const TranslateCContext = struct {
|
||||
pub fn create(self: &TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8,
|
||||
source: []const u8, expected_lines: ...) -> &TestCase
|
||||
{
|
||||
const tc = %%self.b.allocator.create(TestCase);
|
||||
const tc = self.b.allocator.create(TestCase) catch unreachable;
|
||||
*tc = TestCase {
|
||||
.name = name,
|
||||
.sources = ArrayList(TestCase.SourceFile).init(self.b.allocator),
|
||||
@ -966,7 +966,7 @@ pub const TranslateCContext = struct {
|
||||
pub fn addCase(self: &TranslateCContext, case: &const TestCase) {
|
||||
const b = self.b;
|
||||
|
||||
const annotated_case_name = %%fmt.allocPrint(self.b.allocator, "translate-c {}", case.name);
|
||||
const annotated_case_name = fmt.allocPrint(self.b.allocator, "translate-c {}", case.name) catch unreachable;
|
||||
if (self.test_filter) |filter| {
|
||||
if (mem.indexOf(u8, annotated_case_name, filter) == null)
|
||||
return;
|
||||
@ -976,7 +976,7 @@ pub const TranslateCContext = struct {
|
||||
self.step.dependOn(&translate_c_and_cmp.step);
|
||||
|
||||
for (case.sources.toSliceConst()) |src_file| {
|
||||
const expanded_src_path = %%os.path.join(b.allocator, b.cache_root, src_file.filename);
|
||||
const expanded_src_path = os.path.join(b.allocator, b.cache_root, src_file.filename) catch unreachable;
|
||||
const write_src = b.addWriteFile(expanded_src_path, src_file.source);
|
||||
translate_c_and_cmp.step.dependOn(&write_src.step);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user