| ... | @@ -34,6 +34,7 @@ pub fn main() !void { | ... | @@ -34,6 +34,7 @@ pub fn main() !void { |
| 34 | testZigInitExe, | 34 | testZigInitExe, |
| 35 | testGodboltApi, | 35 | testGodboltApi, |
| 36 | testMissingOutputPath, | 36 | testMissingOutputPath, |
| | 37 | testZigFmt, |
| 37 | }; | 38 | }; |
| 38 | for (test_fns) |testFn| { | 39 | for (test_fns) |testFn| { |
| 39 | try fs.cwd().deleteTree(dir_path); | 40 | try fs.cwd().deleteTree(dir_path); |
| ... | @@ -143,3 +144,29 @@ fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void { | ... | @@ -143,3 +144,29 @@ fn testMissingOutputPath(zig_exe: []const u8, dir_path: []const u8) !void { |
| 143 | zig_exe, "build-exe", source_path, "--output-dir", output_path, | 144 | zig_exe, "build-exe", source_path, "--output-dir", output_path, |
| 144 | }); | 145 | }); |
| 145 | } | 146 | } |
| | 147 | |
| | 148 | fn testZigFmt(zig_exe: []const u8, dir_path: []const u8) !void { |
| | 149 | _ = try exec(dir_path, &[_][]const u8{ zig_exe, "init-exe" }); |
| | 150 | |
| | 151 | const unformatted_code = |
| | 152 | \\fn square(num: i32) i32 { |
| | 153 | \\return num * num; |
| | 154 | \\} |
| | 155 | ; |
| | 156 | |
| | 157 | const fmt1_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt1.zig" }); |
| | 158 | try fs.cwd().writeFile(fmt1_zig_path, unformatted_code); |
| | 159 | |
| | 160 | const run_result1 = try exec(dir_path, &[_][]const u8{ zig_exe, "fmt", fmt1_zig_path }); |
| | 161 | // stderr should be file path + \n |
| | 162 | testing.expect(std.mem.startsWith(u8, run_result1.stderr, fmt1_zig_path)); |
| | 163 | testing.expect(run_result1.stderr.len == fmt1_zig_path.len + 1 and run_result1.stderr[run_result1.stderr.len - 1] == '\n'); |
| | 164 | |
| | 165 | const fmt2_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "fmt2.zig" }); |
| | 166 | try fs.cwd().writeFile(fmt2_zig_path, unformatted_code); |
| | 167 | |
| | 168 | const run_result2 = try exec(dir_path, &[_][]const u8{ zig_exe, "fmt", dir_path }); |
| | 169 | // running it on the dir, only the new file should be changed |
| | 170 | testing.expect(std.mem.startsWith(u8, run_result2.stderr, fmt2_zig_path)); |
| | 171 | testing.expect(run_result2.stderr.len == fmt2_zig_path.len + 1 and run_result2.stderr[run_result2.stderr.len - 1] == '\n'); |
| | 172 | } |