authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 19:33:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-07 22:43:53-07:00
logd8e26275f29b304772bfeed9359e1ff5fe7038a8
treeb255b2a136beedb6a411ad0eae273354d9c4040c
parentc873c2eed9f9bcd4e8d8d6937ea7c3644d382440

update standalone and incremental tests to new API


72 files changed, 335 insertions(+), 880 deletions(-)

doc/langref.html.in+2-1
...@@ -374,7 +374,8 @@...@@ -374,7 +374,8 @@
374 <p>374 <p>
375 Most of the time, it is more appropriate to write to stderr rather than stdout, and375 Most of the time, it is more appropriate to write to stderr rather than stdout, and
376 whether or not the message is successfully written to the stream is irrelevant.376 whether or not the message is successfully written to the stream is irrelevant.
377 For this common case, there is a simpler API:377 Also, formatted printing often comes in handy. For this common case,
378 there is a simpler API:
378 </p>379 </p>
379 {#code|hello_again.zig#}380 {#code|hello_again.zig#}
380381
doc/langref/bad_default_value.zig+1-1
...@@ -17,7 +17,7 @@ pub fn main() !void {...@@ -17,7 +17,7 @@ pub fn main() !void {
17 .maximum = 0.20,17 .maximum = 0.20,
18 };18 };
19 const category = threshold.categorize(0.90);19 const category = threshold.categorize(0.90);
20 try std.io.getStdOut().writeAll(@tagName(category));20 try std.fs.File.stdout().writeAll(@tagName(category));
21}21}
2222
23const std = @import("std");23const std = @import("std");
doc/langref/hello.zig+1-2
...@@ -1,8 +1,7 @@...@@ -1,8 +1,7 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() !void {3pub fn main() !void {
4 const stdout = std.io.getStdOut().writer();4 try std.fs.File.stdout().writeAll("Hello, World!\n");
5 try stdout.print("Hello, {s}!\n", .{"world"});
6}5}
76
8// exe=succeed7// exe=succeed
doc/langref/hello_again.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() void {3pub fn main() void {
4 std.debug.print("Hello, world!\n", .{});4 std.debug.print("Hello, {s}!\n", .{"World"});
5}5}
66
7// exe=succeed7// exe=succeed
lib/compiler/resinator/cli.zig+13-14
...@@ -125,13 +125,12 @@ pub const Diagnostics = struct {...@@ -125,13 +125,12 @@ pub const Diagnostics = struct {
125 }125 }
126126
127 pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void {127 pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void {
128 std.debug.lockStdErr();128 const stderr = std.debug.lockStderrWriter(&.{});
129 defer std.debug.unlockStdErr();129 defer std.debug.unlockStderrWriter();
130 const stderr = std.fs.File.stderr().deprecatedWriter();
131 self.renderToWriter(args, stderr, config) catch return;130 self.renderToWriter(args, stderr, config) catch return;
132 }131 }
133132
134 pub fn renderToWriter(self: *Diagnostics, args: []const []const u8, writer: anytype, config: std.io.tty.Config) !void {133 pub fn renderToWriter(self: *Diagnostics, args: []const []const u8, writer: *std.io.Writer, config: std.io.tty.Config) !void {
135 for (self.errors.items) |err_details| {134 for (self.errors.items) |err_details| {
136 try renderErrorMessage(writer, config, err_details, args);135 try renderErrorMessage(writer, config, err_details, args);
137 }136 }
...@@ -1403,7 +1402,7 @@ test parsePercent {...@@ -1403,7 +1402,7 @@ test parsePercent {
1403 try std.testing.expectError(error.InvalidFormat, parsePercent("~1"));1402 try std.testing.expectError(error.InvalidFormat, parsePercent("~1"));
1404}1403}
14051404
1406pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {1405pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void {
1407 try config.setColor(writer, .dim);1406 try config.setColor(writer, .dim);
1408 try writer.writeAll("<cli>");1407 try writer.writeAll("<cli>");
1409 try config.setColor(writer, .reset);1408 try config.setColor(writer, .reset);
...@@ -1481,27 +1480,27 @@ pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, err_detail...@@ -1481,27 +1480,27 @@ pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, err_detail
1481 try writer.writeByte('\n');1480 try writer.writeByte('\n');
14821481
1483 try config.setColor(writer, .green);1482 try config.setColor(writer, .green);
1484 try writer.writeByteNTimes(' ', prefix.len);1483 try writer.splatByteAll(' ', prefix.len);
1485 // Special case for when the option is *only* a prefix (e.g. invalid option: -)1484 // Special case for when the option is *only* a prefix (e.g. invalid option: -)
1486 if (err_details.arg_span.prefix_len == arg_with_name.len) {1485 if (err_details.arg_span.prefix_len == arg_with_name.len) {
1487 try writer.writeByteNTimes('^', err_details.arg_span.prefix_len);1486 try writer.splatByteAll('^', err_details.arg_span.prefix_len);
1488 } else {1487 } else {
1489 try writer.writeByteNTimes('~', err_details.arg_span.prefix_len);1488 try writer.splatByteAll('~', err_details.arg_span.prefix_len);
1490 try writer.writeByteNTimes(' ', err_details.arg_span.name_offset - err_details.arg_span.prefix_len);1489 try writer.splatByteAll(' ', err_details.arg_span.name_offset - err_details.arg_span.prefix_len);
1491 if (!err_details.arg_span.point_at_next_arg and err_details.arg_span.value_offset == 0) {1490 if (!err_details.arg_span.point_at_next_arg and err_details.arg_span.value_offset == 0) {
1492 try writer.writeByte('^');1491 try writer.writeByte('^');
1493 try writer.writeByteNTimes('~', name_slice.len - 1);1492 try writer.splatByteAll('~', name_slice.len - 1);
1494 } else if (err_details.arg_span.value_offset > 0) {1493 } else if (err_details.arg_span.value_offset > 0) {
1495 try writer.writeByteNTimes('~', err_details.arg_span.value_offset - err_details.arg_span.name_offset);1494 try writer.splatByteAll('~', err_details.arg_span.value_offset - err_details.arg_span.name_offset);
1496 try writer.writeByte('^');1495 try writer.writeByte('^');
1497 if (err_details.arg_span.value_offset < arg_with_name.len) {1496 if (err_details.arg_span.value_offset < arg_with_name.len) {
1498 try writer.writeByteNTimes('~', arg_with_name.len - err_details.arg_span.value_offset - 1);1497 try writer.splatByteAll('~', arg_with_name.len - err_details.arg_span.value_offset - 1);
1499 }1498 }
1500 } else if (err_details.arg_span.point_at_next_arg) {1499 } else if (err_details.arg_span.point_at_next_arg) {
1501 try writer.writeByteNTimes('~', arg_with_name.len - err_details.arg_span.name_offset + 1);1500 try writer.splatByteAll('~', arg_with_name.len - err_details.arg_span.name_offset + 1);
1502 try writer.writeByte('^');1501 try writer.writeByte('^');
1503 if (next_arg_len > 0) {1502 if (next_arg_len > 0) {
1504 try writer.writeByteNTimes('~', next_arg_len - 1);1503 try writer.splatByteAll('~', next_arg_len - 1);
1505 }1504 }
1506 }1505 }
1507 }1506 }
lib/compiler/resinator/errors.zig+18-19
...@@ -62,9 +62,8 @@ pub const Diagnostics = struct {...@@ -62,9 +62,8 @@ pub const Diagnostics = struct {
62 }62 }
6363
64 pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void {64 pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void {
65 std.debug.lockStdErr();65 const stderr = std.debug.lockStderrWriter(&.{});
66 defer std.debug.unlockStdErr();66 defer std.debug.unlockStderrWriter();
67 const stderr = std.fs.File.stderr().deprecatedWriter();
68 for (self.errors.items) |err_details| {67 for (self.errors.items) |err_details| {
69 renderErrorMessage(stderr, tty_config, cwd, err_details, source, self.strings.items, source_mappings) catch return;68 renderErrorMessage(stderr, tty_config, cwd, err_details, source, self.strings.items, source_mappings) catch return;
70 }69 }
...@@ -445,7 +444,7 @@ pub const ErrorDetails = struct {...@@ -445,7 +444,7 @@ pub const ErrorDetails = struct {
445 pub fn render(self: ErrorDetails, writer: anytype, source: []const u8, strings: []const []const u8) !void {444 pub fn render(self: ErrorDetails, writer: anytype, source: []const u8, strings: []const []const u8) !void {
446 switch (self.err) {445 switch (self.err) {
447 .unfinished_string_literal => {446 .unfinished_string_literal => {
448 return writer.print("unfinished string literal at '{s}', expected closing '\"'", .{self.fmtToken(source)});447 return writer.print("unfinished string literal at '{f}', expected closing '\"'", .{self.fmtToken(source)});
449 },448 },
450 .string_literal_too_long => {449 .string_literal_too_long => {
451 return writer.print("string literal too long (max is currently {} characters)", .{self.extra.number});450 return writer.print("string literal too long (max is currently {} characters)", .{self.extra.number});
...@@ -524,26 +523,26 @@ pub const ErrorDetails = struct {...@@ -524,26 +523,26 @@ pub const ErrorDetails = struct {
524 return writer.print("unsupported code page '{s} (id={})' in #pragma code_page", .{ @tagName(code_page), number });523 return writer.print("unsupported code page '{s} (id={})' in #pragma code_page", .{ @tagName(code_page), number });
525 },524 },
526 .unfinished_raw_data_block => {525 .unfinished_raw_data_block => {
527 return writer.print("unfinished raw data block at '{s}', expected closing '}}' or 'END'", .{self.fmtToken(source)});526 return writer.print("unfinished raw data block at '{f}', expected closing '}}' or 'END'", .{self.fmtToken(source)});
528 },527 },
529 .unfinished_string_table_block => {528 .unfinished_string_table_block => {
530 return writer.print("unfinished STRINGTABLE block at '{s}', expected closing '}}' or 'END'", .{self.fmtToken(source)});529 return writer.print("unfinished STRINGTABLE block at '{f}', expected closing '}}' or 'END'", .{self.fmtToken(source)});
531 },530 },
532 .expected_token => {531 .expected_token => {
533 return writer.print("expected '{s}', got '{s}'", .{ self.extra.expected.nameForErrorDisplay(), self.fmtToken(source) });532 return writer.print("expected '{s}', got '{f}'", .{ self.extra.expected.nameForErrorDisplay(), self.fmtToken(source) });
534 },533 },
535 .expected_something_else => {534 .expected_something_else => {
536 try writer.writeAll("expected ");535 try writer.writeAll("expected ");
537 try self.extra.expected_types.writeCommaSeparated(writer);536 try self.extra.expected_types.writeCommaSeparated(writer);
538 return writer.print("; got '{s}'", .{self.fmtToken(source)});537 return writer.print("; got '{f}'", .{self.fmtToken(source)});
539 },538 },
540 .resource_type_cant_use_raw_data => switch (self.type) {539 .resource_type_cant_use_raw_data => switch (self.type) {
541 .err, .warning => try writer.print("expected '<filename>', found '{s}' (resource type '{s}' can't use raw data)", .{ self.fmtToken(source), self.extra.resource.nameForErrorDisplay() }),540 .err, .warning => try writer.print("expected '<filename>', found '{f}' (resource type '{s}' can't use raw data)", .{ self.fmtToken(source), self.extra.resource.nameForErrorDisplay() }),
542 .note => try writer.print("if '{s}' is intended to be a filename, it must be specified as a quoted string literal", .{self.fmtToken(source)}),541 .note => try writer.print("if '{f}' is intended to be a filename, it must be specified as a quoted string literal", .{self.fmtToken(source)}),
543 .hint => return,542 .hint => return,
544 },543 },
545 .id_must_be_ordinal => {544 .id_must_be_ordinal => {
546 try writer.print("id of resource type '{s}' must be an ordinal (u16), got '{s}'", .{ self.extra.resource.nameForErrorDisplay(), self.fmtToken(source) });545 try writer.print("id of resource type '{s}' must be an ordinal (u16), got '{f}'", .{ self.extra.resource.nameForErrorDisplay(), self.fmtToken(source) });
547 },546 },
548 .name_or_id_not_allowed => {547 .name_or_id_not_allowed => {
549 try writer.print("name or id is not allowed for resource type '{s}'", .{self.extra.resource.nameForErrorDisplay()});548 try writer.print("name or id is not allowed for resource type '{s}'", .{self.extra.resource.nameForErrorDisplay()});
...@@ -559,7 +558,7 @@ pub const ErrorDetails = struct {...@@ -559,7 +558,7 @@ pub const ErrorDetails = struct {
559 try writer.writeAll("ASCII character not equivalent to virtual key code");558 try writer.writeAll("ASCII character not equivalent to virtual key code");
560 },559 },
561 .empty_menu_not_allowed => {560 .empty_menu_not_allowed => {
562 try writer.print("empty menu of type '{s}' not allowed", .{self.fmtToken(source)});561 try writer.print("empty menu of type '{f}' not allowed", .{self.fmtToken(source)});
563 },562 },
564 .rc_would_miscompile_version_value_padding => switch (self.type) {563 .rc_would_miscompile_version_value_padding => switch (self.type) {
565 .err, .warning => return writer.print("the padding before this quoted string value would be miscompiled by the Win32 RC compiler", .{}),564 .err, .warning => return writer.print("the padding before this quoted string value would be miscompiled by the Win32 RC compiler", .{}),
...@@ -624,7 +623,7 @@ pub const ErrorDetails = struct {...@@ -624,7 +623,7 @@ pub const ErrorDetails = struct {
624 .string_already_defined => switch (self.type) {623 .string_already_defined => switch (self.type) {
625 .err, .warning => {624 .err, .warning => {
626 const language = self.extra.string_and_language.language;625 const language = self.extra.string_and_language.language;
627 return writer.print("string with id {d} (0x{X}) already defined for language {}", .{ self.extra.string_and_language.id, self.extra.string_and_language.id, language });626 return writer.print("string with id {d} (0x{X}) already defined for language {f}", .{ self.extra.string_and_language.id, self.extra.string_and_language.id, language });
628 },627 },
629 .note => return writer.print("previous definition of string with id {d} (0x{X}) here", .{ self.extra.string_and_language.id, self.extra.string_and_language.id }),628 .note => return writer.print("previous definition of string with id {d} (0x{X}) here", .{ self.extra.string_and_language.id, self.extra.string_and_language.id }),
630 .hint => return,629 .hint => return,
...@@ -639,7 +638,7 @@ pub const ErrorDetails = struct {...@@ -639,7 +638,7 @@ pub const ErrorDetails = struct {
639 try writer.print("unable to open file '{s}': {s}", .{ strings[self.extra.file_open_error.filename_string_index], @tagName(self.extra.file_open_error.err) });638 try writer.print("unable to open file '{s}': {s}", .{ strings[self.extra.file_open_error.filename_string_index], @tagName(self.extra.file_open_error.err) });
640 },639 },
641 .invalid_accelerator_key => {640 .invalid_accelerator_key => {
642 try writer.print("invalid accelerator key '{s}': {s}", .{ self.fmtToken(source), @tagName(self.extra.accelerator_error.err) });641 try writer.print("invalid accelerator key '{f}': {s}", .{ self.fmtToken(source), @tagName(self.extra.accelerator_error.err) });
643 },642 },
644 .accelerator_type_required => {643 .accelerator_type_required => {
645 try writer.writeAll("accelerator type [ASCII or VIRTKEY] required when key is an integer");644 try writer.writeAll("accelerator type [ASCII or VIRTKEY] required when key is an integer");
...@@ -895,7 +894,7 @@ fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usiz...@@ -895,7 +894,7 @@ fn cellCount(code_page: SupportedCodePage, source: []const u8, start_index: usiz
895894
896const truncated_str = "<...truncated...>";895const truncated_str = "<...truncated...>";
897896
898pub fn renderErrorMessage(writer: anytype, tty_config: std.io.tty.Config, cwd: std.fs.Dir, err_details: ErrorDetails, source: []const u8, strings: []const []const u8, source_mappings: ?SourceMappings) !void {897pub fn renderErrorMessage(writer: *std.io.Writer, tty_config: std.io.tty.Config, cwd: std.fs.Dir, err_details: ErrorDetails, source: []const u8, strings: []const []const u8, source_mappings: ?SourceMappings) !void {
899 if (err_details.type == .hint) return;898 if (err_details.type == .hint) return;
900899
901 const source_line_start = err_details.token.getLineStartForErrorDisplay(source);900 const source_line_start = err_details.token.getLineStartForErrorDisplay(source);
...@@ -978,10 +977,10 @@ pub fn renderErrorMessage(writer: anytype, tty_config: std.io.tty.Config, cwd: s...@@ -978,10 +977,10 @@ pub fn renderErrorMessage(writer: anytype, tty_config: std.io.tty.Config, cwd: s
978977
979 try tty_config.setColor(writer, .green);978 try tty_config.setColor(writer, .green);
980 const num_spaces = truncated_visual_info.point_offset - truncated_visual_info.before_len;979 const num_spaces = truncated_visual_info.point_offset - truncated_visual_info.before_len;
981 try writer.writeByteNTimes(' ', num_spaces);980 try writer.splatByteAll(' ', num_spaces);
982 try writer.writeByteNTimes('~', truncated_visual_info.before_len);981 try writer.splatByteAll('~', truncated_visual_info.before_len);
983 try writer.writeByte('^');982 try writer.writeByte('^');
984 try writer.writeByteNTimes('~', truncated_visual_info.after_len);983 try writer.splatByteAll('~', truncated_visual_info.after_len);
985 try writer.writeByte('\n');984 try writer.writeByte('\n');
986 try tty_config.setColor(writer, .reset);985 try tty_config.setColor(writer, .reset);
987986
...@@ -1082,7 +1081,7 @@ const CorrespondingLines = struct {...@@ -1082,7 +1081,7 @@ const CorrespondingLines = struct {
1082 buffered_reader: BufferedReaderType,1081 buffered_reader: BufferedReaderType,
1083 code_page: SupportedCodePage,1082 code_page: SupportedCodePage,
10841083
1085 const BufferedReaderType = std.io.BufferedReader(512, std.fs.File.Reader);1084 const BufferedReaderType = std.io.BufferedReader(512, std.fs.File.DeprecatedReader);
10861085
1087 pub fn init(cwd: std.fs.Dir, err_details: ErrorDetails, line_for_comparison: []const u8, corresponding_span: SourceMappings.CorrespondingSpan, corresponding_file: []const u8) !CorrespondingLines {1086 pub fn init(cwd: std.fs.Dir, err_details: ErrorDetails, line_for_comparison: []const u8, corresponding_span: SourceMappings.CorrespondingSpan, corresponding_file: []const u8) !CorrespondingLines {
1088 // We don't do line comparison for this error, so don't print the note if the line1087 // We don't do line comparison for this error, so don't print the note if the line
lib/compiler/resinator/main.zig+10-6
...@@ -29,7 +29,7 @@ pub fn main() !void {...@@ -29,7 +29,7 @@ pub fn main() !void {
29 defer std.process.argsFree(allocator, args);29 defer std.process.argsFree(allocator, args);
3030
31 if (args.len < 2) {31 if (args.len < 2) {
32 try renderErrorMessage(stderr.deprecatedWriter(), stderr_config, .err, "expected zig lib dir as first argument", .{});32 try renderErrorMessage(std.debug.lockStderrWriter(&.{}), stderr_config, .err, "expected zig lib dir as first argument", .{});
33 std.process.exit(1);33 std.process.exit(1);
34 }34 }
35 const zig_lib_dir = args[1];35 const zig_lib_dir = args[1];
...@@ -343,7 +343,7 @@ pub fn main() !void {...@@ -343,7 +343,7 @@ pub fn main() !void {
343 switch (err) {343 switch (err) {
344 error.DuplicateResource => {344 error.DuplicateResource => {
345 const duplicate_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];345 const duplicate_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
346 try error_handler.emitMessage(allocator, .err, "duplicate resource [id: {}, type: {}, language: {}]", .{346 try error_handler.emitMessage(allocator, .err, "duplicate resource [id: {f}, type: {f}, language: {f}]", .{
347 duplicate_resource.name_value,347 duplicate_resource.name_value,
348 fmtResourceType(duplicate_resource.type_value),348 fmtResourceType(duplicate_resource.type_value),
349 duplicate_resource.language,349 duplicate_resource.language,
...@@ -352,7 +352,7 @@ pub fn main() !void {...@@ -352,7 +352,7 @@ pub fn main() !void {
352 error.ResourceDataTooLong => {352 error.ResourceDataTooLong => {
353 const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];353 const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
354 try error_handler.emitMessage(allocator, .err, "resource has a data length that is too large to be written into a coff section", .{});354 try error_handler.emitMessage(allocator, .err, "resource has a data length that is too large to be written into a coff section", .{});
355 try error_handler.emitMessage(allocator, .note, "the resource with the invalid size is [id: {}, type: {}, language: {}]", .{355 try error_handler.emitMessage(allocator, .note, "the resource with the invalid size is [id: {f}, type: {f}, language: {f}]", .{
356 overflow_resource.name_value,356 overflow_resource.name_value,
357 fmtResourceType(overflow_resource.type_value),357 fmtResourceType(overflow_resource.type_value),
358 overflow_resource.language,358 overflow_resource.language,
...@@ -361,7 +361,7 @@ pub fn main() !void {...@@ -361,7 +361,7 @@ pub fn main() !void {
361 error.TotalResourceDataTooLong => {361 error.TotalResourceDataTooLong => {
362 const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];362 const overflow_resource = resources.list.items[cvtres_diagnostics.duplicate_resource];
363 try error_handler.emitMessage(allocator, .err, "total resource data exceeds the maximum of the coff 'size of raw data' field", .{});363 try error_handler.emitMessage(allocator, .err, "total resource data exceeds the maximum of the coff 'size of raw data' field", .{});
364 try error_handler.emitMessage(allocator, .note, "size overflow occurred when attempting to write this resource: [id: {}, type: {}, language: {}]", .{364 try error_handler.emitMessage(allocator, .note, "size overflow occurred when attempting to write this resource: [id: {f}, type: {f}, language: {f}]", .{
365 overflow_resource.name_value,365 overflow_resource.name_value,
366 fmtResourceType(overflow_resource.type_value),366 fmtResourceType(overflow_resource.type_value),
367 overflow_resource.language,367 overflow_resource.language,
...@@ -645,7 +645,9 @@ const ErrorHandler = union(enum) {...@@ -645,7 +645,9 @@ const ErrorHandler = union(enum) {
645 },645 },
646 .tty => {646 .tty => {
647 // extra newline to separate this line from the aro errors647 // extra newline to separate this line from the aro errors
648 try renderErrorMessage(std.fs.File.stderr().deprecatedWriter(), self.tty, .err, "{s}\n", .{fail_msg});648 const stderr = std.debug.lockStderrWriter(&.{});
649 defer std.debug.unlockStderrWriter();
650 try renderErrorMessage(stderr, self.tty, .err, "{s}\n", .{fail_msg});
649 aro.Diagnostics.render(comp, self.tty);651 aro.Diagnostics.render(comp, self.tty);
650 },652 },
651 }653 }
...@@ -690,7 +692,9 @@ const ErrorHandler = union(enum) {...@@ -690,7 +692,9 @@ const ErrorHandler = union(enum) {
690 try server.serveErrorBundle(error_bundle);692 try server.serveErrorBundle(error_bundle);
691 },693 },
692 .tty => {694 .tty => {
693 try renderErrorMessage(std.fs.File.stderr().deprecatedWriter(), self.tty, msg_type, format, args);695 const stderr = std.debug.lockStderrWriter(&.{});
696 defer std.debug.unlockStderrWriter();
697 try renderErrorMessage(stderr, self.tty, msg_type, format, args);
694 },698 },
695 }699 }
696 }700 }
lib/compiler/resinator/res.zig+2-2
...@@ -442,7 +442,7 @@ pub const NameOrOrdinal = union(enum) {...@@ -442,7 +442,7 @@ pub const NameOrOrdinal = union(enum) {
442 pub fn format(self: NameOrOrdinal, w: *std.io.Writer) !void {442 pub fn format(self: NameOrOrdinal, w: *std.io.Writer) !void {
443 switch (self) {443 switch (self) {
444 .name => |name| {444 .name => |name| {
445 try w.print("{s}", .{std.unicode.fmtUtf16Le(name)});445 try w.print("{f}", .{std.unicode.fmtUtf16Le(name)});
446 },446 },
447 .ordinal => |ordinal| {447 .ordinal => |ordinal| {
448 try w.print("{d}", .{ordinal});448 try w.print("{d}", .{ordinal});
...@@ -453,7 +453,7 @@ pub const NameOrOrdinal = union(enum) {...@@ -453,7 +453,7 @@ pub const NameOrOrdinal = union(enum) {
453 fn formatResourceType(self: NameOrOrdinal, w: *std.io.Writer) std.io.Writer.Error!void {453 fn formatResourceType(self: NameOrOrdinal, w: *std.io.Writer) std.io.Writer.Error!void {
454 switch (self) {454 switch (self) {
455 .name => |name| {455 .name => |name| {
456 try w.print("{s}", .{std.unicode.fmtUtf16Le(name)});456 try w.print("{f}", .{std.unicode.fmtUtf16Le(name)});
457 },457 },
458 .ordinal => |ordinal| {458 .ordinal => |ordinal| {
459 if (std.enums.tagName(RT, @enumFromInt(ordinal))) |predefined_type_name| {459 if (std.enums.tagName(RT, @enumFromInt(ordinal))) |predefined_type_name| {
lib/compiler/resinator/utils.zig+1-1
...@@ -86,7 +86,7 @@ pub const ErrorMessageType = enum { err, warning, note };...@@ -86,7 +86,7 @@ pub const ErrorMessageType = enum { err, warning, note };
8686
87/// Used for generic colored errors/warnings/notes, more context-specific error messages87/// Used for generic colored errors/warnings/notes, more context-specific error messages
88/// are handled elsewhere.88/// are handled elsewhere.
89pub fn renderErrorMessage(writer: anytype, config: std.io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {89pub fn renderErrorMessage(writer: *std.io.Writer, config: std.io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void {
90 switch (msg_type) {90 switch (msg_type) {
91 .err => {91 .err => {
92 try config.setColor(writer, .bold);92 try config.setColor(writer, .bold);
lib/fuzzer.zig+12-9
...@@ -9,7 +9,8 @@ pub const std_options = std.Options{...@@ -9,7 +9,8 @@ pub const std_options = std.Options{
9 .logFn = logOverride,9 .logFn = logOverride,
10};10};
1111
12var log_file: ?std.fs.File = null;12var log_file_buffer: [256]u8 = undefined;
13var log_file_writer: ?std.fs.File.Writer = null;
1314
14fn logOverride(15fn logOverride(
15 comptime level: std.log.Level,16 comptime level: std.log.Level,
...@@ -17,15 +18,17 @@ fn logOverride(...@@ -17,15 +18,17 @@ fn logOverride(
17 comptime format: []const u8,18 comptime format: []const u8,
18 args: anytype,19 args: anytype,
19) void {20) void {
20 const f = if (log_file) |f| f else f: {21 const fw = if (log_file_writer) |*f| f else f: {
21 const f = fuzzer.cache_dir.createFile("tmp/libfuzzer.log", .{}) catch22 const f = fuzzer.cache_dir.createFile("tmp/libfuzzer.log", .{}) catch
22 @panic("failed to open fuzzer log file");23 @panic("failed to open fuzzer log file");
23 log_file = f;24 log_file_writer = f.writer(&log_file_buffer);
24 break :f f;25 break :f &log_file_writer.?;
25 };26 };
26 const prefix1 = comptime level.asText();27 const prefix1 = comptime level.asText();
27 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";28 const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
28 f.writer().print(prefix1 ++ prefix2 ++ format ++ "\n", args) catch @panic("failed to write to fuzzer log");29 fw.interface.print(prefix1 ++ prefix2 ++ format ++ "\n", args) catch
30 @panic("failed to write to fuzzer log");
31 fw.interface.flush() catch @panic("failed to flush fuzzer log");
29}32}
3033
31/// Helps determine run uniqueness in the face of recursion.34/// Helps determine run uniqueness in the face of recursion.
...@@ -226,18 +229,18 @@ const Fuzzer = struct {...@@ -226,18 +229,18 @@ const Fuzzer = struct {
226 .read = true,229 .read = true,
227 }) catch |e| switch (e) {230 }) catch |e| switch (e) {
228 error.PathAlreadyExists => continue,231 error.PathAlreadyExists => continue,
229 else => fatal("unable to create '{}{d}: {s}", .{ f.corpus_directory, i, @errorName(err) }),232 else => fatal("unable to create '{f}{d}: {s}", .{ f.corpus_directory, i, @errorName(err) }),
230 };233 };
231 errdefer input_file.close();234 errdefer input_file.close();
232 // Initialize the mmap for the current input.235 // Initialize the mmap for the current input.
233 f.input = MemoryMappedList.create(input_file, 0, std.heap.page_size_max) catch |e| {236 f.input = MemoryMappedList.create(input_file, 0, std.heap.page_size_max) catch |e| {
234 fatal("unable to init memory map for input at '{}{d}': {s}", .{237 fatal("unable to init memory map for input at '{f}{d}': {s}", .{
235 f.corpus_directory, i, @errorName(e),238 f.corpus_directory, i, @errorName(e),
236 });239 });
237 };240 };
238 break;241 break;
239 },242 },
240 else => fatal("unable to read '{}{d}': {s}", .{ f.corpus_directory, i, @errorName(err) }),243 else => fatal("unable to read '{f}{d}': {s}", .{ f.corpus_directory, i, @errorName(err) }),
241 };244 };
242 errdefer gpa.free(input);245 errdefer gpa.free(input);
243 f.corpus.append(gpa, .{246 f.corpus.append(gpa, .{
...@@ -263,7 +266,7 @@ const Fuzzer = struct {...@@ -263,7 +266,7 @@ const Fuzzer = struct {
263 const sub_path = try std.fmt.allocPrint(gpa, "f/{s}", .{f.unit_test_name});266 const sub_path = try std.fmt.allocPrint(gpa, "f/{s}", .{f.unit_test_name});
264 f.corpus_directory = .{267 f.corpus_directory = .{
265 .handle = f.cache_dir.makeOpenPath(sub_path, .{}) catch |err|268 .handle = f.cache_dir.makeOpenPath(sub_path, .{}) catch |err|
266 fatal("unable to open corpus directory 'f/{s}': {s}", .{ sub_path, @errorName(err) }),269 fatal("unable to open corpus directory 'f/{s}': {t}", .{ sub_path, err }),
267 .path = sub_path,270 .path = sub_path,
268 };271 };
269 initNextInput(f);272 initNextInput(f);
lib/std/elf.zig+5-5
...@@ -511,7 +511,7 @@ pub const Header = struct {...@@ -511,7 +511,7 @@ pub const Header = struct {
511 pub fn read(parse_source: anytype) !Header {511 pub fn read(parse_source: anytype) !Header {
512 var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined;512 var hdr_buf: [@sizeOf(Elf64_Ehdr)]u8 align(@alignOf(Elf64_Ehdr)) = undefined;
513 try parse_source.seekableStream().seekTo(0);513 try parse_source.seekableStream().seekTo(0);
514 try parse_source.reader().readNoEof(&hdr_buf);514 try parse_source.deprecatedReader().readNoEof(&hdr_buf);
515 return Header.parse(&hdr_buf);515 return Header.parse(&hdr_buf);
516 }516 }
517517
...@@ -586,7 +586,7 @@ pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {...@@ -586,7 +586,7 @@ pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {
586 var phdr: Elf64_Phdr = undefined;586 var phdr: Elf64_Phdr = undefined;
587 const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;587 const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;
588 try self.parse_source.seekableStream().seekTo(offset);588 try self.parse_source.seekableStream().seekTo(offset);
589 try self.parse_source.reader().readNoEof(mem.asBytes(&phdr));589 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&phdr));
590590
591 // ELF endianness matches native endianness.591 // ELF endianness matches native endianness.
592 if (self.elf_header.endian == native_endian) return phdr;592 if (self.elf_header.endian == native_endian) return phdr;
...@@ -599,7 +599,7 @@ pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {...@@ -599,7 +599,7 @@ pub fn ProgramHeaderIterator(comptime ParseSource: anytype) type {
599 var phdr: Elf32_Phdr = undefined;599 var phdr: Elf32_Phdr = undefined;
600 const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;600 const offset = self.elf_header.phoff + @sizeOf(@TypeOf(phdr)) * self.index;
601 try self.parse_source.seekableStream().seekTo(offset);601 try self.parse_source.seekableStream().seekTo(offset);
602 try self.parse_source.reader().readNoEof(mem.asBytes(&phdr));602 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&phdr));
603603
604 // ELF endianness does NOT match native endianness.604 // ELF endianness does NOT match native endianness.
605 if (self.elf_header.endian != native_endian) {605 if (self.elf_header.endian != native_endian) {
...@@ -636,7 +636,7 @@ pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {...@@ -636,7 +636,7 @@ pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {
636 var shdr: Elf64_Shdr = undefined;636 var shdr: Elf64_Shdr = undefined;
637 const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;637 const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;
638 try self.parse_source.seekableStream().seekTo(offset);638 try self.parse_source.seekableStream().seekTo(offset);
639 try self.parse_source.reader().readNoEof(mem.asBytes(&shdr));639 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&shdr));
640640
641 // ELF endianness matches native endianness.641 // ELF endianness matches native endianness.
642 if (self.elf_header.endian == native_endian) return shdr;642 if (self.elf_header.endian == native_endian) return shdr;
...@@ -649,7 +649,7 @@ pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {...@@ -649,7 +649,7 @@ pub fn SectionHeaderIterator(comptime ParseSource: anytype) type {
649 var shdr: Elf32_Shdr = undefined;649 var shdr: Elf32_Shdr = undefined;
650 const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;650 const offset = self.elf_header.shoff + @sizeOf(@TypeOf(shdr)) * self.index;
651 try self.parse_source.seekableStream().seekTo(offset);651 try self.parse_source.seekableStream().seekTo(offset);
652 try self.parse_source.reader().readNoEof(mem.asBytes(&shdr));652 try self.parse_source.deprecatedReader().readNoEof(mem.asBytes(&shdr));
653653
654 // ELF endianness does NOT match native endianness.654 // ELF endianness does NOT match native endianness.
655 if (self.elf_header.endian != native_endian) {655 if (self.elf_header.endian != native_endian) {
lib/std/io/Writer.zig+2
...@@ -705,6 +705,8 @@ pub fn sendFileReading(w: *Writer, file_reader: *File.Reader, limit: Limit) File...@@ -705,6 +705,8 @@ pub fn sendFileReading(w: *Writer, file_reader: *File.Reader, limit: Limit) File
705 return n;705 return n;
706}706}
707707
708/// Number of bytes logically written is returned. This excludes bytes from
709/// `buffer` because they have already been logically written.
708pub fn sendFileAll(w: *Writer, file_reader: *File.Reader, limit: Limit) FileAllError!usize {710pub fn sendFileAll(w: *Writer, file_reader: *File.Reader, limit: Limit) FileAllError!usize {
709 var remaining = @intFromEnum(limit);711 var remaining = @intFromEnum(limit);
710 while (remaining > 0) {712 while (remaining > 0) {
lib/std/os/windows.zig+2-3
...@@ -2812,9 +2812,8 @@ pub fn unexpectedError(err: Win32Error) UnexpectedError {...@@ -2812,9 +2812,8 @@ pub fn unexpectedError(err: Win32Error) UnexpectedError {
2812 buf_wstr.len,2812 buf_wstr.len,
2813 null,2813 null,
2814 );2814 );
2815 std.debug.print("error.Unexpected: GetLastError({}): {}\n", .{2815 std.debug.print("error.Unexpected: GetLastError({d}): {f}\n", .{
2816 @intFromEnum(err),2816 err, std.unicode.fmtUtf16Le(buf_wstr[0..len]),
2817 std.unicode.fmtUtf16Le(buf_wstr[0..len]),
2818 });2817 });
2819 std.debug.dumpCurrentStackTrace(@returnAddress());2818 std.debug.dumpCurrentStackTrace(@returnAddress());
2820 }2819 }
lib/std/zig/parser_test.zig+4-4
...@@ -2744,11 +2744,11 @@ test "zig fmt: preserve spacing" {...@@ -2744,11 +2744,11 @@ test "zig fmt: preserve spacing" {
2744 \\const std = @import("std");2744 \\const std = @import("std");
2745 \\2745 \\
2746 \\pub fn main() !void {2746 \\pub fn main() !void {
2747 \\ var stdout_file = std.io.getStdOut;2747 \\ var stdout_file = std.lol.abcd;
2748 \\ var stdout_file = std.io.getStdOut;2748 \\ var stdout_file = std.lol.abcd;
2749 \\2749 \\
2750 \\ var stdout_file = std.io.getStdOut;2750 \\ var stdout_file = std.lol.abcd;
2751 \\ var stdout_file = std.io.getStdOut;2751 \\ var stdout_file = std.lol.abcd;
2752 \\}2752 \\}
2753 \\2753 \\
2754 );2754 );
src/main.zig+6-6
...@@ -6074,7 +6074,7 @@ fn cmdAstCheck(...@@ -6074,7 +6074,7 @@ fn cmdAstCheck(
60746074
6075 const tree = try Ast.parse(arena, source, mode);6075 const tree = try Ast.parse(arena, source, mode);
60766076
6077 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);6077 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
6078 const stdout_bw = &stdout_writer.interface;6078 const stdout_bw = &stdout_writer.interface;
6079 switch (mode) {6079 switch (mode) {
6080 .zig => {6080 .zig => {
...@@ -6289,7 +6289,7 @@ fn detectNativeCpuWithLLVM(...@@ -6289,7 +6289,7 @@ fn detectNativeCpuWithLLVM(
6289}6289}
62906290
6291fn printCpu(cpu: std.Target.Cpu) !void {6291fn printCpu(cpu: std.Target.Cpu) !void {
6292 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);6292 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
6293 const stdout_bw = &stdout_writer.interface;6293 const stdout_bw = &stdout_writer.interface;
62946294
6295 if (cpu.model.llvm_name) |llvm_name| {6295 if (cpu.model.llvm_name) |llvm_name| {
...@@ -6338,7 +6338,7 @@ fn cmdDumpLlvmInts(...@@ -6338,7 +6338,7 @@ fn cmdDumpLlvmInts(
6338 const dl = tm.createTargetDataLayout();6338 const dl = tm.createTargetDataLayout();
6339 const context = llvm.Context.create();6339 const context = llvm.Context.create();
63406340
6341 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);6341 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
6342 const stdout_bw = &stdout_writer.interface;6342 const stdout_bw = &stdout_writer.interface;
6343 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {6343 for ([_]u16{ 1, 8, 16, 32, 64, 128, 256 }) |bits| {
6344 const int_type = context.intType(bits);6344 const int_type = context.intType(bits);
...@@ -6367,7 +6367,7 @@ fn cmdDumpZir(...@@ -6367,7 +6367,7 @@ fn cmdDumpZir(
6367 defer f.close();6367 defer f.close();
63686368
6369 const zir = try Zcu.loadZirCache(arena, f);6369 const zir = try Zcu.loadZirCache(arena, f);
6370 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);6370 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
6371 const stdout_bw = &stdout_writer.interface;6371 const stdout_bw = &stdout_writer.interface;
63726372
6373 {6373 {
...@@ -6453,7 +6453,7 @@ fn cmdChangelist(...@@ -6453,7 +6453,7 @@ fn cmdChangelist(
6453 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;6453 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .empty;
6454 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);6454 try Zcu.mapOldZirToNew(arena, old_zir, new_zir, &inst_map);
64556455
6456 var stdout_writer = fs.File.stdout().writer(&stdio_buffer);6456 var stdout_writer = fs.File.stdout().writerStreaming(&stdio_buffer);
6457 const stdout_bw = &stdout_writer.interface;6457 const stdout_bw = &stdout_writer.interface;
6458 {6458 {
6459 try stdout_bw.print("Instruction mappings:\n", .{});6459 try stdout_bw.print("Instruction mappings:\n", .{});
...@@ -6913,7 +6913,7 @@ fn cmdFetch(...@@ -6913,7 +6913,7 @@ fn cmdFetch(
69136913
6914 const name = switch (save) {6914 const name = switch (save) {
6915 .no => {6915 .no => {
6916 var stdout = fs.File.stdout().writer(&stdio_buffer);6916 var stdout = fs.File.stdout().writerStreaming(&stdio_buffer);
6917 try stdout.interface.print("{s}\n", .{package_hash_slice});6917 try stdout.interface.print("{s}\n", .{package_hash_slice});
6918 try stdout.interface.flush();6918 try stdout.interface.flush();
6919 return cleanExit();6919 return cleanExit();
test/compare_output.zig+3-286
...@@ -17,15 +17,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -17,15 +17,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
17 \\}17 \\}
18 , "Hello, world!" ++ if (@import("builtin").os.tag == .windows) "\r\n" else "\n");18 , "Hello, world!" ++ if (@import("builtin").os.tag == .windows) "\r\n" else "\n");
1919
20 cases.add("hello world without libc",
21 \\const io = @import("std").io;
22 \\
23 \\pub fn main() void {
24 \\ const stdout = io.getStdOut().writer();
25 \\ stdout.print("Hello, world!\n{d:4} {x:3} {c}\n", .{@as(u32, 12), @as(u16, 0x12), @as(u8, 'a')}) catch unreachable;
26 \\}
27 , "Hello, world!\n 12 12 a\n");
28
29 cases.addC("number literals",20 cases.addC("number literals",
30 \\const std = @import("std");21 \\const std = @import("std");
31 \\const builtin = @import("builtin");22 \\const builtin = @import("builtin");
...@@ -158,24 +149,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -158,24 +149,6 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
158 \\149 \\
159 );150 );
160151
161 cases.add("order-independent declarations",
162 \\const io = @import("std").io;
163 \\const z = io.stdin_fileno;
164 \\const x : @TypeOf(y) = 1234;
165 \\const y : u16 = 5678;
166 \\pub fn main() void {
167 \\ var x_local : i32 = print_ok(x);
168 \\ _ = &x_local;
169 \\}
170 \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {
171 \\ _ = val;
172 \\ const stdout = io.getStdOut().writer();
173 \\ stdout.print("OK\n", .{}) catch unreachable;
174 \\ return 0;
175 \\}
176 \\const foo : i32 = 0;
177 , "OK\n");
178
179 cases.addC("expose function pointer to C land",152 cases.addC("expose function pointer to C land",
180 \\const c = @cImport(@cInclude("stdlib.h"));153 \\const c = @cImport(@cInclude("stdlib.h"));
181 \\154 \\
...@@ -236,267 +209,11 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -236,267 +209,11 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
236 \\}209 \\}
237 , "3.25\n3\n3.00\n-0.40\n");210 , "3.25\n3\n3.00\n-0.40\n");
238211
239 cases.add("same named methods in incomplete struct",212 cases.add("valid carriage return example", "const std = @import(\"std\");\r\n" ++ // Testing CRLF line endings are valid
240 \\const io = @import("std").io;
241 \\
242 \\const Foo = struct {
243 \\ field1: Bar,
244 \\
245 \\ fn method(a: *const Foo) bool {
246 \\ _ = a;
247 \\ return true;
248 \\ }
249 \\};
250 \\
251 \\const Bar = struct {
252 \\ field2: i32,
253 \\
254 \\ fn method(b: *const Bar) bool {
255 \\ _ = b;
256 \\ return true;
257 \\ }
258 \\};
259 \\
260 \\pub fn main() void {
261 \\ const bar = Bar {.field2 = 13,};
262 \\ const foo = Foo {.field1 = bar,};
263 \\ const stdout = io.getStdOut().writer();
264 \\ if (!foo.method()) {
265 \\ stdout.print("BAD\n", .{}) catch unreachable;
266 \\ }
267 \\ if (!bar.method()) {
268 \\ stdout.print("BAD\n", .{}) catch unreachable;
269 \\ }
270 \\ stdout.print("OK\n", .{}) catch unreachable;
271 \\}
272 , "OK\n");
273
274 cases.add("defer with only fallthrough",
275 \\const io = @import("std").io;
276 \\pub fn main() void {
277 \\ const stdout = io.getStdOut().writer();
278 \\ stdout.print("before\n", .{}) catch unreachable;
279 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
280 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
281 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
282 \\ stdout.print("after\n", .{}) catch unreachable;
283 \\}
284 , "before\nafter\ndefer3\ndefer2\ndefer1\n");
285
286 cases.add("defer with return",
287 \\const io = @import("std").io;
288 \\const os = @import("std").os;
289 \\pub fn main() void {
290 \\ const stdout = io.getStdOut().writer();
291 \\ stdout.print("before\n", .{}) catch unreachable;
292 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
293 \\ defer stdout.print("defer2\n", .{}) catch unreachable;
294 \\ var gpa: @import("std").heap.GeneralPurposeAllocator(.{}) = .init;
295 \\ defer _ = gpa.deinit();
296 \\ var arena = @import("std").heap.ArenaAllocator.init(gpa.allocator());
297 \\ defer arena.deinit();
298 \\ var args_it = @import("std").process.argsWithAllocator(arena.allocator()) catch unreachable;
299 \\ if (args_it.skip() and !args_it.skip()) return;
300 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
301 \\ stdout.print("after\n", .{}) catch unreachable;
302 \\}
303 , "before\ndefer2\ndefer1\n");
304
305 cases.add("errdefer and it fails",
306 \\const io = @import("std").io;
307 \\pub fn main() void {
308 \\ do_test() catch return;
309 \\}
310 \\fn do_test() !void {
311 \\ const stdout = io.getStdOut().writer();
312 \\ stdout.print("before\n", .{}) catch unreachable;
313 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
314 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
315 \\ try its_gonna_fail();
316 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
317 \\ stdout.print("after\n", .{}) catch unreachable;
318 \\}
319 \\fn its_gonna_fail() !void {
320 \\ return error.IToldYouItWouldFail;
321 \\}
322 , "before\ndeferErr\ndefer1\n");
323
324 cases.add("errdefer and it passes",
325 \\const io = @import("std").io;
326 \\pub fn main() void {
327 \\ do_test() catch return;
328 \\}
329 \\fn do_test() !void {
330 \\ const stdout = io.getStdOut().writer();
331 \\ stdout.print("before\n", .{}) catch unreachable;
332 \\ defer stdout.print("defer1\n", .{}) catch unreachable;
333 \\ errdefer stdout.print("deferErr\n", .{}) catch unreachable;
334 \\ try its_gonna_pass();
335 \\ defer stdout.print("defer3\n", .{}) catch unreachable;
336 \\ stdout.print("after\n", .{}) catch unreachable;
337 \\}
338 \\fn its_gonna_pass() anyerror!void { }
339 , "before\nafter\ndefer3\ndefer1\n");
340
341 cases.addCase(x: {
342 var tc = cases.create("@embedFile",
343 \\const foo_txt = @embedFile("foo.txt");
344 \\const io = @import("std").io;
345 \\
346 \\pub fn main() void {
347 \\ const stdout = io.getStdOut().writer();
348 \\ stdout.print(foo_txt, .{}) catch unreachable;
349 \\}
350 , "1234\nabcd\n");
351
352 tc.addSourceFile("foo.txt", "1234\nabcd\n");
353
354 break :x tc;
355 });
356
357 cases.addCase(x: {
358 var tc = cases.create("parsing args",
359 \\const std = @import("std");
360 \\const io = std.io;
361 \\const os = std.os;
362 \\
363 \\pub fn main() !void {
364 \\ var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
365 \\ defer _ = gpa.deinit();
366 \\ var arena = std.heap.ArenaAllocator.init(gpa.allocator());
367 \\ defer arena.deinit();
368 \\ var args_it = try std.process.argsWithAllocator(arena.allocator());
369 \\ const stdout = io.getStdOut().writer();
370 \\ var index: usize = 0;
371 \\ _ = args_it.skip();
372 \\ while (args_it.next()) |arg| : (index += 1) {
373 \\ try stdout.print("{}: {s}\n", .{index, arg});
374 \\ }
375 \\}
376 ,
377 \\0: first arg
378 \\1: 'a' 'b' \
379 \\2: bare
380 \\3: ba""re
381 \\4: "
382 \\5: last arg
383 \\
384 );
385
386 tc.setCommandLineArgs(&[_][]const u8{
387 "first arg",
388 "'a' 'b' \\",
389 "bare",
390 "ba\"\"re",
391 "\"",
392 "last arg",
393 });
394
395 break :x tc;
396 });
397
398 cases.addCase(x: {
399 var tc = cases.create("parsing args new API",
400 \\const std = @import("std");
401 \\const io = std.io;
402 \\const os = std.os;
403 \\
404 \\pub fn main() !void {
405 \\ var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
406 \\ defer _ = gpa.deinit();
407 \\ var arena = std.heap.ArenaAllocator.init(gpa.allocator());
408 \\ defer arena.deinit();
409 \\ var args_it = try std.process.argsWithAllocator(arena.allocator());
410 \\ const stdout = io.getStdOut().writer();
411 \\ var index: usize = 0;
412 \\ _ = args_it.skip();
413 \\ while (args_it.next()) |arg| : (index += 1) {
414 \\ try stdout.print("{}: {s}\n", .{index, arg});
415 \\ }
416 \\}
417 ,
418 \\0: first arg
419 \\1: 'a' 'b' \
420 \\2: bare
421 \\3: ba""re
422 \\4: "
423 \\5: last arg
424 \\
425 );
426
427 tc.setCommandLineArgs(&[_][]const u8{
428 "first arg",
429 "'a' 'b' \\",
430 "bare",
431 "ba\"\"re",
432 "\"",
433 "last arg",
434 });
435
436 break :x tc;
437 });
438
439 // It is required to override the log function in order to print to stdout instead of stderr
440 cases.add("std.log per scope log level override",
441 \\const std = @import("std");
442 \\
443 \\pub const std_options: std.Options = .{
444 \\ .log_level = .debug,
445 \\
446 \\ .log_scope_levels = &.{
447 \\ .{ .scope = .a, .level = .warn },
448 \\ .{ .scope = .c, .level = .err },
449 \\ },
450 \\ .logFn = log,
451 \\};
452 \\
453 \\const loga = std.log.scoped(.a);
454 \\const logb = std.log.scoped(.b);
455 \\const logc = std.log.scoped(.c);
456 \\
457 \\pub fn main() !void {
458 \\ loga.debug("", .{});
459 \\ logb.debug("", .{});
460 \\ logc.debug("", .{});
461 \\
462 \\ loga.info("", .{});
463 \\ logb.info("", .{});
464 \\ logc.info("", .{});
465 \\
466 \\ loga.warn("", .{});
467 \\ logb.warn("", .{});
468 \\ logc.warn("", .{});
469 \\
470 \\ loga.err("", .{});
471 \\ logb.err("", .{});
472 \\ logc.err("", .{});
473 \\}
474 \\pub fn log(
475 \\ comptime level: std.log.Level,
476 \\ comptime scope: @TypeOf(.EnumLiteral),
477 \\ comptime format: []const u8,
478 \\ args: anytype,
479 \\) void {
480 \\ const level_txt = comptime level.asText();
481 \\ const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "):";
482 \\ const stdout = std.io.getStdOut().writer();
483 \\ nosuspend stdout.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;
484 \\}
485 ,
486 \\debug(b):
487 \\info(b):
488 \\warning(a):
489 \\warning(b):
490 \\error(a):
491 \\error(b):
492 \\error(c):
493 \\
494 );
495
496 cases.add("valid carriage return example", "const io = @import(\"std\").io;\r\n" ++ // Testing CRLF line endings are valid
497 "\r\n" ++213 "\r\n" ++
498 "pub \r fn main() void {\r\n" ++ // Testing isolated carriage return as whitespace is valid214 "pub \r fn main() void {\r\n" ++ // Testing isolated carriage return as whitespace is valid
499 " const stdout = io.getStdOut().writer();\r\n" ++215 " var file_writer = std.fs.File.stdout().writerStreaming(&.{});\r\n" ++
216 " const stdout = &file_writer.interface;\r\n" ++
500 " stdout.print(\\\\A Multiline\r\n" ++ // testing CRLF at end of multiline string line is valid and normalises to \n in the output217 " stdout.print(\\\\A Multiline\r\n" ++ // testing CRLF at end of multiline string line is valid and normalises to \n in the output
501 " \\\\String\r\n" ++218 " \\\\String\r\n" ++
502 " , .{}) catch unreachable;\r\n" ++219 " , .{}) catch unreachable;\r\n" ++
test/incremental/add_decl+7-7
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6#file=main.zig6#file=main.zig
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 try std.io.getStdOut().writeAll(foo);9 try std.fs.File.stdout().writeAll(foo);
10}10}
11const foo = "good morning\n";11const foo = "good morning\n";
12#expect_stdout="good morning\n"12#expect_stdout="good morning\n"
...@@ -15,7 +15,7 @@ const foo = "good morning\n";...@@ -15,7 +15,7 @@ const foo = "good morning\n";
15#file=main.zig15#file=main.zig
16const std = @import("std");16const std = @import("std");
17pub fn main() !void {17pub fn main() !void {
18 try std.io.getStdOut().writeAll(foo);18 try std.fs.File.stdout().writeAll(foo);
19}19}
20const foo = "good morning\n";20const foo = "good morning\n";
21const bar = "good evening\n";21const bar = "good evening\n";
...@@ -25,7 +25,7 @@ const bar = "good evening\n";...@@ -25,7 +25,7 @@ const bar = "good evening\n";
25#file=main.zig25#file=main.zig
26const std = @import("std");26const std = @import("std");
27pub fn main() !void {27pub fn main() !void {
28 try std.io.getStdOut().writeAll(bar);28 try std.fs.File.stdout().writeAll(bar);
29}29}
30const foo = "good morning\n";30const foo = "good morning\n";
31const bar = "good evening\n";31const bar = "good evening\n";
...@@ -35,17 +35,17 @@ const bar = "good evening\n";...@@ -35,17 +35,17 @@ const bar = "good evening\n";
35#file=main.zig35#file=main.zig
36const std = @import("std");36const std = @import("std");
37pub fn main() !void {37pub fn main() !void {
38 try std.io.getStdOut().writeAll(qux);38 try std.fs.File.stdout().writeAll(qux);
39}39}
40const foo = "good morning\n";40const foo = "good morning\n";
41const bar = "good evening\n";41const bar = "good evening\n";
42#expect_error=main.zig:3:37: error: use of undeclared identifier 'qux'42#expect_error=main.zig:3:39: error: use of undeclared identifier 'qux'
4343
44#update=add missing declaration44#update=add missing declaration
45#file=main.zig45#file=main.zig
46const std = @import("std");46const std = @import("std");
47pub fn main() !void {47pub fn main() !void {
48 try std.io.getStdOut().writeAll(qux);48 try std.fs.File.stdout().writeAll(qux);
49}49}
50const foo = "good morning\n";50const foo = "good morning\n";
51const bar = "good evening\n";51const bar = "good evening\n";
...@@ -56,7 +56,7 @@ const qux = "good night\n";...@@ -56,7 +56,7 @@ const qux = "good night\n";
56#file=main.zig56#file=main.zig
57const std = @import("std");57const std = @import("std");
58pub fn main() !void {58pub fn main() !void {
59 try std.io.getStdOut().writeAll(qux);59 try std.fs.File.stdout().writeAll(qux);
60}60}
61const qux = "good night\n";61const qux = "good night\n";
62#expect_stdout="good night\n"62#expect_stdout="good night\n"
test/incremental/add_decl_namespaced+7-7
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6#file=main.zig6#file=main.zig
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 try std.io.getStdOut().writeAll(@This().foo);9 try std.fs.File.stdout().writeAll(@This().foo);
10}10}
11const foo = "good morning\n";11const foo = "good morning\n";
12#expect_stdout="good morning\n"12#expect_stdout="good morning\n"
...@@ -15,7 +15,7 @@ const foo = "good morning\n";...@@ -15,7 +15,7 @@ const foo = "good morning\n";
15#file=main.zig15#file=main.zig
16const std = @import("std");16const std = @import("std");
17pub fn main() !void {17pub fn main() !void {
18 try std.io.getStdOut().writeAll(@This().foo);18 try std.fs.File.stdout().writeAll(@This().foo);
19}19}
20const foo = "good morning\n";20const foo = "good morning\n";
21const bar = "good evening\n";21const bar = "good evening\n";
...@@ -25,7 +25,7 @@ const bar = "good evening\n";...@@ -25,7 +25,7 @@ const bar = "good evening\n";
25#file=main.zig25#file=main.zig
26const std = @import("std");26const std = @import("std");
27pub fn main() !void {27pub fn main() !void {
28 try std.io.getStdOut().writeAll(@This().bar);28 try std.fs.File.stdout().writeAll(@This().bar);
29}29}
30const foo = "good morning\n";30const foo = "good morning\n";
31const bar = "good evening\n";31const bar = "good evening\n";
...@@ -35,18 +35,18 @@ const bar = "good evening\n";...@@ -35,18 +35,18 @@ const bar = "good evening\n";
35#file=main.zig35#file=main.zig
36const std = @import("std");36const std = @import("std");
37pub fn main() !void {37pub fn main() !void {
38 try std.io.getStdOut().writeAll(@This().qux);38 try std.fs.File.stdout().writeAll(@This().qux);
39}39}
40const foo = "good morning\n";40const foo = "good morning\n";
41const bar = "good evening\n";41const bar = "good evening\n";
42#expect_error=main.zig:3:44: error: root source file struct 'main' has no member named 'qux'42#expect_error=main.zig:3:46: error: root source file struct 'main' has no member named 'qux'
43#expect_error=main.zig:1:1: note: struct declared here43#expect_error=main.zig:1:1: note: struct declared here
4444
45#update=add missing declaration45#update=add missing declaration
46#file=main.zig46#file=main.zig
47const std = @import("std");47const std = @import("std");
48pub fn main() !void {48pub fn main() !void {
49 try std.io.getStdOut().writeAll(@This().qux);49 try std.fs.File.stdout().writeAll(@This().qux);
50}50}
51const foo = "good morning\n";51const foo = "good morning\n";
52const bar = "good evening\n";52const bar = "good evening\n";
...@@ -57,7 +57,7 @@ const qux = "good night\n";...@@ -57,7 +57,7 @@ const qux = "good night\n";
57#file=main.zig57#file=main.zig
58const std = @import("std");58const std = @import("std");
59pub fn main() !void {59pub fn main() !void {
60 try std.io.getStdOut().writeAll(@This().qux);60 try std.fs.File.stdout().writeAll(@This().qux);
61}61}
62const qux = "good night\n";62const qux = "good night\n";
63#expect_stdout="good night\n"63#expect_stdout="good night\n"
test/incremental/bad_import+2-2
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7#file=main.zig7#file=main.zig
8pub fn main() !void {8pub fn main() !void {
9 _ = @import("foo.zig");9 _ = @import("foo.zig");
10 try std.io.getStdOut().writeAll("success\n");10 try std.fs.File.stdout().writeAll("success\n");
11}11}
12const std = @import("std");12const std = @import("std");
13#file=foo.zig13#file=foo.zig
...@@ -29,7 +29,7 @@ comptime {...@@ -29,7 +29,7 @@ comptime {
29#file=main.zig29#file=main.zig
30pub fn main() !void {30pub fn main() !void {
31 //_ = @import("foo.zig");31 //_ = @import("foo.zig");
32 try std.io.getStdOut().writeAll("success\n");32 try std.fs.File.stdout().writeAll("success\n");
33}33}
34const std = @import("std");34const std = @import("std");
35#expect_stdout="success\n"35#expect_stdout="success\n"
test/incremental/change_embed_file+3-3
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const std = @import("std");7const std = @import("std");
8const string = @embedFile("string.txt");8const string = @embedFile("string.txt");
9pub fn main() !void {9pub fn main() !void {
10 try std.io.getStdOut().writeAll(string);10 try std.fs.File.stdout().writeAll(string);
11}11}
12#file=string.txt12#file=string.txt
13Hello, World!13Hello, World!
...@@ -27,7 +27,7 @@ Hello again, World!...@@ -27,7 +27,7 @@ Hello again, World!
27const std = @import("std");27const std = @import("std");
28const string = @embedFile("string.txt");28const string = @embedFile("string.txt");
29pub fn main() !void {29pub fn main() !void {
30 try std.io.getStdOut().writeAll("a hardcoded string\n");30 try std.fs.File.stdout().writeAll("a hardcoded string\n");
31}31}
32#expect_stdout="a hardcoded string\n"32#expect_stdout="a hardcoded string\n"
3333
...@@ -36,7 +36,7 @@ pub fn main() !void {...@@ -36,7 +36,7 @@ pub fn main() !void {
36const std = @import("std");36const std = @import("std");
37const string = @embedFile("string.txt");37const string = @embedFile("string.txt");
38pub fn main() !void {38pub fn main() !void {
39 try std.io.getStdOut().writeAll(string);39 try std.fs.File.stdout().writeAll(string);
40}40}
41#expect_error=main.zig:2:27: error: unable to open 'string.txt': FileNotFound41#expect_error=main.zig:2:27: error: unable to open 'string.txt': FileNotFound
4242
test/incremental/change_enum_tag_type+6-3
...@@ -14,7 +14,8 @@ const Foo = enum(Tag) {...@@ -14,7 +14,8 @@ const Foo = enum(Tag) {
14pub fn main() !void {14pub fn main() !void {
15 var val: Foo = undefined;15 var val: Foo = undefined;
16 val = .a;16 val = .a;
17 try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});17 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
18 try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
18}19}
19const std = @import("std");20const std = @import("std");
20#expect_stdout="a\n"21#expect_stdout="a\n"
...@@ -31,7 +32,8 @@ const Foo = enum(Tag) {...@@ -31,7 +32,8 @@ const Foo = enum(Tag) {
31pub fn main() !void {32pub fn main() !void {
32 var val: Foo = undefined;33 var val: Foo = undefined;
33 val = .a;34 val = .a;
34 try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});35 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
36 try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
35}37}
36comptime {38comptime {
37 // These can't be true at the same time; analysis should stop as soon as it sees `Foo`39 // These can't be true at the same time; analysis should stop as soon as it sees `Foo`
...@@ -53,7 +55,8 @@ const Foo = enum(Tag) {...@@ -53,7 +55,8 @@ const Foo = enum(Tag) {
53pub fn main() !void {55pub fn main() !void {
54 var val: Foo = undefined;56 var val: Foo = undefined;
55 val = .a;57 val = .a;
56 try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});58 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
59 try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
57}60}
58const std = @import("std");61const std = @import("std");
59#expect_stdout="a\n"62#expect_stdout="a\n"
test/incremental/change_exports+12-6
...@@ -16,7 +16,8 @@ pub fn main() !void {...@@ -16,7 +16,8 @@ pub fn main() !void {
16 extern const bar: u32;16 extern const bar: u32;
17 };17 };
18 S.foo();18 S.foo();
19 try std.io.getStdOut().writer().print("{}\n", .{S.bar});19 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
20 try stdout_writer.interface.print("{}\n", .{S.bar});
20}21}
21const std = @import("std");22const std = @import("std");
22#expect_stdout="123\n"23#expect_stdout="123\n"
...@@ -37,7 +38,8 @@ pub fn main() !void {...@@ -37,7 +38,8 @@ pub fn main() !void {
37 extern const other: u32;38 extern const other: u32;
38 };39 };
39 S.foo();40 S.foo();
40 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });41 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
42 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
41}43}
42const std = @import("std");44const std = @import("std");
43#expect_error=main.zig:6:5: error: exported symbol collision: foo45#expect_error=main.zig:6:5: error: exported symbol collision: foo
...@@ -59,7 +61,8 @@ pub fn main() !void {...@@ -59,7 +61,8 @@ pub fn main() !void {
59 extern const other: u32;61 extern const other: u32;
60 };62 };
61 S.foo();63 S.foo();
62 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });64 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
65 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
63}66}
64const std = @import("std");67const std = @import("std");
65#expect_stdout="123 456\n"68#expect_stdout="123 456\n"
...@@ -83,7 +86,8 @@ pub fn main() !void {...@@ -83,7 +86,8 @@ pub fn main() !void {
83 extern const other: u32;86 extern const other: u32;
84 };87 };
85 S.foo();88 S.foo();
86 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });89 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
90 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
87}91}
88const std = @import("std");92const std = @import("std");
89#expect_stdout="123 456\n"93#expect_stdout="123 456\n"
...@@ -128,7 +132,8 @@ pub fn main() !void {...@@ -128,7 +132,8 @@ pub fn main() !void {
128 extern const other: u32;132 extern const other: u32;
129 };133 };
130 S.foo();134 S.foo();
131 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });135 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
136 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
132}137}
133const std = @import("std");138const std = @import("std");
134#expect_stdout="123 456\n"139#expect_stdout="123 456\n"
...@@ -152,7 +157,8 @@ pub fn main() !void {...@@ -152,7 +157,8 @@ pub fn main() !void {
152 extern const other: u32;157 extern const other: u32;
153 };158 };
154 S.foo();159 S.foo();
155 try std.io.getStdOut().writer().print("{} {}\n", .{ S.bar, S.other });160 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
161 try stdout_writer.interface.print("{} {}\n", .{ S.bar, S.other });
156}162}
157const std = @import("std");163const std = @import("std");
158#expect_error=main.zig:5:5: error: exported symbol collision: bar164#expect_error=main.zig:5:5: error: exported symbol collision: bar
test/incremental/change_fn_type+6-3
...@@ -7,7 +7,8 @@ pub fn main() !void {...@@ -7,7 +7,8 @@ pub fn main() !void {
7 try foo(123);7 try foo(123);
8}8}
9fn foo(x: u8) !void {9fn foo(x: u8) !void {
10 return std.io.getStdOut().writer().print("{d}\n", .{x});10 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
11 return stdout_writer.interface.print("{d}\n", .{x});
11}12}
12const std = @import("std");13const std = @import("std");
13#expect_stdout="123\n"14#expect_stdout="123\n"
...@@ -18,7 +19,8 @@ pub fn main() !void {...@@ -18,7 +19,8 @@ pub fn main() !void {
18 try foo(123);19 try foo(123);
19}20}
20fn foo(x: i64) !void {21fn foo(x: i64) !void {
21 return std.io.getStdOut().writer().print("{d}\n", .{x});22 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
23 return stdout_writer.interface.print("{d}\n", .{x});
22}24}
23const std = @import("std");25const std = @import("std");
24#expect_stdout="123\n"26#expect_stdout="123\n"
...@@ -29,7 +31,8 @@ pub fn main() !void {...@@ -29,7 +31,8 @@ pub fn main() !void {
29 try foo(-42);31 try foo(-42);
30}32}
31fn foo(x: i64) !void {33fn foo(x: i64) !void {
32 return std.io.getStdOut().writer().print("{d}\n", .{x});34 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
35 return stdout_writer.interface.print("{d}\n", .{x});
33}36}
34const std = @import("std");37const std = @import("std");
35#expect_stdout="-42\n"38#expect_stdout="-42\n"
test/incremental/change_generic_line_number+2-2
...@@ -6,7 +6,7 @@ const std = @import("std");...@@ -6,7 +6,7 @@ const std = @import("std");
6fn Printer(message: []const u8) type {6fn Printer(message: []const u8) type {
7 return struct {7 return struct {
8 fn print() !void {8 fn print() !void {
9 try std.io.getStdOut().writeAll(message);9 try std.fs.File.stdout().writeAll(message);
10 }10 }
11 };11 };
12}12}
...@@ -22,7 +22,7 @@ const std = @import("std");...@@ -22,7 +22,7 @@ const std = @import("std");
22fn Printer(message: []const u8) type {22fn Printer(message: []const u8) type {
23 return struct {23 return struct {
24 fn print() !void {24 fn print() !void {
25 try std.io.getStdOut().writeAll(message);25 try std.fs.File.stdout().writeAll(message);
26 }26 }
27 };27 };
28}28}
test/incremental/change_line_number+2-2
...@@ -4,7 +4,7 @@...@@ -4,7 +4,7 @@
4#file=main.zig4#file=main.zig
5const std = @import("std");5const std = @import("std");
6pub fn main() !void {6pub fn main() !void {
7 try std.io.getStdOut().writeAll("foo\n");7 try std.fs.File.stdout().writeAll("foo\n");
8}8}
9#expect_stdout="foo\n"9#expect_stdout="foo\n"
10#update=change line number10#update=change line number
...@@ -12,6 +12,6 @@ pub fn main() !void {...@@ -12,6 +12,6 @@ pub fn main() !void {
12const std = @import("std");12const std = @import("std");
1313
14pub fn main() !void {14pub fn main() !void {
15 try std.io.getStdOut().writeAll("foo\n");15 try std.fs.File.stdout().writeAll("foo\n");
16}16}
17#expect_stdout="foo\n"17#expect_stdout="foo\n"
test/incremental/change_panic_handler+6-3
...@@ -11,7 +11,8 @@ pub fn main() !u8 {...@@ -11,7 +11,8 @@ pub fn main() !u8 {
11}11}
12pub const panic = std.debug.FullPanic(myPanic);12pub const panic = std.debug.FullPanic(myPanic);
13fn myPanic(msg: []const u8, _: ?usize) noreturn {13fn myPanic(msg: []const u8, _: ?usize) noreturn {
14 std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {};14 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
15 stdout_writer.interface.print("panic message: {s}\n", .{msg}) catch {};
15 std.process.exit(0);16 std.process.exit(0);
16}17}
17const std = @import("std");18const std = @import("std");
...@@ -27,7 +28,8 @@ pub fn main() !u8 {...@@ -27,7 +28,8 @@ pub fn main() !u8 {
27}28}
28pub const panic = std.debug.FullPanic(myPanic);29pub const panic = std.debug.FullPanic(myPanic);
29fn myPanic(msg: []const u8, _: ?usize) noreturn {30fn myPanic(msg: []const u8, _: ?usize) noreturn {
30 std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {};31 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
32 stdout_writer.interface.print("new panic message: {s}\n", .{msg}) catch {};
31 std.process.exit(0);33 std.process.exit(0);
32}34}
33const std = @import("std");35const std = @import("std");
...@@ -43,7 +45,8 @@ pub fn main() !u8 {...@@ -43,7 +45,8 @@ pub fn main() !u8 {
43}45}
44pub const panic = std.debug.FullPanic(myPanicNew);46pub const panic = std.debug.FullPanic(myPanicNew);
45fn myPanicNew(msg: []const u8, _: ?usize) noreturn {47fn myPanicNew(msg: []const u8, _: ?usize) noreturn {
46 std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {};48 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
49 stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {};
47 std.process.exit(0);50 std.process.exit(0);
48}51}
49const std = @import("std");52const std = @import("std");
test/incremental/change_panic_handler_explicit+6-3
...@@ -41,7 +41,8 @@ pub const panic = struct {...@@ -41,7 +41,8 @@ pub const panic = struct {
41 pub const noreturnReturned = no_panic.noreturnReturned;41 pub const noreturnReturned = no_panic.noreturnReturned;
42};42};
43fn myPanic(msg: []const u8, _: ?usize) noreturn {43fn myPanic(msg: []const u8, _: ?usize) noreturn {
44 std.io.getStdOut().writer().print("panic message: {s}\n", .{msg}) catch {};44 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
45 stdout_writer.interface.print("panic message: {s}\n", .{msg}) catch {};
45 std.process.exit(0);46 std.process.exit(0);
46}47}
47const std = @import("std");48const std = @import("std");
...@@ -87,7 +88,8 @@ pub const panic = struct {...@@ -87,7 +88,8 @@ pub const panic = struct {
87 pub const noreturnReturned = no_panic.noreturnReturned;88 pub const noreturnReturned = no_panic.noreturnReturned;
88};89};
89fn myPanic(msg: []const u8, _: ?usize) noreturn {90fn myPanic(msg: []const u8, _: ?usize) noreturn {
90 std.io.getStdOut().writer().print("new panic message: {s}\n", .{msg}) catch {};91 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
92 stdout_writer.interface.print("new panic message: {s}\n", .{msg}) catch {};
91 std.process.exit(0);93 std.process.exit(0);
92}94}
93const std = @import("std");95const std = @import("std");
...@@ -133,7 +135,8 @@ pub const panic = struct {...@@ -133,7 +135,8 @@ pub const panic = struct {
133 pub const noreturnReturned = no_panic.noreturnReturned;135 pub const noreturnReturned = no_panic.noreturnReturned;
134};136};
135fn myPanicNew(msg: []const u8, _: ?usize) noreturn {137fn myPanicNew(msg: []const u8, _: ?usize) noreturn {
136 std.io.getStdOut().writer().print("third panic message: {s}\n", .{msg}) catch {};138 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
139 stdout_writer.interface.print("third panic message: {s}\n", .{msg}) catch {};
137 std.process.exit(0);140 std.process.exit(0);
138}141}
139const std = @import("std");142const std = @import("std");
test/incremental/change_shift_op+4-2
...@@ -8,7 +8,8 @@ pub fn main() !void {...@@ -8,7 +8,8 @@ pub fn main() !void {
8 try foo(0x1300);8 try foo(0x1300);
9}9}
10fn foo(x: u16) !void {10fn foo(x: u16) !void {
11 try std.io.getStdOut().writer().print("0x{x}\n", .{x << 4});11 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
12 try stdout_writer.interface.print("0x{x}\n", .{x << 4});
12}13}
13const std = @import("std");14const std = @import("std");
14#expect_stdout="0x3000\n"15#expect_stdout="0x3000\n"
...@@ -18,7 +19,8 @@ pub fn main() !void {...@@ -18,7 +19,8 @@ pub fn main() !void {
18 try foo(0x1300);19 try foo(0x1300);
19}20}
20fn foo(x: u16) !void {21fn foo(x: u16) !void {
21 try std.io.getStdOut().writer().print("0x{x}\n", .{x >> 4});22 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
23 try stdout_writer.interface.print("0x{x}\n", .{x >> 4});
22}24}
23const std = @import("std");25const std = @import("std");
24#expect_stdout="0x130\n"26#expect_stdout="0x130\n"
test/incremental/change_struct_same_fields+6-3
...@@ -10,7 +10,8 @@ pub fn main() !void {...@@ -10,7 +10,8 @@ pub fn main() !void {
10 try foo(&val);10 try foo(&val);
11}11}
12fn foo(val: *const S) !void {12fn foo(val: *const S) !void {
13 try std.io.getStdOut().writer().print(13 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
14 try stdout_writer.interface.print(
14 "{d} {d}\n",15 "{d} {d}\n",
15 .{ val.x, val.y },16 .{ val.x, val.y },
16 );17 );
...@@ -26,7 +27,8 @@ pub fn main() !void {...@@ -26,7 +27,8 @@ pub fn main() !void {
26 try foo(&val);27 try foo(&val);
27}28}
28fn foo(val: *const S) !void {29fn foo(val: *const S) !void {
29 try std.io.getStdOut().writer().print(30 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
31 try stdout_writer.interface.print(
30 "{d} {d}\n",32 "{d} {d}\n",
31 .{ val.x, val.y },33 .{ val.x, val.y },
32 );34 );
...@@ -42,7 +44,8 @@ pub fn main() !void {...@@ -42,7 +44,8 @@ pub fn main() !void {
42 try foo(&val);44 try foo(&val);
43}45}
44fn foo(val: *const S) !void {46fn foo(val: *const S) !void {
45 try std.io.getStdOut().writer().print(47 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
48 try stdout_writer.interface.print(
46 "{d} {d}\n",49 "{d} {d}\n",
47 .{ val.x, val.y },50 .{ val.x, val.y },
48 );51 );
test/incremental/change_zon_file+3-3
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const std = @import("std");7const std = @import("std");
8const message: []const u8 = @import("message.zon");8const message: []const u8 = @import("message.zon");
9pub fn main() !void {9pub fn main() !void {
10 try std.io.getStdOut().writeAll(message);10 try std.fs.File.stdout().writeAll(message);
11}11}
12#file=message.zon12#file=message.zon
13"Hello, World!\n"13"Hello, World!\n"
...@@ -28,7 +28,7 @@ pub fn main() !void {...@@ -28,7 +28,7 @@ pub fn main() !void {
28const std = @import("std");28const std = @import("std");
29const message: []const u8 = @import("message.zon");29const message: []const u8 = @import("message.zon");
30pub fn main() !void {30pub fn main() !void {
31 try std.io.getStdOut().writeAll("a hardcoded string\n");31 try std.fs.File.stdout().writeAll("a hardcoded string\n");
32}32}
33#expect_error=message.zon:1:1: error: unable to load 'message.zon': FileNotFound33#expect_error=message.zon:1:1: error: unable to load 'message.zon': FileNotFound
34#expect_error=main.zig:2:37: note: file imported here34#expect_error=main.zig:2:37: note: file imported here
...@@ -43,6 +43,6 @@ pub fn main() !void {...@@ -43,6 +43,6 @@ pub fn main() !void {
43const std = @import("std");43const std = @import("std");
44const message: []const u8 = @import("message.zon");44const message: []const u8 = @import("message.zon");
45pub fn main() !void {45pub fn main() !void {
46 try std.io.getStdOut().writeAll(message);46 try std.fs.File.stdout().writeAll(message);
47}47}
48#expect_stdout="We're back, World!\n"48#expect_stdout="We're back, World!\n"
test/incremental/change_zon_file_no_result_type+1-1
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6#file=main.zig6#file=main.zig
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 try std.io.getStdOut().writeAll(@import("foo.zon").message);9 try std.fs.File.stdout().writeAll(@import("foo.zon").message);
10}10}
11#file=foo.zon11#file=foo.zon
12.{12.{
test/incremental/compile_log+3-3
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7#file=main.zig7#file=main.zig
8const std = @import("std");8const std = @import("std");
9pub fn main() !void {9pub fn main() !void {
10 try std.io.getStdOut().writeAll("Hello, World!\n");10 try std.fs.File.stdout().writeAll("Hello, World!\n");
11}11}
12#expect_stdout="Hello, World!\n"12#expect_stdout="Hello, World!\n"
1313
...@@ -15,7 +15,7 @@ pub fn main() !void {...@@ -15,7 +15,7 @@ pub fn main() !void {
15#file=main.zig15#file=main.zig
16const std = @import("std");16const std = @import("std");
17pub fn main() !void {17pub fn main() !void {
18 try std.io.getStdOut().writeAll("Hello, World!\n");18 try std.fs.File.stdout().writeAll("Hello, World!\n");
19 @compileLog("this is a log");19 @compileLog("this is a log");
20}20}
21#expect_error=main.zig:4:5: error: found compile log statement21#expect_error=main.zig:4:5: error: found compile log statement
...@@ -25,6 +25,6 @@ pub fn main() !void {...@@ -25,6 +25,6 @@ pub fn main() !void {
25#file=main.zig25#file=main.zig
26const std = @import("std");26const std = @import("std");
27pub fn main() !void {27pub fn main() !void {
28 try std.io.getStdOut().writeAll("Hello, World!\n");28 try std.fs.File.stdout().writeAll("Hello, World!\n");
29}29}
30#expect_stdout="Hello, World!\n"30#expect_stdout="Hello, World!\n"
test/incremental/fix_astgen_failure+5-5
...@@ -9,28 +9,28 @@ pub fn main() !void {...@@ -9,28 +9,28 @@ pub fn main() !void {
9}9}
10#file=foo.zig10#file=foo.zig
11pub fn hello() !void {11pub fn hello() !void {
12 try std.io.getStdOut().writeAll("Hello, World!\n");12 try std.fs.File.stdout().writeAll("Hello, World!\n");
13}13}
14#expect_error=foo.zig:2:9: error: use of undeclared identifier 'std'14#expect_error=foo.zig:2:9: error: use of undeclared identifier 'std'
15#update=fix the error15#update=fix the error
16#file=foo.zig16#file=foo.zig
17const std = @import("std");17const std = @import("std");
18pub fn hello() !void {18pub fn hello() !void {
19 try std.io.getStdOut().writeAll("Hello, World!\n");19 try std.fs.File.stdout().writeAll("Hello, World!\n");
20}20}
21#expect_stdout="Hello, World!\n"21#expect_stdout="Hello, World!\n"
22#update=add new error22#update=add new error
23#file=foo.zig23#file=foo.zig
24const std = @import("std");24const std = @import("std");
25pub fn hello() !void {25pub fn hello() !void {
26 try std.io.getStdOut().writeAll(hello_str);26 try std.fs.File.stdout().writeAll(hello_str);
27}27}
28#expect_error=foo.zig:3:37: error: use of undeclared identifier 'hello_str'28#expect_error=foo.zig:3:39: error: use of undeclared identifier 'hello_str'
29#update=fix the new error29#update=fix the new error
30#file=foo.zig30#file=foo.zig
31const std = @import("std");31const std = @import("std");
32const hello_str = "Hello, World! Again!\n";32const hello_str = "Hello, World! Again!\n";
33pub fn hello() !void {33pub fn hello() !void {
34 try std.io.getStdOut().writeAll(hello_str);34 try std.fs.File.stdout().writeAll(hello_str);
35}35}
36#expect_stdout="Hello, World! Again!\n"36#expect_stdout="Hello, World! Again!\n"
test/incremental/function_becomes_inline+3-3
...@@ -7,7 +7,7 @@ pub fn main() !void {...@@ -7,7 +7,7 @@ pub fn main() !void {
7 try foo();7 try foo();
8}8}
9fn foo() !void {9fn foo() !void {
10 try std.io.getStdOut().writer().writeAll("Hello, World!\n");10 try std.fs.File.stdout().writeAll("Hello, World!\n");
11}11}
12const std = @import("std");12const std = @import("std");
13#expect_stdout="Hello, World!\n"13#expect_stdout="Hello, World!\n"
...@@ -18,7 +18,7 @@ pub fn main() !void {...@@ -18,7 +18,7 @@ pub fn main() !void {
18 try foo();18 try foo();
19}19}
20inline fn foo() !void {20inline fn foo() !void {
21 try std.io.getStdOut().writer().writeAll("Hello, World!\n");21 try std.fs.File.stdout().writeAll("Hello, World!\n");
22}22}
23const std = @import("std");23const std = @import("std");
24#expect_stdout="Hello, World!\n"24#expect_stdout="Hello, World!\n"
...@@ -29,7 +29,7 @@ pub fn main() !void {...@@ -29,7 +29,7 @@ pub fn main() !void {
29 try foo();29 try foo();
30}30}
31inline fn foo() !void {31inline fn foo() !void {
32 try std.io.getStdOut().writer().writeAll("Hello, `inline` World!\n");32 try std.fs.File.stdout().writeAll("Hello, `inline` World!\n");
33}33}
34const std = @import("std");34const std = @import("std");
35#expect_stdout="Hello, `inline` World!\n"35#expect_stdout="Hello, `inline` World!\n"
test/incremental/hello+2-2
...@@ -6,13 +6,13 @@...@@ -6,13 +6,13 @@
6#file=main.zig6#file=main.zig
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 try std.io.getStdOut().writeAll("good morning\n");9 try std.fs.File.stdout().writeAll("good morning\n");
10}10}
11#expect_stdout="good morning\n"11#expect_stdout="good morning\n"
12#update=change the string12#update=change the string
13#file=main.zig13#file=main.zig
14const std = @import("std");14const std = @import("std");
15pub fn main() !void {15pub fn main() !void {
16 try std.io.getStdOut().writeAll("おはようございます\n");16 try std.fs.File.stdout().writeAll("おはようございます\n");
17}17}
18#expect_stdout="おはようございます\n"18#expect_stdout="おはようございます\n"
test/incremental/make_decl_pub+2-2
...@@ -11,7 +11,7 @@ pub fn main() !void {...@@ -11,7 +11,7 @@ pub fn main() !void {
11#file=foo.zig11#file=foo.zig
12const std = @import("std");12const std = @import("std");
13fn hello() !void {13fn hello() !void {
14 try std.io.getStdOut().writeAll("Hello, World!\n");14 try std.fs.File.stdout().writeAll("Hello, World!\n");
15}15}
16#expect_error=main.zig:3:12: error: 'hello' is not marked 'pub'16#expect_error=main.zig:3:12: error: 'hello' is not marked 'pub'
17#expect_error=foo.zig:2:1: note: declared here17#expect_error=foo.zig:2:1: note: declared here
...@@ -20,6 +20,6 @@ fn hello() !void {...@@ -20,6 +20,6 @@ fn hello() !void {
20#file=foo.zig20#file=foo.zig
21const std = @import("std");21const std = @import("std");
22pub fn hello() !void {22pub fn hello() !void {
23 try std.io.getStdOut().writeAll("Hello, World!\n");23 try std.fs.File.stdout().writeAll("Hello, World!\n");
24}24}
25#expect_stdout="Hello, World!\n"25#expect_stdout="Hello, World!\n"
test/incremental/modify_inline_fn+2-2
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 const str = getStr();9 const str = getStr();
10 try std.io.getStdOut().writeAll(str);10 try std.fs.File.stdout().writeAll(str);
11}11}
12inline fn getStr() []const u8 {12inline fn getStr() []const u8 {
13 return "foo\n";13 return "foo\n";
...@@ -18,7 +18,7 @@ inline fn getStr() []const u8 {...@@ -18,7 +18,7 @@ inline fn getStr() []const u8 {
18const std = @import("std");18const std = @import("std");
19pub fn main() !void {19pub fn main() !void {
20 const str = getStr();20 const str = getStr();
21 try std.io.getStdOut().writeAll(str);21 try std.fs.File.stdout().writeAll(str);
22}22}
23inline fn getStr() []const u8 {23inline fn getStr() []const u8 {
24 return "bar\n";24 return "bar\n";
test/incremental/move_src+6-4
...@@ -6,7 +6,8 @@...@@ -6,7 +6,8 @@
6#file=main.zig6#file=main.zig
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 try std.io.getStdOut().writer().print("{d} {d}\n", .{ foo(), bar() });9 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
10 try stdout_writer.interface.print("{d} {d}\n", .{ foo(), bar() });
10}11}
11fn foo() u32 {12fn foo() u32 {
12 return @src().line;13 return @src().line;
...@@ -14,13 +15,14 @@ fn foo() u32 {...@@ -14,13 +15,14 @@ fn foo() u32 {
14fn bar() u32 {15fn bar() u32 {
15 return 123;16 return 123;
16}17}
17#expect_stdout="6 123\n"18#expect_stdout="7 123\n"
1819
19#update=add newline20#update=add newline
20#file=main.zig21#file=main.zig
21const std = @import("std");22const std = @import("std");
22pub fn main() !void {23pub fn main() !void {
23 try std.io.getStdOut().writer().print("{d} {d}\n", .{ foo(), bar() });24 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
25 try stdout_writer.interface.print("{d} {d}\n", .{ foo(), bar() });
24}26}
2527
26fn foo() u32 {28fn foo() u32 {
...@@ -29,4 +31,4 @@ fn foo() u32 {...@@ -29,4 +31,4 @@ fn foo() u32 {
29fn bar() u32 {31fn bar() u32 {
30 return 123;32 return 123;
31}33}
32#expect_stdout="7 123\n"34#expect_stdout="8 123\n"
test/incremental/no_change_preserves_tag_names+2-2
...@@ -7,7 +7,7 @@...@@ -7,7 +7,7 @@
7const std = @import("std");7const std = @import("std");
8var some_enum: enum { first, second } = .first;8var some_enum: enum { first, second } = .first;
9pub fn main() !void {9pub fn main() !void {
10 try std.io.getStdOut().writeAll(@tagName(some_enum));10 try std.fs.File.stdout().writeAll(@tagName(some_enum));
11}11}
12#expect_stdout="first"12#expect_stdout="first"
13#update=no change13#update=no change
...@@ -15,6 +15,6 @@ pub fn main() !void {...@@ -15,6 +15,6 @@ pub fn main() !void {
15const std = @import("std");15const std = @import("std");
16var some_enum: enum { first, second } = .first;16var some_enum: enum { first, second } = .first;
17pub fn main() !void {17pub fn main() !void {
18 try std.io.getStdOut().writeAll(@tagName(some_enum));18 try std.fs.File.stdout().writeAll(@tagName(some_enum));
19}19}
20#expect_stdout="first"20#expect_stdout="first"
test/incremental/recursive_function_becomes_non_recursive+2-2
...@@ -8,7 +8,7 @@ pub fn main() !void {...@@ -8,7 +8,7 @@ pub fn main() !void {
8 try foo(false);8 try foo(false);
9}9}
10fn foo(recurse: bool) !void {10fn foo(recurse: bool) !void {
11 const stdout = std.io.getStdOut().writer();11 const stdout = std.fs.File.stdout();
12 if (recurse) return foo(true);12 if (recurse) return foo(true);
13 try stdout.writeAll("non-recursive path\n");13 try stdout.writeAll("non-recursive path\n");
14}14}
...@@ -21,7 +21,7 @@ pub fn main() !void {...@@ -21,7 +21,7 @@ pub fn main() !void {
21 try foo(true);21 try foo(true);
22}22}
23fn foo(recurse: bool) !void {23fn foo(recurse: bool) !void {
24 const stdout = std.io.getStdOut().writer();24 const stdout = std.fs.File.stdout();
25 if (recurse) return stdout.writeAll("x==1\n");25 if (recurse) return stdout.writeAll("x==1\n");
26 try stdout.writeAll("non-recursive path\n");26 try stdout.writeAll("non-recursive path\n");
27}27}
test/incremental/remove_enum_field+5-3
...@@ -9,7 +9,8 @@ const MyEnum = enum(u8) {...@@ -9,7 +9,8 @@ const MyEnum = enum(u8) {
9 bar = 2,9 bar = 2,
10};10};
11pub fn main() !void {11pub fn main() !void {
12 try std.io.getStdOut().writer().print("{}\n", .{@intFromEnum(MyEnum.foo)});12 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
13 try stdout_writer.interface.print("{}\n", .{@intFromEnum(MyEnum.foo)});
13}14}
14const std = @import("std");15const std = @import("std");
15#expect_stdout="1\n"16#expect_stdout="1\n"
...@@ -20,8 +21,9 @@ const MyEnum = enum(u8) {...@@ -20,8 +21,9 @@ const MyEnum = enum(u8) {
20 bar = 2,21 bar = 2,
21};22};
22pub fn main() !void {23pub fn main() !void {
23 try std.io.getStdOut().writer().print("{}\n", .{@intFromEnum(MyEnum.foo)});24 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
25 try stdout_writer.interface.print("{}\n", .{@intFromEnum(MyEnum.foo)});
24}26}
25const std = @import("std");27const std = @import("std");
26#expect_error=main.zig:6:73: error: enum 'main.MyEnum' has no member named 'foo'28#expect_error=main.zig:7:69: error: enum 'main.MyEnum' has no member named 'foo'
27#expect_error=main.zig:1:16: note: enum declared here29#expect_error=main.zig:1:16: note: enum declared here
test/incremental/unreferenced_error+4-4
...@@ -6,7 +6,7 @@...@@ -6,7 +6,7 @@
6#file=main.zig6#file=main.zig
7const std = @import("std");7const std = @import("std");
8pub fn main() !void {8pub fn main() !void {
9 try std.io.getStdOut().writeAll(a);9 try std.fs.File.stdout().writeAll(a);
10}10}
11const a = "Hello, World!\n";11const a = "Hello, World!\n";
12#expect_stdout="Hello, World!\n"12#expect_stdout="Hello, World!\n"
...@@ -15,7 +15,7 @@ const a = "Hello, World!\n";...@@ -15,7 +15,7 @@ const a = "Hello, World!\n";
15#file=main.zig15#file=main.zig
16const std = @import("std");16const std = @import("std");
17pub fn main() !void {17pub fn main() !void {
18 try std.io.getStdOut().writeAll(a);18 try std.fs.File.stdout().writeAll(a);
19}19}
20const a = @compileError("bad a");20const a = @compileError("bad a");
21#expect_error=main.zig:5:11: error: bad a21#expect_error=main.zig:5:11: error: bad a
...@@ -24,7 +24,7 @@ const a = @compileError("bad a");...@@ -24,7 +24,7 @@ const a = @compileError("bad a");
24#file=main.zig24#file=main.zig
25const std = @import("std");25const std = @import("std");
26pub fn main() !void {26pub fn main() !void {
27 try std.io.getStdOut().writeAll(b);27 try std.fs.File.stdout().writeAll(b);
28}28}
29const a = @compileError("bad a");29const a = @compileError("bad a");
30const b = "Hi there!\n";30const b = "Hi there!\n";
...@@ -34,7 +34,7 @@ const b = "Hi there!\n";...@@ -34,7 +34,7 @@ const b = "Hi there!\n";
34#file=main.zig34#file=main.zig
35const std = @import("std");35const std = @import("std");
36pub fn main() !void {36pub fn main() !void {
37 try std.io.getStdOut().writeAll(a);37 try std.fs.File.stdout().writeAll(a);
38}38}
39const a = "Back to a\n";39const a = "Back to a\n";
40const b = @compileError("bad b");40const b = @compileError("bad b");
test/link/bss/main.zig+4-1
...@@ -4,8 +4,11 @@ const std = @import("std");...@@ -4,8 +4,11 @@ const std = @import("std");
4var buffer: [0x1000000]u64 = [1]u64{0} ** 0x1000000;4var buffer: [0x1000000]u64 = [1]u64{0} ** 0x1000000;
55
6pub fn main() anyerror!void {6pub fn main() anyerror!void {
7 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
8
7 buffer[0x10] = 1;9 buffer[0x10] = 1;
8 try std.io.getStdOut().writer().print("{d}, {d}, {d}\n", .{10
11 try stdout_writer.interface.print("{d}, {d}, {d}\n", .{
9 // workaround the dreaded decl_val12 // workaround the dreaded decl_val
10 (&buffer)[0],13 (&buffer)[0],
11 (&buffer)[0x10],14 (&buffer)[0x10],
test/link/elf.zig+4-4
...@@ -1315,8 +1315,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step {...@@ -1315,8 +1315,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step {
1315 \\extern var live_var2: i32;1315 \\extern var live_var2: i32;
1316 \\extern fn live_fn2() void;1316 \\extern fn live_fn2() void;
1317 \\pub fn main() void {1317 \\pub fn main() void {
1318 \\ const stdout = std.io.getStdOut();1318 \\ var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
1319 \\ stdout.deprecatedWriter().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable;1319 \\ stdout_writer.interface.print("{d} {d}\n", .{ live_var1, live_var2 }) catch @panic("fail");
1320 \\ live_fn2();1320 \\ live_fn2();
1321 \\}1321 \\}
1322 ,1322 ,
...@@ -1357,8 +1357,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step {...@@ -1357,8 +1357,8 @@ fn testGcSectionsZig(b: *Build, opts: Options) *Step {
1357 \\extern var live_var2: i32;1357 \\extern var live_var2: i32;
1358 \\extern fn live_fn2() void;1358 \\extern fn live_fn2() void;
1359 \\pub fn main() void {1359 \\pub fn main() void {
1360 \\ const stdout = std.io.getStdOut();1360 \\ var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
1361 \\ stdout.deprecatedWriter().print("{d} {d}\n", .{ live_var1, live_var2 }) catch unreachable;1361 \\ stdout_writer.interface.print("{d} {d}\n", .{ live_var1, live_var2 }) catch @panic("fail");
1362 \\ live_fn2();1362 \\ live_fn2();
1363 \\}1363 \\}
1364 ,1364 ,
test/link/macho.zig+4-3
...@@ -710,7 +710,7 @@ fn testHelloZig(b: *Build, opts: Options) *Step {...@@ -710,7 +710,7 @@ fn testHelloZig(b: *Build, opts: Options) *Step {
710 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes = 710 const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
711 \\const std = @import("std");711 \\const std = @import("std");
712 \\pub fn main() void {712 \\pub fn main() void {
713 \\ std.io.getStdOut().writer().print("Hello world!\n", .{}) catch unreachable;713 \\ std.fs.File.stdout().writeAll("Hello world!\n") catch @panic("fail");
714 \\}714 \\}
715 });715 });
716716
...@@ -2365,10 +2365,11 @@ fn testTlsZig(b: *Build, opts: Options) *Step {...@@ -2365,10 +2365,11 @@ fn testTlsZig(b: *Build, opts: Options) *Step {
2365 \\threadlocal var x: i32 = 0;2365 \\threadlocal var x: i32 = 0;
2366 \\threadlocal var y: i32 = -1;2366 \\threadlocal var y: i32 = -1;
2367 \\pub fn main() void {2367 \\pub fn main() void {
2368 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;2368 \\ var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
2369 \\ stdout_writer.interface.print("{d} {d}\n", .{x, y}) catch unreachable;
2369 \\ x -= 1;2370 \\ x -= 1;
2370 \\ y += 1;2371 \\ y += 1;
2371 \\ std.io.getStdOut().writer().print("{d} {d}\n", .{x, y}) catch unreachable;2372 \\ stdout_writer.interface.print("{d} {d}\n", .{x, y}) catch unreachable;
2372 \\}2373 \\}
2373 });2374 });
23742375
test/link/wasm/extern/main.zig+2-2
...@@ -3,6 +3,6 @@ const std = @import("std");...@@ -3,6 +3,6 @@ const std = @import("std");
3extern const foo: u32;3extern const foo: u32;
44
5pub fn main() void {5pub fn main() void {
6 const std_out = std.io.getStdOut();6 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
7 std_out.writer().print("Result: {d}", .{foo}) catch {};7 stdout_writer.interface.print("Result: {d}", .{foo}) catch {};
8}8}
test/src/check-stack-trace.zig+1-1
...@@ -84,5 +84,5 @@ pub fn main() !void {...@@ -84,5 +84,5 @@ pub fn main() !void {
84 break :got_result try buf.toOwnedSlice();84 break :got_result try buf.toOwnedSlice();
85 };85 };
8686
87 try std.io.getStdOut().writeAll(got);87 try std.fs.File.stdout().writeAll(got);
88}88}
test/standalone/child_process/child.zig+4-3
...@@ -27,12 +27,12 @@ fn run(allocator: std.mem.Allocator) !void {...@@ -27,12 +27,12 @@ fn run(allocator: std.mem.Allocator) !void {
27 }27 }
2828
29 // test stdout pipe; parent verifies29 // test stdout pipe; parent verifies
30 try std.io.getStdOut().writer().writeAll("hello from stdout");30 try std.fs.File.stdout().writeAll("hello from stdout");
3131
32 // test stdin pipe from parent32 // test stdin pipe from parent
33 const hello_stdin = "hello from stdin";33 const hello_stdin = "hello from stdin";
34 var buf: [hello_stdin.len]u8 = undefined;34 var buf: [hello_stdin.len]u8 = undefined;
35 const stdin = std.io.getStdIn().reader();35 const stdin: std.fs.File = .stdin();
36 const n = try stdin.readAll(&buf);36 const n = try stdin.readAll(&buf);
37 if (!std.mem.eql(u8, buf[0..n], hello_stdin)) {37 if (!std.mem.eql(u8, buf[0..n], hello_stdin)) {
38 testError("stdin: '{s}'; want '{s}'", .{ buf[0..n], hello_stdin });38 testError("stdin: '{s}'; want '{s}'", .{ buf[0..n], hello_stdin });
...@@ -40,7 +40,8 @@ fn run(allocator: std.mem.Allocator) !void {...@@ -40,7 +40,8 @@ fn run(allocator: std.mem.Allocator) !void {
40}40}
4141
42fn testError(comptime fmt: []const u8, args: anytype) void {42fn testError(comptime fmt: []const u8, args: anytype) void {
43 const stderr = std.io.getStdErr().writer();43 var stderr_writer = std.fs.File.stderr().writer(&.{});
44 const stderr = &stderr_writer.interface;
44 stderr.print("CHILD TEST ERROR: ", .{}) catch {};45 stderr.print("CHILD TEST ERROR: ", .{}) catch {};
45 stderr.print(fmt, args) catch {};46 stderr.print(fmt, args) catch {};
46 if (fmt[fmt.len - 1] != '\n') {47 if (fmt[fmt.len - 1] != '\n') {
test/standalone/child_process/main.zig+4-3
...@@ -19,13 +19,13 @@ pub fn main() !void {...@@ -19,13 +19,13 @@ pub fn main() !void {
19 child.stderr_behavior = .Inherit;19 child.stderr_behavior = .Inherit;
20 try child.spawn();20 try child.spawn();
21 const child_stdin = child.stdin.?;21 const child_stdin = child.stdin.?;
22 try child_stdin.writer().writeAll("hello from stdin"); // verified in child22 try child_stdin.writeAll("hello from stdin"); // verified in child
23 child_stdin.close();23 child_stdin.close();
24 child.stdin = null;24 child.stdin = null;
2525
26 const hello_stdout = "hello from stdout";26 const hello_stdout = "hello from stdout";
27 var buf: [hello_stdout.len]u8 = undefined;27 var buf: [hello_stdout.len]u8 = undefined;
28 const n = try child.stdout.?.reader().readAll(&buf);28 const n = try child.stdout.?.deprecatedReader().readAll(&buf);
29 if (!std.mem.eql(u8, buf[0..n], hello_stdout)) {29 if (!std.mem.eql(u8, buf[0..n], hello_stdout)) {
30 testError("child stdout: '{s}'; want '{s}'", .{ buf[0..n], hello_stdout });30 testError("child stdout: '{s}'; want '{s}'", .{ buf[0..n], hello_stdout });
31 }31 }
...@@ -45,7 +45,8 @@ pub fn main() !void {...@@ -45,7 +45,8 @@ pub fn main() !void {
45var parent_test_error = false;45var parent_test_error = false;
4646
47fn testError(comptime fmt: []const u8, args: anytype) void {47fn testError(comptime fmt: []const u8, args: anytype) void {
48 const stderr = std.io.getStdErr().writer();48 var stderr_writer = std.fs.File.stderr().writer(&.{});
49 const stderr = &stderr_writer.interface;
49 stderr.print("PARENT TEST ERROR: ", .{}) catch {};50 stderr.print("PARENT TEST ERROR: ", .{}) catch {};
50 stderr.print(fmt, args) catch {};51 stderr.print(fmt, args) catch {};
51 if (fmt[fmt.len - 1] != '\n') {52 if (fmt[fmt.len - 1] != '\n') {
test/standalone/sigpipe/breakpipe.zig+1-1
...@@ -10,7 +10,7 @@ pub fn main() !void {...@@ -10,7 +10,7 @@ pub fn main() !void {
10 std.posix.close(pipe[0]);10 std.posix.close(pipe[0]);
11 _ = std.posix.write(pipe[1], "a") catch |err| switch (err) {11 _ = std.posix.write(pipe[1], "a") catch |err| switch (err) {
12 error.BrokenPipe => {12 error.BrokenPipe => {
13 try std.io.getStdOut().writer().writeAll("BrokenPipe\n");13 try std.fs.File.stdout().writeAll("BrokenPipe\n");
14 std.posix.exit(123);14 std.posix.exit(123);
15 },15 },
16 else => |e| return e,16 else => |e| return e,
test/standalone/simple/brace_expansion.zig deleted-292
...@@ -1,292 +0,0 @@
1const std = @import("std");
2const io = std.io;
3const mem = std.mem;
4const debug = std.debug;
5const assert = debug.assert;
6const testing = std.testing;
7const ArrayList = std.ArrayList;
8const maxInt = std.math.maxInt;
9
10const Token = union(enum) {
11 Word: []const u8,
12 OpenBrace,
13 CloseBrace,
14 Comma,
15 Eof,
16};
17
18var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
19var global_allocator = gpa.allocator();
20
21fn tokenize(input: []const u8) !ArrayList(Token) {
22 const State = enum {
23 Start,
24 Word,
25 };
26
27 var token_list = ArrayList(Token).init(global_allocator);
28 errdefer token_list.deinit();
29 var tok_begin: usize = undefined;
30 var state = State.Start;
31
32 for (input, 0..) |b, i| {
33 switch (state) {
34 .Start => switch (b) {
35 'a'...'z', 'A'...'Z' => {
36 state = State.Word;
37 tok_begin = i;
38 },
39 '{' => try token_list.append(Token.OpenBrace),
40 '}' => try token_list.append(Token.CloseBrace),
41 ',' => try token_list.append(Token.Comma),
42 else => return error.InvalidInput,
43 },
44 .Word => switch (b) {
45 'a'...'z', 'A'...'Z' => {},
46 '{', '}', ',' => {
47 try token_list.append(Token{ .Word = input[tok_begin..i] });
48 switch (b) {
49 '{' => try token_list.append(Token.OpenBrace),
50 '}' => try token_list.append(Token.CloseBrace),
51 ',' => try token_list.append(Token.Comma),
52 else => unreachable,
53 }
54 state = State.Start;
55 },
56 else => return error.InvalidInput,
57 },
58 }
59 }
60 switch (state) {
61 State.Start => {},
62 State.Word => try token_list.append(Token{ .Word = input[tok_begin..] }),
63 }
64 try token_list.append(Token.Eof);
65 return token_list;
66}
67
68const Node = union(enum) {
69 Scalar: []const u8,
70 List: ArrayList(Node),
71 Combine: []Node,
72
73 fn deinit(self: Node) void {
74 switch (self) {
75 .Scalar => {},
76 .Combine => |pair| {
77 pair[0].deinit();
78 pair[1].deinit();
79 global_allocator.free(pair);
80 },
81 .List => |list| {
82 for (list.items) |item| {
83 item.deinit();
84 }
85 list.deinit();
86 },
87 }
88 }
89};
90
91const ParseError = error{
92 InvalidInput,
93 OutOfMemory,
94};
95
96fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
97 const first_token = tokens.items[token_index.*];
98 token_index.* += 1;
99
100 const result_node = switch (first_token) {
101 .Word => |word| Node{ .Scalar = word },
102 .OpenBrace => blk: {
103 var list = ArrayList(Node).init(global_allocator);
104 errdefer {
105 for (list.items) |node| node.deinit();
106 list.deinit();
107 }
108 while (true) {
109 try list.append(try parse(tokens, token_index));
110
111 const token = tokens.items[token_index.*];
112 token_index.* += 1;
113
114 switch (token) {
115 .CloseBrace => break,
116 .Comma => continue,
117 else => return error.InvalidInput,
118 }
119 }
120 break :blk Node{ .List = list };
121 },
122 else => return error.InvalidInput,
123 };
124
125 switch (tokens.items[token_index.*]) {
126 .Word, .OpenBrace => {
127 const pair = try global_allocator.alloc(Node, 2);
128 errdefer global_allocator.free(pair);
129 pair[0] = result_node;
130 pair[1] = try parse(tokens, token_index);
131 return Node{ .Combine = pair };
132 },
133 else => return result_node,
134 }
135}
136
137fn expandString(input: []const u8, output: *ArrayList(u8)) !void {
138 const tokens = try tokenize(input);
139 defer tokens.deinit();
140 if (tokens.items.len == 1) {
141 return output.resize(0);
142 }
143
144 var token_index: usize = 0;
145 const root = try parse(&tokens, &token_index);
146 defer root.deinit();
147 const last_token = tokens.items[token_index];
148 switch (last_token) {
149 Token.Eof => {},
150 else => return error.InvalidInput,
151 }
152
153 var result_list = ArrayList(ArrayList(u8)).init(global_allocator);
154 defer {
155 for (result_list.items) |*buf| buf.deinit();
156 result_list.deinit();
157 }
158
159 try expandNode(root, &result_list);
160
161 try output.resize(0);
162 for (result_list.items, 0..) |buf, i| {
163 if (i != 0) {
164 try output.append(' ');
165 }
166 try output.appendSlice(buf.items);
167 }
168}
169
170const ExpandNodeError = error{OutOfMemory};
171
172fn expandNode(node: Node, output: *ArrayList(ArrayList(u8))) ExpandNodeError!void {
173 assert(output.items.len == 0);
174 switch (node) {
175 .Scalar => |scalar| {
176 var list = ArrayList(u8).init(global_allocator);
177 errdefer list.deinit();
178 try list.appendSlice(scalar);
179 try output.append(list);
180 },
181 .Combine => |pair| {
182 const a_node = pair[0];
183 const b_node = pair[1];
184
185 var child_list_a = ArrayList(ArrayList(u8)).init(global_allocator);
186 defer {
187 for (child_list_a.items) |*buf| buf.deinit();
188 child_list_a.deinit();
189 }
190 try expandNode(a_node, &child_list_a);
191
192 var child_list_b = ArrayList(ArrayList(u8)).init(global_allocator);
193 defer {
194 for (child_list_b.items) |*buf| buf.deinit();
195 child_list_b.deinit();
196 }
197 try expandNode(b_node, &child_list_b);
198
199 for (child_list_a.items) |buf_a| {
200 for (child_list_b.items) |buf_b| {
201 var combined_buf = ArrayList(u8).init(global_allocator);
202 errdefer combined_buf.deinit();
203
204 try combined_buf.appendSlice(buf_a.items);
205 try combined_buf.appendSlice(buf_b.items);
206 try output.append(combined_buf);
207 }
208 }
209 },
210 .List => |list| {
211 for (list.items) |child_node| {
212 var child_list = ArrayList(ArrayList(u8)).init(global_allocator);
213 errdefer for (child_list.items) |*buf| buf.deinit();
214 defer child_list.deinit();
215
216 try expandNode(child_node, &child_list);
217
218 for (child_list.items) |buf| {
219 try output.append(buf);
220 }
221 }
222 },
223 }
224}
225
226pub fn main() !void {
227 defer _ = gpa.deinit();
228 const stdin_file = io.getStdIn();
229 const stdout_file = io.getStdOut();
230
231 const stdin = try stdin_file.deprecatedReader().readAllAlloc(global_allocator, std.math.maxInt(usize));
232 defer global_allocator.free(stdin);
233
234 var result_buf = ArrayList(u8).init(global_allocator);
235 defer result_buf.deinit();
236
237 try expandString(stdin, &result_buf);
238 try stdout_file.writeAll(result_buf.items);
239}
240
241test "invalid inputs" {
242 global_allocator = std.testing.allocator;
243
244 try expectError("}ABC", error.InvalidInput);
245 try expectError("{ABC", error.InvalidInput);
246 try expectError("}{", error.InvalidInput);
247 try expectError("{}", error.InvalidInput);
248 try expectError("A,B,C", error.InvalidInput);
249 try expectError("{A{B,C}", error.InvalidInput);
250 try expectError("{A,}", error.InvalidInput);
251
252 try expectError("\n", error.InvalidInput);
253}
254
255fn expectError(test_input: []const u8, expected_err: anyerror) !void {
256 var output_buf = ArrayList(u8).init(global_allocator);
257 defer output_buf.deinit();
258
259 try testing.expectError(expected_err, expandString(test_input, &output_buf));
260}
261
262test "valid inputs" {
263 global_allocator = std.testing.allocator;
264
265 try expectExpansion("{x,y,z}", "x y z");
266 try expectExpansion("{A,B}{x,y}", "Ax Ay Bx By");
267 try expectExpansion("{A,B{x,y}}", "A Bx By");
268
269 try expectExpansion("{ABC}", "ABC");
270 try expectExpansion("{A,B,C}", "A B C");
271 try expectExpansion("ABC", "ABC");
272
273 try expectExpansion("", "");
274 try expectExpansion("{A,B}{C,{x,y}}{g,h}", "ACg ACh Axg Axh Ayg Ayh BCg BCh Bxg Bxh Byg Byh");
275 try expectExpansion("{A,B}{C,C{x,y}}{g,h}", "ACg ACh ACxg ACxh ACyg ACyh BCg BCh BCxg BCxh BCyg BCyh");
276 try expectExpansion("{A,B}a", "Aa Ba");
277 try expectExpansion("{C,{x,y}}", "C x y");
278 try expectExpansion("z{C,{x,y}}", "zC zx zy");
279 try expectExpansion("a{b,c{d,e{f,g}}}", "ab acd acef aceg");
280 try expectExpansion("a{x,y}b", "axb ayb");
281 try expectExpansion("z{{a,b}}", "za zb");
282 try expectExpansion("a{b}", "ab");
283}
284
285fn expectExpansion(test_input: []const u8, expected_result: []const u8) !void {
286 var result = ArrayList(u8).init(global_allocator);
287 defer result.deinit();
288
289 expandString(test_input, &result) catch unreachable;
290
291 try testing.expectEqualSlices(u8, expected_result, result.items);
292}
test/standalone/simple/build.zig-4
...@@ -109,10 +109,6 @@ const cases = [_]Case{...@@ -109,10 +109,6 @@ const cases = [_]Case{
109 //.{109 //.{
110 // .src_path = "issue_9693/main.zig",110 // .src_path = "issue_9693/main.zig",
111 //},111 //},
112 .{
113 .src_path = "brace_expansion.zig",
114 .is_test = true,
115 },
116 .{112 .{
117 .src_path = "issue_7030.zig",113 .src_path = "issue_7030.zig",
118 .target = .{114 .target = .{
test/standalone/simple/cat/main.zig+10-10
...@@ -1,42 +1,42 @@...@@ -1,42 +1,42 @@
1const std = @import("std");1const std = @import("std");
2const io = std.io;2const io = std.io;
3const process = std.process;
4const fs = std.fs;3const fs = std.fs;
5const mem = std.mem;4const mem = std.mem;
6const warn = std.log.warn;5const warn = std.log.warn;
6const fatal = std.process.fatal;
77
8pub fn main() !void {8pub fn main() !void {
9 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);9 var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
10 defer arena_instance.deinit();10 defer arena_instance.deinit();
11 const arena = arena_instance.allocator();11 const arena = arena_instance.allocator();
1212
13 const args = try process.argsAlloc(arena);13 const args = try std.process.argsAlloc(arena);
1414
15 const exe = args[0];15 const exe = args[0];
16 var catted_anything = false;16 var catted_anything = false;
17 const stdout_file = io.getStdOut();17 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
18 const stdout = &stdout_writer.interface;
19 var stdin_reader = std.fs.File.stdin().reader(&.{});
1820
19 const cwd = fs.cwd();21 const cwd = fs.cwd();
2022
21 for (args[1..]) |arg| {23 for (args[1..]) |arg| {
22 if (mem.eql(u8, arg, "-")) {24 if (mem.eql(u8, arg, "-")) {
23 catted_anything = true;25 catted_anything = true;
24 try stdout_file.writeFileAll(io.getStdIn(), .{});26 _ = try stdout.sendFileAll(&stdin_reader, .unlimited);
25 } else if (mem.startsWith(u8, arg, "-")) {27 } else if (mem.startsWith(u8, arg, "-")) {
26 return usage(exe);28 return usage(exe);
27 } else {29 } else {
28 const file = cwd.openFile(arg, .{}) catch |err| {30 const file = cwd.openFile(arg, .{}) catch |err| fatal("unable to open file: {t}\n", .{err});
29 warn("Unable to open file: {s}\n", .{@errorName(err)});
30 return err;
31 };
32 defer file.close();31 defer file.close();
3332
34 catted_anything = true;33 catted_anything = true;
35 try stdout_file.writeFileAll(file, .{});34 var file_reader = file.reader(&.{});
35 _ = try stdout.sendFileAll(&file_reader, .unlimited);
36 }36 }
37 }37 }
38 if (!catted_anything) {38 if (!catted_anything) {
39 try stdout_file.writeFileAll(io.getStdIn(), .{});39 _ = try stdout.sendFileAll(&stdin_reader, .unlimited);
40 }40 }
41}41}
4242
test/standalone/simple/guess_number/main.zig+11-13
...@@ -1,37 +1,35 @@...@@ -1,37 +1,35 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const io = std.io;
4const fmt = std.fmt;
53
6pub fn main() !void {4pub fn main() !void {
7 const stdout = io.getStdOut().writer();5 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
8 const stdin = io.getStdIn();6 const out = &stdout_writer.interface;
7 const stdin: std.fs.File = .stdin();
98
10 try stdout.print("Welcome to the Guess Number Game in Zig.\n", .{});9 try out.writeAll("Welcome to the Guess Number Game in Zig.\n");
1110
12 const answer = std.crypto.random.intRangeLessThan(u8, 0, 100) + 1;11 const answer = std.crypto.random.intRangeLessThan(u8, 0, 100) + 1;
1312
14 while (true) {13 while (true) {
15 try stdout.print("\nGuess a number between 1 and 100: ", .{});14 try out.writeAll("\nGuess a number between 1 and 100: ");
16 var line_buf: [20]u8 = undefined;15 var line_buf: [20]u8 = undefined;
17
18 const amt = try stdin.read(&line_buf);16 const amt = try stdin.read(&line_buf);
19 if (amt == line_buf.len) {17 if (amt == line_buf.len) {
20 try stdout.print("Input too long.\n", .{});18 try out.writeAll("Input too long.\n");
21 continue;19 continue;
22 }20 }
23 const line = std.mem.trimEnd(u8, line_buf[0..amt], "\r\n");21 const line = std.mem.trimEnd(u8, line_buf[0..amt], "\r\n");
2422
25 const guess = fmt.parseUnsigned(u8, line, 10) catch {23 const guess = std.fmt.parseUnsigned(u8, line, 10) catch {
26 try stdout.print("Invalid number.\n", .{});24 try out.writeAll("Invalid number.\n");
27 continue;25 continue;
28 };26 };
29 if (guess > answer) {27 if (guess > answer) {
30 try stdout.print("Guess lower.\n", .{});28 try out.writeAll("Guess lower.\n");
31 } else if (guess < answer) {29 } else if (guess < answer) {
32 try stdout.print("Guess higher.\n", .{});30 try out.writeAll("Guess higher.\n");
33 } else {31 } else {
34 try stdout.print("You win!\n", .{});32 try out.writeAll("You win!\n");
35 return;33 return;
36 }34 }
37 }35 }
test/standalone/simple/hello_world/hello.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() !void {3pub fn main() !void {
4 try std.io.getStdOut().writeAll("Hello, World!\n");4 try std.fs.File.stdout().writeAll("Hello, World!\n");
5}5}
test/standalone/simple/std_enums_big_enums.zig+1
...@@ -6,6 +6,7 @@ pub fn main() void {...@@ -6,6 +6,7 @@ pub fn main() void {
6 const Big = @Type(.{ .@"enum" = .{6 const Big = @Type(.{ .@"enum" = .{
7 .tag_type = u16,7 .tag_type = u16,
8 .fields = make_fields: {8 .fields = make_fields: {
9 @setEvalBranchQuota(500000);
9 var fields: [1001]std.builtin.Type.EnumField = undefined;10 var fields: [1001]std.builtin.Type.EnumField = undefined;
10 for (&fields, 0..) |*field, i| {11 for (&fields, 0..) |*field, i| {
11 field.* = .{ .name = std.fmt.comptimePrint("field_{d}", .{i}), .value = i };12 field.* = .{ .name = std.fmt.comptimePrint("field_{d}", .{i}), .value = i };
test/standalone/windows_bat_args/echo-args.zig+2-1
...@@ -5,7 +5,8 @@ pub fn main() !void {...@@ -5,7 +5,8 @@ pub fn main() !void {
5 defer arena_state.deinit();5 defer arena_state.deinit();
6 const arena = arena_state.allocator();6 const arena = arena_state.allocator();
77
8 const stdout = std.io.getStdOut().writer();8 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
9 const stdout = &stdout_writer.interface;
9 var args = try std.process.argsAlloc(arena);10 var args = try std.process.argsAlloc(arena);
10 for (args[1..], 1..) |arg, i| {11 for (args[1..], 1..) |arg, i| {
11 try stdout.writeAll(arg);12 try stdout.writeAll(arg);
test/standalone/windows_spawn/hello.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn main() !void {3pub fn main() !void {
4 const stdout = std.io.getStdOut().writer();4 var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
5 const stdout = &stdout_writer.interface;
5 try stdout.writeAll("hello from exe\n");6 try stdout.writeAll("hello from exe\n");
6}7}
tools/docgen.zig+1-2
...@@ -43,8 +43,7 @@ pub fn main() !void {...@@ -43,8 +43,7 @@ pub fn main() !void {
43 while (args_it.next()) |arg| {43 while (args_it.next()) |arg| {
44 if (mem.startsWith(u8, arg, "-")) {44 if (mem.startsWith(u8, arg, "-")) {
45 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {45 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
46 const stdout = io.getStdOut().writer();46 try fs.File.stdout().writeAll(usage);
47 try stdout.writeAll(usage);
48 process.exit(0);47 process.exit(0);
49 } else if (mem.eql(u8, arg, "--code-dir")) {48 } else if (mem.eql(u8, arg, "--code-dir")) {
50 if (args_it.next()) |param| {49 if (args_it.next()) |param| {
tools/doctest.zig+1-1
...@@ -44,7 +44,7 @@ pub fn main() !void {...@@ -44,7 +44,7 @@ pub fn main() !void {
44 while (args_it.next()) |arg| {44 while (args_it.next()) |arg| {
45 if (mem.startsWith(u8, arg, "-")) {45 if (mem.startsWith(u8, arg, "-")) {
46 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {46 if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
47 try std.io.getStdOut().writeAll(usage);47 try std.fs.File.stdout().writeAll(usage);
48 process.exit(0);48 process.exit(0);
49 } else if (mem.eql(u8, arg, "-i")) {49 } else if (mem.eql(u8, arg, "-i")) {
50 opt_input = args_it.next() orelse fatal("expected parameter after -i", .{});50 opt_input = args_it.next() orelse fatal("expected parameter after -i", .{});
tools/dump-cov.zig+4-3
...@@ -48,8 +48,9 @@ pub fn main() !void {...@@ -48,8 +48,9 @@ pub fn main() !void {
48 fatal("failed to load coverage file {}: {s}", .{ cov_path, @errorName(err) });48 fatal("failed to load coverage file {}: {s}", .{ cov_path, @errorName(err) });
49 };49 };
5050
51 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());51 var stdout_buffer: [4000]u8 = undefined;
52 const stdout = bw.writer();52 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
53 const stdout = &stdout_writer.interface;
5354
54 const header: *SeenPcsHeader = @ptrCast(cov_bytes);55 const header: *SeenPcsHeader = @ptrCast(cov_bytes);
55 try stdout.print("{any}\n", .{header.*});56 try stdout.print("{any}\n", .{header.*});
...@@ -83,5 +84,5 @@ pub fn main() !void {...@@ -83,5 +84,5 @@ pub fn main() !void {
83 });84 });
84 }85 }
8586
86 try bw.flush();87 try stdout.flush();
87}88}
tools/fetch_them_macos_headers.zig+2-13
...@@ -5,6 +5,8 @@ const mem = std.mem;...@@ -5,6 +5,8 @@ const mem = std.mem;
5const process = std.process;5const process = std.process;
6const assert = std.debug.assert;6const assert = std.debug.assert;
7const tmpDir = std.testing.tmpDir;7const tmpDir = std.testing.tmpDir;
8const fatal = std.process.fatal;
9const info = std.log.info;
810
9const Allocator = mem.Allocator;11const Allocator = mem.Allocator;
10const OsTag = std.Target.Os.Tag;12const OsTag = std.Target.Os.Tag;
...@@ -245,19 +247,6 @@ const ArgsIterator = struct {...@@ -245,19 +247,6 @@ const ArgsIterator = struct {
245 }247 }
246};248};
247249
248fn info(comptime format: []const u8, args: anytype) void {
249 const msg = std.fmt.allocPrint(gpa, "info: " ++ format ++ "\n", args) catch return;
250 std.io.getStdOut().writeAll(msg) catch {};
251}
252
253fn fatal(comptime format: []const u8, args: anytype) noreturn {
254 ret: {
255 const msg = std.fmt.allocPrint(gpa, "fatal: " ++ format ++ "\n", args) catch break :ret;
256 std.io.getStdErr().writeAll(msg) catch {};
257 }
258 std.process.exit(1);
259}
260
261const Version = struct {250const Version = struct {
262 major: u16,251 major: u16,
263 minor: u8,252 minor: u8,
tools/gen_macos_headers_c.zig+9-17
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const assert = std.debug.assert;2const assert = std.debug.assert;
3const info = std.log.info;
4const fatal = std.process.fatal;
35
4const Allocator = std.mem.Allocator;6const Allocator = std.mem.Allocator;
57
...@@ -13,19 +15,6 @@ const usage =...@@ -13,19 +15,6 @@ const usage =
13 \\-h, --help Print this help and exit15 \\-h, --help Print this help and exit
14;16;
1517
16fn info(comptime format: []const u8, args: anytype) void {
17 const msg = std.fmt.allocPrint(gpa, "info: " ++ format ++ "\n", args) catch return;
18 std.io.getStdOut().writeAll(msg) catch {};
19}
20
21fn fatal(comptime format: []const u8, args: anytype) noreturn {
22 ret: {
23 const msg = std.fmt.allocPrint(gpa, "fatal: " ++ format ++ "\n", args) catch break :ret;
24 std.io.getStdErr().writeAll(msg) catch {};
25 }
26 std.process.exit(1);
27}
28
29pub fn main() anyerror!void {18pub fn main() anyerror!void {
30 var arena_allocator = std.heap.ArenaAllocator.init(gpa);19 var arena_allocator = std.heap.ArenaAllocator.init(gpa);
31 defer arena_allocator.deinit();20 defer arena_allocator.deinit();
...@@ -58,16 +47,19 @@ pub fn main() anyerror!void {...@@ -58,16 +47,19 @@ pub fn main() anyerror!void {
5847
59 std.mem.sort([]const u8, paths.items, {}, SortFn.lessThan);48 std.mem.sort([]const u8, paths.items, {}, SortFn.lessThan);
6049
61 const stdout = std.io.getStdOut().writer();50 var buffer: [2000]u8 = undefined;
62 try stdout.writeAll("#define _XOPEN_SOURCE\n");51 var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
52 const w = &stdout_writer.interface;
53 try w.writeAll("#define _XOPEN_SOURCE\n");
63 for (paths.items) |path| {54 for (paths.items) |path| {
64 try stdout.print("#include <{s}>\n", .{path});55 try w.print("#include <{s}>\n", .{path});
65 }56 }
66 try stdout.writeAll(57 try w.writeAll(
67 \\int main(int argc, char **argv) {58 \\int main(int argc, char **argv) {
68 \\ return 0;59 \\ return 0;
69 \\}60 \\}
70 );61 );
62 try w.flush();
71}63}
7264
73fn findHeaders(65fn findHeaders(
tools/gen_outline_atomics.zig+4-3
...@@ -17,8 +17,9 @@ pub fn main() !void {...@@ -17,8 +17,9 @@ pub fn main() !void {
1717
18 //const args = try std.process.argsAlloc(arena);18 //const args = try std.process.argsAlloc(arena);
1919
20 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());20 var stdout_buffer: [2000]u8 = undefined;
21 const w = bw.writer();21 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
22 const w = &stdout_writer.interface;
2223
23 try w.writeAll(24 try w.writeAll(
24 \\//! This file is generated by tools/gen_outline_atomics.zig.25 \\//! This file is generated by tools/gen_outline_atomics.zig.
...@@ -57,7 +58,7 @@ pub fn main() !void {...@@ -57,7 +58,7 @@ pub fn main() !void {
5758
58 try w.writeAll(footer.items);59 try w.writeAll(footer.items);
59 try w.writeAll("}\n");60 try w.writeAll("}\n");
60 try bw.flush();61 try w.flush();
61}62}
6263
63fn writeFunction(64fn writeFunction(
tools/gen_spirv_spec.zig+9-12
...@@ -91,9 +91,10 @@ pub fn main() !void {...@@ -91,9 +91,10 @@ pub fn main() !void {
9191
92 try readExtRegistry(&exts, a, std.fs.cwd(), args[2]);92 try readExtRegistry(&exts, a, std.fs.cwd(), args[2]);
9393
94 var bw = std.io.bufferedWriter(std.io.getStdOut().writer());94 var buffer: [4000]u8 = undefined;
95 try render(bw.writer(), a, core_spec, exts.items);95 var w = std.fs.File.stdout().writerStreaming(&buffer);
96 try bw.flush();96 try render(&w, a, core_spec, exts.items);
97 try w.flush();
97}98}
9899
99fn readExtRegistry(exts: *std.ArrayList(Extension), a: Allocator, dir: std.fs.Dir, sub_path: []const u8) !void {100fn readExtRegistry(exts: *std.ArrayList(Extension), a: Allocator, dir: std.fs.Dir, sub_path: []const u8) !void {
...@@ -166,7 +167,7 @@ fn tagPriorityScore(tag: []const u8) usize {...@@ -166,7 +167,7 @@ fn tagPriorityScore(tag: []const u8) usize {
166 }167 }
167}168}
168169
169fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []const Extension) !void {170fn render(writer: *std.io.Writer, a: Allocator, registry: CoreRegistry, extensions: []const Extension) !void {
170 try writer.writeAll(171 try writer.writeAll(
171 \\//! This file is auto-generated by tools/gen_spirv_spec.zig.172 \\//! This file is auto-generated by tools/gen_spirv_spec.zig.
172 \\173 \\
...@@ -188,15 +189,10 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c...@@ -188,15 +189,10 @@ fn render(writer: anytype, a: Allocator, registry: CoreRegistry, extensions: []c
188 \\ none,189 \\ none,
189 \\ _,190 \\ _,
190 \\191 \\
191 \\ pub fn format(192 \\ pub fn format(self: IdResult, writer: *std.io.Writer) std.io.Writer.Error!void {
192 \\ self: IdResult,
193 \\ comptime _: []const u8,
194 \\ _: std.fmt.FormatOptions,
195 \\ writer: anytype,
196 \\ ) @TypeOf(writer).Error!void {
197 \\ switch (self) {193 \\ switch (self) {
198 \\ .none => try writer.writeAll("(none)"),194 \\ .none => try writer.writeAll("(none)"),
199 \\ else => try writer.print("%{}", .{@intFromEnum(self)}),195 \\ else => try writer.print("%{d}", .{@intFromEnum(self)}),
200 \\ }196 \\ }
201 \\ }197 \\ }
202 \\};198 \\};
...@@ -899,7 +895,8 @@ fn parseHexInt(text: []const u8) !u31 {...@@ -899,7 +895,8 @@ fn parseHexInt(text: []const u8) !u31 {
899}895}
900896
901fn usageAndExit(arg0: []const u8, code: u8) noreturn {897fn usageAndExit(arg0: []const u8, code: u8) noreturn {
902 std.io.getStdErr().writer().print(898 const stderr = std.debug.lockStderrWriter(&.{});
899 stderr.print(
903 \\Usage: {s} <SPIRV-Headers repository path> <path/to/zig/src/codegen/spirv/extinst.zig.grammar.json>900 \\Usage: {s} <SPIRV-Headers repository path> <path/to/zig/src/codegen/spirv/extinst.zig.grammar.json>
904 \\901 \\
905 \\Generates Zig bindings for SPIR-V specifications found in the SPIRV-Headers902 \\Generates Zig bindings for SPIR-V specifications found in the SPIRV-Headers
tools/gen_stubs.zig+5-1
...@@ -333,7 +333,9 @@ pub fn main() !void {...@@ -333,7 +333,9 @@ pub fn main() !void {
333 }333 }
334 }334 }
335335
336 const stdout = std.io.getStdOut().writer();336 var stdout_buffer: [2000]u8 = undefined;
337 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
338 const stdout = &stdout_writer.interface;
337 try stdout.writeAll(339 try stdout.writeAll(
338 \\#ifdef PTR64340 \\#ifdef PTR64
339 \\#define WEAK64 .weak341 \\#define WEAK64 .weak
...@@ -533,6 +535,8 @@ pub fn main() !void {...@@ -533,6 +535,8 @@ pub fn main() !void {
533 .all => {},535 .all => {},
534 .single, .multi, .family, .time32 => try stdout.writeAll("#endif\n"),536 .single, .multi, .family, .time32 => try stdout.writeAll("#endif\n"),
535 }537 }
538
539 try stdout.flush();
536}540}
537541
538fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) !void {542fn parseElf(parse: Parse, comptime is_64: bool, comptime endian: builtin.Endian) !void {
tools/generate_JSONTestSuite.zig+5-1
...@@ -6,7 +6,9 @@ pub fn main() !void {...@@ -6,7 +6,9 @@ pub fn main() !void {
6 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;6 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
7 var allocator = gpa.allocator();7 var allocator = gpa.allocator();
88
9 var output = std.io.getStdOut().writer();9 var stdout_buffer: [2000]u8 = undefined;
10 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
11 const output = &stdout_writer.interface;
10 try output.writeAll(12 try output.writeAll(
11 \\// This file was generated by _generate_JSONTestSuite.zig13 \\// This file was generated by _generate_JSONTestSuite.zig
12 \\// These test cases are sourced from: https://github.com/nst/JSONTestSuite14 \\// These test cases are sourced from: https://github.com/nst/JSONTestSuite
...@@ -44,6 +46,8 @@ pub fn main() !void {...@@ -44,6 +46,8 @@ pub fn main() !void {
44 try writeString(output, contents);46 try writeString(output, contents);
45 try output.writeAll(");\n}\n");47 try output.writeAll(");\n}\n");
46 }48 }
49
50 try output.flush();
47}51}
4852
49const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500;53const i_structure_500_nested_arrays = "[" ** 500 ++ "]" ** 500;
tools/generate_c_size_and_align_checks.zig+7-4
...@@ -42,20 +42,23 @@ pub fn main() !void {...@@ -42,20 +42,23 @@ pub fn main() !void {
42 const query = try std.Target.Query.parse(.{ .arch_os_abi = args[1] });42 const query = try std.Target.Query.parse(.{ .arch_os_abi = args[1] });
43 const target = try std.zig.system.resolveTargetQuery(query);43 const target = try std.zig.system.resolveTargetQuery(query);
4444
45 const stdout = std.io.getStdOut().writer();45 var buffer: [2000]u8 = undefined;
46 var stdout_writer = std.fs.File.stdout().writerStreaming(&buffer);
47 const w = &stdout_writer.interface;
46 inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| {48 inline for (@typeInfo(std.Target.CType).@"enum".fields) |field| {
47 const c_type: std.Target.CType = @enumFromInt(field.value);49 const c_type: std.Target.CType = @enumFromInt(field.value);
48 try stdout.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{50 try w.print("_Static_assert(sizeof({0s}) == {1d}, \"sizeof({0s}) == {1d}\");\n", .{
49 cName(c_type),51 cName(c_type),
50 target.cTypeByteSize(c_type),52 target.cTypeByteSize(c_type),
51 });53 });
52 try stdout.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{54 try w.print("_Static_assert(_Alignof({0s}) == {1d}, \"_Alignof({0s}) == {1d}\");\n", .{
53 cName(c_type),55 cName(c_type),
54 target.cTypeAlignment(c_type),56 target.cTypeAlignment(c_type),
55 });57 });
56 try stdout.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{58 try w.print("_Static_assert(__alignof({0s}) == {1d}, \"__alignof({0s}) == {1d}\");\n\n", .{
57 cName(c_type),59 cName(c_type),
58 target.cTypePreferredAlignment(c_type),60 target.cTypePreferredAlignment(c_type),
59 });61 });
60 }62 }
63 try w.flush();
61}64}
tools/generate_linux_syscalls.zig+11-9
...@@ -666,13 +666,16 @@ pub fn main() !void {...@@ -666,13 +666,16 @@ pub fn main() !void {
666 const allocator = arena.allocator();666 const allocator = arena.allocator();
667667
668 const args = try std.process.argsAlloc(allocator);668 const args = try std.process.argsAlloc(allocator);
669 if (args.len < 3 or mem.eql(u8, args[1], "--help"))669 if (args.len < 3 or mem.eql(u8, args[1], "--help")) {
670 usageAndExit(std.io.getStdErr(), args[0], 1);670 usage(std.debug.lockStderrWriter(&.{}), args[0]) catch std.process.exit(2);
671 std.process.exit(1);
672 }
671 const zig_exe = args[1];673 const zig_exe = args[1];
672 const linux_path = args[2];674 const linux_path = args[2];
673675
674 var buf_out = std.io.bufferedWriter(std.io.getStdOut().writer());676 var stdout_buffer: [2000]u8 = undefined;
675 const writer = buf_out.writer();677 var stdout_writer = std.fs.File.stdout().writerStreaming(&stdout_buffer);
678 const writer = &stdout_writer.interface;
676679
677 var linux_dir = try std.fs.cwd().openDir(linux_path, .{});680 var linux_dir = try std.fs.cwd().openDir(linux_path, .{});
678 defer linux_dir.close();681 defer linux_dir.close();
...@@ -714,17 +717,16 @@ pub fn main() !void {...@@ -714,17 +717,16 @@ pub fn main() !void {
714 }717 }
715 }718 }
716719
717 try buf_out.flush();720 try writer.flush();
718}721}
719722
720fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {723fn usage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
721 file.writer().print(724 try w.print(
722 \\Usage: {s} /path/to/zig /path/to/linux725 \\Usage: {s} /path/to/zig /path/to/linux
723 \\Alternative Usage: zig run /path/to/git/zig/tools/generate_linux_syscalls.zig -- /path/to/zig /path/to/linux726 \\Alternative Usage: zig run /path/to/git/zig/tools/generate_linux_syscalls.zig -- /path/to/zig /path/to/linux
724 \\727 \\
725 \\Generates the list of Linux syscalls for each supported cpu arch, using the Linux development tree.728 \\Generates the list of Linux syscalls for each supported cpu arch, using the Linux development tree.
726 \\Prints to stdout Zig code which you can use to replace the file lib/std/os/linux/syscalls.zig.729 \\Prints to stdout Zig code which you can use to replace the file lib/std/os/linux/syscalls.zig.
727 \\730 \\
728 , .{arg0}) catch std.process.exit(1);731 , .{arg0});
729 std.process.exit(code);
730}732}
tools/update_clang_options.zig+22-20
...@@ -634,25 +634,25 @@ pub fn main() anyerror!void {...@@ -634,25 +634,25 @@ pub fn main() anyerror!void {
634 const allocator = arena.allocator();634 const allocator = arena.allocator();
635 const args = try std.process.argsAlloc(allocator);635 const args = try std.process.argsAlloc(allocator);
636636
637 if (args.len <= 1) {637 var stdout_buffer: [4000]u8 = undefined;
638 usageAndExit(std.io.getStdErr(), args[0], 1);638 var stdout_writer = fs.stdout().writerStreaming(&stdout_buffer);
639 }639 const stdout = &stdout_writer.interface;
640
641 if (args.len <= 1) printUsageAndExit(args[0]);
642
640 if (std.mem.eql(u8, args[1], "--help")) {643 if (std.mem.eql(u8, args[1], "--help")) {
641 usageAndExit(std.io.getStdOut(), args[0], 0);644 printUsage(stdout, args[0]) catch std.process.exit(2);
642 }645 stdout.flush() catch std.process.exit(2);
643 if (args.len < 3) {646 std.process.exit(0);
644 usageAndExit(std.io.getStdErr(), args[0], 1);
645 }647 }
646648
649 if (args.len < 3) printUsageAndExit(args[0]);
650
647 const llvm_tblgen_exe = args[1];651 const llvm_tblgen_exe = args[1];
648 if (std.mem.startsWith(u8, llvm_tblgen_exe, "-")) {652 if (std.mem.startsWith(u8, llvm_tblgen_exe, "-")) printUsageAndExit(args[0]);
649 usageAndExit(std.io.getStdErr(), args[0], 1);
650 }
651653
652 const llvm_src_root = args[2];654 const llvm_src_root = args[2];
653 if (std.mem.startsWith(u8, llvm_src_root, "-")) {655 if (std.mem.startsWith(u8, llvm_src_root, "-")) printUsageAndExit(args[0]);
654 usageAndExit(std.io.getStdErr(), args[0], 1);
655 }
656656
657 var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(allocator);657 var llvm_to_zig_cpu_features = std.StringHashMap([]const u8).init(allocator);
658658
...@@ -719,8 +719,6 @@ pub fn main() anyerror!void {...@@ -719,8 +719,6 @@ pub fn main() anyerror!void {
719 // "W" and "Wl,". So we sort this list in order of descending priority.719 // "W" and "Wl,". So we sort this list in order of descending priority.
720 std.mem.sort(*json.ObjectMap, all_objects.items, {}, objectLessThan);720 std.mem.sort(*json.ObjectMap, all_objects.items, {}, objectLessThan);
721721
722 var buffered_stdout = std.io.bufferedWriter(std.io.getStdOut().writer());
723 const stdout = buffered_stdout.writer();
724 try stdout.writeAll(722 try stdout.writeAll(
725 \\// This file is generated by tools/update_clang_options.zig.723 \\// This file is generated by tools/update_clang_options.zig.
726 \\// zig fmt: off724 \\// zig fmt: off
...@@ -815,7 +813,7 @@ pub fn main() anyerror!void {...@@ -815,7 +813,7 @@ pub fn main() anyerror!void {
815 \\813 \\
816 );814 );
817815
818 try buffered_stdout.flush();816 try stdout.flush();
819}817}
820818
821// TODO we should be able to import clang_options.zig but currently this is problematic because it will819// TODO we should be able to import clang_options.zig but currently this is problematic because it will
...@@ -966,13 +964,17 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {...@@ -966,13 +964,17 @@ fn objectLessThan(context: void, a: *json.ObjectMap, b: *json.ObjectMap) bool {
966 return std.mem.lessThan(u8, a_key, b_key);964 return std.mem.lessThan(u8, a_key, b_key);
967}965}
968966
969fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {967fn printUsageAndExit(arg0: []const u8) noreturn {
970 file.writer().print(968 printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
969 std.process.exit(1);
970}
971
972fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
973 try w.print(
971 \\Usage: {s} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project974 \\Usage: {s} /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
972 \\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project975 \\Alternative Usage: zig run /path/to/git/zig/tools/update_clang_options.zig -- /path/to/llvm-tblgen /path/to/git/llvm/llvm-project
973 \\976 \\
974 \\Prints to stdout Zig code which you can use to replace the file src/clang_options_data.zig.977 \\Prints to stdout Zig code which you can use to replace the file src/clang_options_data.zig.
975 \\978 \\
976 , .{arg0}) catch std.process.exit(1);979 , .{arg0});
977 std.process.exit(code);
978}980}
tools/update_cpu_features.zig+2-2
...@@ -2082,8 +2082,8 @@ fn processOneTarget(job: Job) void {...@@ -2082,8 +2082,8 @@ fn processOneTarget(job: Job) void {
2082}2082}
20832083
2084fn usageAndExit(arg0: []const u8, code: u8) noreturn {2084fn usageAndExit(arg0: []const u8, code: u8) noreturn {
2085 const stderr = std.io.getStdErr();2085 const stderr = std.debug.lockStderrWriter(&.{});
2086 stderr.writer().print(2086 stderr.print(
2087 \\Usage: {s} /path/to/llvm-tblgen /path/git/llvm-project /path/git/zig [zig_name filter]2087 \\Usage: {s} /path/to/llvm-tblgen /path/git/llvm-project /path/git/zig [zig_name filter]
2088 \\2088 \\
2089 \\Updates lib/std/target/<target>.zig from llvm/lib/Target/<Target>/<Target>.td .2089 \\Updates lib/std/target/<target>.zig from llvm/lib/Target/<Target>/<Target>.td .
tools/update_crc_catalog.zig+10-10
...@@ -11,14 +11,10 @@ pub fn main() anyerror!void {...@@ -11,14 +11,10 @@ pub fn main() anyerror!void {
11 const arena = arena_state.allocator();11 const arena = arena_state.allocator();
1212
13 const args = try std.process.argsAlloc(arena);13 const args = try std.process.argsAlloc(arena);
14 if (args.len <= 1) {14 if (args.len <= 1) printUsageAndExit(args[0]);
15 usageAndExit(std.io.getStdErr(), args[0], 1);
16 }
1715
18 const zig_src_root = args[1];16 const zig_src_root = args[1];
19 if (mem.startsWith(u8, zig_src_root, "-")) {17 if (mem.startsWith(u8, zig_src_root, "-")) printUsageAndExit(args[0]);
20 usageAndExit(std.io.getStdErr(), args[0], 1);
21 }
2218
23 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});19 var zig_src_dir = try fs.cwd().openDir(zig_src_root, .{});
24 defer zig_src_dir.close();20 defer zig_src_dir.close();
...@@ -193,10 +189,14 @@ pub fn main() anyerror!void {...@@ -193,10 +189,14 @@ pub fn main() anyerror!void {
193 }189 }
194}190}
195191
196fn usageAndExit(file: fs.File, arg0: []const u8, code: u8) noreturn {192fn printUsageAndExit(arg0: []const u8) noreturn {
197 file.writer().print(193 printUsage(std.debug.lockStderrWriter(&.{}), arg0) catch std.process.exit(2);
194 std.process.exit(1);
195}
196
197fn printUsage(w: *std.io.Writer, arg0: []const u8) std.io.Writer.Error!void {
198 return w.print(
198 \\Usage: {s} /path/git/zig199 \\Usage: {s} /path/git/zig
199 \\200 \\
200 , .{arg0}) catch std.process.exit(1);201 , .{arg0});
201 std.process.exit(code);
202}202}