mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
zig fmt: write modified files to stdout not stderr
This commit is contained in:
parent
8364417c8f
commit
0e4c3934a0
2 changed files with 9 additions and 9 deletions
|
|
@ -2631,8 +2631,8 @@ fn fmtPathFile(
|
|||
if (check_mode) {
|
||||
const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree);
|
||||
if (anything_changed) {
|
||||
// TODO this should output to stdout instead of stderr.
|
||||
std.debug.print("{}\n", .{file_path});
|
||||
const stdout = io.getStdOut().writer();
|
||||
try stdout.print("{}\n", .{file_path});
|
||||
fmt.any_error = true;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -2649,8 +2649,8 @@ fn fmtPathFile(
|
|||
|
||||
try af.file.writeAll(fmt.out_buffer.items);
|
||||
try af.finish();
|
||||
// TODO this should output to stdout instead of stderr.
|
||||
std.debug.print("{}\n", .{file_path});
|
||||
const stdout = io.getStdOut().writer();
|
||||
try stdout.print("{}\n", .{file_path});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
10
test/cli.zig
10
test/cli.zig
|
|
@ -160,18 +160,18 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
|
|||
|
||||
const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
|
||||
// stderr should be file path + \n
|
||||
testing.expect(std.mem.startsWith(u8, run_result1.stderr, fmt1_zig_path));
|
||||
testing.expect(run_result1.stderr.len == fmt1_zig_path.len + 1 and run_result1.stderr[run_result1.stderr.len - 1] == '\n');
|
||||
testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
|
||||
testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
|
||||
|
||||
const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
|
||||
try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
|
||||
|
||||
const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
|
||||
// running it on the dir, only the new file should be changed
|
||||
testing.expect(std.mem.startsWith(u8, run_result2.stderr, fmt2_zig_path));
|
||||
testing.expect(run_result2.stderr.len == fmt2_zig_path.len + 1 and run_result2.stderr[run_result2.stderr.len - 1] == '\n');
|
||||
testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
|
||||
testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
|
||||
|
||||
const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
|
||||
// both files have been formatted, nothing should change now
|
||||
testing.expect(run_result3.stderr.len == 0);
|
||||
testing.expect(run_result3.stdout.len == 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue