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(
26312631 if (check_mode) {
26322632 const anything_changed = try std.zig.render(fmt.gpa, io.null_out_stream, tree);
26332633 if (anything_changed) {
2634 // TODO this should output to stdout instead of stderr.
2635 std.debug.print("{}\n", .{file_path});
2634 const stdout = io.getStdOut().writer();
2635 try stdout.print("{}\n", .{file_path});
26362636 fmt.any_error = true;
26372637 }
26382638 } else {
......@@ -2649,8 +2649,8 @@ fn fmtPathFile(
26492649
26502650 try af.file.writeAll(fmt.out_buffer.items);
26512651 try af.finish();
2652 // TODO this should output to stdout instead of stderr.
2653 std.debug.print("{}\n", .{file_path});
2652 const stdout = io.getStdOut().writer();
2653 try stdout.print("{}\n", .{file_path});
26542654 }
26552655}
26562656
test/cli.zig+5-5
......@@ -160,18 +160,18 @@ fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void {
160160
161161 const run_result1 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path });
162162 // stderr should be file path + \n
163 testing.expect(std.mem.startsWith(u8, run_result1.stderr, 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');
163 testing.expect(std.mem.startsWith(u8, run_result1.stdout, fmt1_zig_path));
164 testing.expect(run_result1.stdout.len == fmt1_zig_path.len + 1 and run_result1.stdout[run_result1.stdout.len - 1] == '\n');
165165
166166 const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" });
167167 try fs.cwd().writeFile(fmt2_zig_path, unformatted_code);
168168
169169 const run_result2 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
170170 // 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));
172 testing.expect(run_result2.stderr.len == fmt2_zig_path.len + 1 and run_result2.stderr[run_result2.stderr.len - 1] == '\n');
171 testing.expect(std.mem.startsWith(u8, run_result2.stdout, fmt2_zig_path));
172 testing.expect(run_result2.stdout.len == fmt2_zig_path.len + 1 and run_result2.stdout[run_result2.stdout.len - 1] == '\n');
173173
174174 const run_result3 = try exec(dir_path, true, &[_][]const u8{ zig_exe, "fmt", dir_path });
175175 // 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);
177177}