Skip to content

Commit 80abaf4

Browse files
authored
Copy cargo clean target-dir validation tests to clean_new_layout.rs (#16878)
### What does this PR try to resolve? #16712 added some additional tests to `clean.rs` but did not add them to `clean_new_layout.rs` (which mirrors `clean.rs` with `-Zbuild-dir-new-layout` enabled) While these tests do not depend on the new build-dir layout, #16807 renames `clean.rs` to `clean_legacy_layout.rs` and `clean_new_layout.rs` to `clean.rs`. Having the tests be in both makes the switch easier and results in less diffs. I pulled this out into its own PR as the stabilization has grown pretty large. ### How to test and review this PR? `cargo test clean`
2 parents b54fe55 + 6b0724a commit 80abaf4

1 file changed

Lines changed: 267 additions & 0 deletions

File tree

tests/testsuite/clean_new_layout.rs

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,3 +1075,270 @@ fn quiet_does_not_show_summary() {
10751075
.masquerade_as_nightly_cargo(&["new build-dir layout"])
10761076
.run();
10771077
}
1078+
1079+
#[cargo_test]
1080+
fn explicit_target_dir_tag_not_present() {
1081+
// invalid target dir explicitly specified via --target-dir cli arg
1082+
1083+
let p = project()
1084+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1085+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1086+
.file("bar/.keep", "")
1087+
.build();
1088+
1089+
p.cargo("clean --target-dir bar")
1090+
.arg("-Zbuild-dir-new-layout")
1091+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1092+
.with_stdout_data("")
1093+
.with_stderr_data(str![[r#"
1094+
[ERROR] cannot clean `[ROOT]/foo/bar`: missing or invalid `CACHEDIR.TAG` file
1095+
|
1096+
= [NOTE] cleaning has been aborted to prevent accidental deletion of unrelated files
1097+
1098+
"#]])
1099+
.with_status(101)
1100+
.run();
1101+
}
1102+
1103+
#[cargo_test]
1104+
fn explicit_target_dir_tag_invalid_signature() {
1105+
let p = project()
1106+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1107+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1108+
.file("bar/CACHEDIR.TAG", "Signature: 1234")
1109+
.build();
1110+
1111+
p.cargo("clean --target-dir bar")
1112+
.arg("-Zbuild-dir-new-layout")
1113+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1114+
.with_stdout_data("")
1115+
.with_stderr_data(str![[r#"
1116+
[ERROR] cannot clean `[ROOT]/foo/bar`: invalid signature in `CACHEDIR.TAG` file
1117+
|
1118+
= [NOTE] cleaning has been aborted to prevent accidental deletion of unrelated files
1119+
1120+
"#]])
1121+
.with_status(101)
1122+
.run();
1123+
}
1124+
1125+
#[cargo_test]
1126+
fn explicit_target_dir_tag_symlink() {
1127+
let p = project()
1128+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1129+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1130+
.file(
1131+
"src/CACHEDIR.TAG",
1132+
"Signature: 8a477f597d28d172789f06886806bc55",
1133+
)
1134+
.symlink("src/CACHEDIR.TAG", "bar/CACHEDIR.TAG")
1135+
.build();
1136+
1137+
p.cargo("clean --target-dir bar")
1138+
.arg("-Zbuild-dir-new-layout")
1139+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1140+
.with_stdout_data("")
1141+
.with_stderr_data(str![[r#"
1142+
[ERROR] cannot clean `[ROOT]/foo/bar`: expect `CACHEDIR.TAG` to be a regular file, got a symlink
1143+
|
1144+
= [NOTE] cleaning has been aborted to prevent accidental deletion of unrelated files
1145+
1146+
"#]])
1147+
.with_status(101)
1148+
.run();
1149+
}
1150+
1151+
#[cargo_test]
1152+
fn explicit_target_dir_tag_valid() {
1153+
let p = project()
1154+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1155+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1156+
.file(
1157+
"bar/CACHEDIR.TAG",
1158+
"Signature: 8a477f597d28d172789f06886806bc55",
1159+
)
1160+
.build();
1161+
1162+
p.cargo("clean --target-dir bar")
1163+
.arg("-Zbuild-dir-new-layout")
1164+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1165+
.run();
1166+
}
1167+
1168+
#[cargo_test]
1169+
fn env_target_dir_tag_not_present() {
1170+
// invalid target dir specified via env var
1171+
1172+
let p = project()
1173+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1174+
.file("bar/.keep", "")
1175+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1176+
.build();
1177+
1178+
p.cargo("clean")
1179+
.arg("-Zbuild-dir-new-layout")
1180+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1181+
.env("CARGO_TARGET_DIR", "bar")
1182+
.with_stderr_data(str![[r#"
1183+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
1184+
1185+
"#]])
1186+
.run();
1187+
}
1188+
1189+
#[cargo_test]
1190+
fn env_target_dir_tag_invalid_signature() {
1191+
let p = project()
1192+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1193+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1194+
.file("bar/CACHEDIR.TAG", "Signature: 1234")
1195+
.build();
1196+
1197+
p.cargo("clean")
1198+
.arg("-Zbuild-dir-new-layout")
1199+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1200+
.env("CARGO_TARGET_DIR", "bar")
1201+
.with_stderr_data(str![[r#"
1202+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
1203+
1204+
"#]])
1205+
.run();
1206+
}
1207+
1208+
#[cargo_test]
1209+
fn env_target_dir_tag_symlink() {
1210+
let p = project()
1211+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1212+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1213+
.file(
1214+
"src/CACHEDIR.TAG",
1215+
"Signature: 8a477f597d28d172789f06886806bc55",
1216+
)
1217+
.symlink("src/CACHEDIR.TAG", "bar/CACHEDIR.TAG")
1218+
.build();
1219+
1220+
p.cargo("clean")
1221+
.arg("-Zbuild-dir-new-layout")
1222+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1223+
.env("CARGO_TARGET_DIR", "bar")
1224+
.with_stderr_data(str![[r#"
1225+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
1226+
1227+
"#]])
1228+
.run();
1229+
}
1230+
1231+
#[cargo_test]
1232+
fn env_target_dir_tag_valid() {
1233+
let p = project()
1234+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1235+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1236+
.file(
1237+
"bar/CACHEDIR.TAG",
1238+
"Signature: 8a477f597d28d172789f06886806bc55",
1239+
)
1240+
.build();
1241+
1242+
p.cargo("clean")
1243+
.arg("-Zbuild-dir-new-layout")
1244+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1245+
.env("CARGO_TARGET_DIR", "bar")
1246+
.run();
1247+
}
1248+
1249+
#[cargo_test]
1250+
fn config_target_dir_tag_not_present() {
1251+
// invalid target dir specified via build config
1252+
1253+
let p = project()
1254+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1255+
.file("bar/.keep", "")
1256+
.file("src/foo.rs", "")
1257+
.file(
1258+
".cargo/config.toml",
1259+
"[build]
1260+
target-dir = 'bar'",
1261+
)
1262+
.build();
1263+
1264+
p.cargo("clean")
1265+
.arg("-Zbuild-dir-new-layout")
1266+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1267+
.with_stderr_data(str![[r#"
1268+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
1269+
1270+
"#]])
1271+
.run();
1272+
}
1273+
1274+
#[cargo_test]
1275+
fn config_target_dir_tag_invalid_signature() {
1276+
let p = project()
1277+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1278+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1279+
.file("bar/CACHEDIR.TAG", "Signature: 1234")
1280+
.file(
1281+
".cargo/config.toml",
1282+
"[build]
1283+
target-dir = 'bar'",
1284+
)
1285+
.build();
1286+
1287+
p.cargo("clean")
1288+
.arg("-Zbuild-dir-new-layout")
1289+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1290+
.with_stderr_data(str![[r#"
1291+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
1292+
1293+
"#]])
1294+
.run();
1295+
}
1296+
1297+
#[cargo_test]
1298+
fn config_target_dir_tag_symlink() {
1299+
let p = project()
1300+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1301+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1302+
.file(
1303+
"src/CACHEDIR.TAG",
1304+
"Signature: 8a477f597d28d172789f06886806bc55",
1305+
)
1306+
.symlink("src/CACHEDIR.TAG", "bar/CACHEDIR.TAG")
1307+
.file(
1308+
".cargo/config.toml",
1309+
"[build]
1310+
target-dir = 'bar'",
1311+
)
1312+
.build();
1313+
1314+
p.cargo("clean")
1315+
.arg("-Zbuild-dir-new-layout")
1316+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1317+
.with_stderr_data(str![[r#"
1318+
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total
1319+
1320+
"#]])
1321+
.run();
1322+
}
1323+
1324+
#[cargo_test]
1325+
fn config_target_dir_tag_valid() {
1326+
let p = project()
1327+
.file("Cargo.toml", &basic_bin_manifest("foo"))
1328+
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
1329+
.file(
1330+
"bar/CACHEDIR.TAG",
1331+
"Signature: 8a477f597d28d172789f06886806bc55",
1332+
)
1333+
.file(
1334+
".cargo/config.toml",
1335+
"[build]
1336+
target-dir = 'bar'",
1337+
)
1338+
.build();
1339+
1340+
p.cargo("clean")
1341+
.arg("-Zbuild-dir-new-layout")
1342+
.masquerade_as_nightly_cargo(&["new build-dir layout"])
1343+
.run();
1344+
}

0 commit comments

Comments
 (0)