authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-10-14 16:20:20+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-16 20:23:18-04:00
log0e4c3934a02cda80a72a730593ece41c7fa8026a
tree923d6b37f0000bb47e2b0f004d8d38798172c4f3
parent8364417c8fead9f617a4c1a83af0c6401a1c4240

zig fmt: write modified files to stdout not stderr


2 files changed, 9 insertions(+), 9 deletions(-)

src/main.zig+4-4
...@@ -2631,8 +2631,8 @@ fn fmtPathFile(...@@ -2631,8 +2631,8 @@ fn fmtPathFile(
2631 if (check_mode) {2631 if (check_mode) {
2632 const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree);2632 const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree);
2633 if (anything_changed) {2633 if (anything_changed) {
2634 // TODO this should output to stdout instead of stderr.2634 const stdout = io.getStdOut().writer();
2635 std.debug.print("{}\n", .{file_path});2635 try stdout.print("{}\n", .{file_path});
2636 fmt.any_error = true;2636 fmt.any_error = true;
2637 }2637 }
2638 } else {2638 } else {
...@@ -2649,8 +2649,8 @@ fn fmtPathFile(...@@ -2649,8 +2649,8 @@ fn fmtPathFile(
26492649
2650 try af.file.writeAll(fmt.out_buffer.items);2650 try af.file.writeAll(fmt.out_buffer.items);
2651 try af.finish();2651 try af.finish();
2652 // TODO this should output to stdout instead of stderr.2652 const stdout = io.getStdOut().writer();
2653 std.debug.print("{}\n", .{file_path});2653 try stdout.print("{}\n", .{file_path});
2654 }2654 }
2655}2655}
26562656
test/cli.zig+5-5
...@@ -160,18 +160,18 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {...@@ -160,18 +160,18 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
160160
161 const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });161 const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
162 // stderr should be file path + \n162 // stderr should be file path + \n
163 testing.expect(std.mem.startsWith(u8, run_result1.stderr, fmt1_zig_path));163 testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
164 testing.expect(run_result1.stderr.len == fmt1_zig_path.len + 1 and run_result1.stderr[run_result1.stderr.len - 1] == '\n');164 testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
165165
166 const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });166 const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
167 try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);167 try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
168168
169 const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });169 const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
170 // running it on the dir, only the new file should be changed170 // running it on the dir, only the new file should be changed
171 testing.expect(std.mem.startsWith(u8, run_result2.stderr, fmt2_zig_path));171 testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
172 testing.expect(run_result2.stderr.len == fmt2_zig_path.len + 1 and run_result2.stderr[run_result2.stderr.len - 1] == '\n');172 testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
173173
174 const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });174 const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
175 // both files have been formatted, nothing should change now175 // both files have been formatted, nothing should change now
176 testing.expect(run_result3.stderr.len == 0);176 testing.expect(run_result3.stdout.len == 0);
177}177}