| ... | ... | @@ -1176,6 +1176,100 @@ pub fn addCliTests(b: *std.Build) *Step { |
| 1176 | 1176 | step.dependOn(&cleanup.step); |
| 1177 | 1177 | } |
| 1178 | 1178 | |
| 1179 | { |
| 1180 | // Test `zig build -fallow-deprecated`. |
| 1181 | |
| 1182 | const deprecated_check: std.Build.Step.Run.StdIo.Check = .{ |
| 1183 | .expect_stderr_match = "found deprecated code", |
| 1184 | }; |
| 1185 | |
| 1186 | const tmp_path = b.makeTempPath(); |
| 1187 | |
| 1188 | // create custom main.zig file containing a deprecated decl |
| 1189 | { |
| 1190 | const new_main_src = |
| 1191 | \\const bad = @deprecated(42); |
| 1192 | \\ |
| 1193 | \\pub fn main() u8 { |
| 1194 | \\ return bad; |
| 1195 | \\} |
| 1196 | \\ |
| 1197 | \\test { |
| 1198 | \\ if (bad != 42) return error.Bad; |
| 1199 | \\} |
| 1200 | ; |
| 1201 | |
| 1202 | var src_dir = std.fs.cwd().makeOpenPath(b.pathJoin(&.{ tmp_path, "src" }), .{}) catch unreachable; |
| 1203 | defer src_dir.close(); |
| 1204 | |
| 1205 | var main = src_dir.createFile("main.zig", .{}) catch unreachable; |
| 1206 | defer main.close(); |
| 1207 | |
| 1208 | main.writeAll(new_main_src) catch unreachable; |
| 1209 | } |
| 1210 | |
| 1211 | const init_exe = b.addSystemCommand(&.{ b.graph.zig_exe, "init" }); |
| 1212 | init_exe.setCwd(.{ .cwd_relative = tmp_path }); |
| 1213 | init_exe.setName("zig init"); |
| 1214 | init_exe.expectStdOutEqual(""); |
| 1215 | init_exe.expectStdErrEqual("info: created build.zig\n" ++ |
| 1216 | "info: created build.zig.zon\n" ++ |
| 1217 | "info: preserving already existing file: src" ++ s ++ "main.zig\n" ++ |
| 1218 | "info: created src" ++ s ++ "root.zig\n"); |
| 1219 | |
| 1220 | const run_test_bad = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "test", "--color", "off" }); |
| 1221 | run_test_bad.setCwd(.{ .cwd_relative = tmp_path }); |
| 1222 | run_test_bad.setName("zig build test"); |
| 1223 | run_test_bad.expectExitCode(1); |
| 1224 | run_test_bad.expectStdOutEqual(""); |
| 1225 | run_test_bad.addCheck(deprecated_check); |
| 1226 | run_test_bad.step.dependOn(&init_exe.step); |
| 1227 | |
| 1228 | const run_test = b.addSystemCommand(&.{ |
| 1229 | b.graph.zig_exe, |
| 1230 | "build", |
| 1231 | "test", |
| 1232 | "--color", |
| 1233 | "off", |
| 1234 | "-fallow-deprecated", |
| 1235 | }); |
| 1236 | run_test.setCwd(.{ .cwd_relative = tmp_path }); |
| 1237 | run_test.setName("zig build test"); |
| 1238 | run_test.expectExitCode(0); |
| 1239 | run_test.expectStdOutEqual(""); |
| 1240 | run_test.expectStdErrEqual(""); |
| 1241 | run_test.step.dependOn(&init_exe.step); |
| 1242 | |
| 1243 | const run_build_bad = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "--color", "off" }); |
| 1244 | run_build_bad.setCwd(.{ .cwd_relative = tmp_path }); |
| 1245 | run_build_bad.setName("zig build test"); |
| 1246 | run_build_bad.expectExitCode(1); |
| 1247 | run_build_bad.expectStdOutEqual(""); |
| 1248 | run_build_bad.addCheck(deprecated_check); |
| 1249 | run_build_bad.step.dependOn(&init_exe.step); |
| 1250 | |
| 1251 | const run_build = b.addSystemCommand(&.{ |
| 1252 | b.graph.zig_exe, |
| 1253 | "build", |
| 1254 | "--color", |
| 1255 | "off", |
| 1256 | "-fallow-deprecated", |
| 1257 | }); |
| 1258 | run_build.setCwd(.{ .cwd_relative = tmp_path }); |
| 1259 | run_build.setName("zig build test"); |
| 1260 | run_build.expectExitCode(0); |
| 1261 | run_build.expectStdOutEqual(""); |
| 1262 | run_build.expectStdErrEqual(""); |
| 1263 | run_build.step.dependOn(&init_exe.step); |
| 1264 | |
| 1265 | const cleanup = b.addRemoveDirTree(.{ .cwd_relative = tmp_path }); |
| 1266 | cleanup.step.dependOn(&run_test.step); |
| 1267 | cleanup.step.dependOn(&run_test_bad.step); |
| 1268 | cleanup.step.dependOn(&run_build.step); |
| 1269 | cleanup.step.dependOn(&run_build_bad.step); |
| 1270 | |
| 1271 | step.dependOn(&cleanup.step); |
| 1272 | } |
| 1179 | 1273 | // Test Godbolt API |
| 1180 | 1274 | if (builtin.os.tag == .linux and builtin.cpu.arch == .x86_64) { |
| 1181 | 1275 | const tmp_path = b.makeTempPath(); |