Skip to content

Commit 6d0825d

Browse files
committed
test: migrate lockfile_compat to snapbox
1 parent 02c0f7e commit 6d0825d

File tree

1 file changed

+66
-89
lines changed

1 file changed

+66
-89
lines changed

tests/testsuite/lockfile_compat.rs

Lines changed: 66 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Tests for supporting older versions of the Cargo.lock file format.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::compare::assert_e2e;
64
use cargo_test_support::git;
75
use cargo_test_support::registry::Package;
@@ -236,10 +234,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
236234

237235
p.cargo("check")
238236
.with_status(101)
239-
.with_stderr(
240-
"\
241-
[UPDATING] `[..]` index
242-
error: checksum for `bar v0.1.0` changed between lock files
237+
.with_stderr_data(str![[r#"
238+
[UPDATING] `dummy-registry` index
239+
[ERROR] checksum for `bar v0.1.0` changed between lock files
243240
244241
this could be indicative of a few possible errors:
245242
@@ -249,8 +246,8 @@ this could be indicative of a few possible errors:
249246
250247
unable to verify that `bar v0.1.0` is the same as when the lockfile was generated
251248
252-
",
253-
)
249+
250+
"#]])
254251
.run();
255252
}
256253

@@ -297,25 +294,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
297294
);
298295
let p = p.build();
299296

300-
p.cargo("fetch")
301-
.with_status(101)
302-
.with_stderr(
303-
"\
304-
[UPDATING] `[..]` index
305-
error: checksum for `bar v0.1.0` was not previously calculated, but a checksum \
306-
could now be calculated
297+
p.cargo("fetch").with_status(101).with_stderr_data(str![[r#"
298+
[UPDATING] `dummy-registry` index
299+
[ERROR] checksum for `bar v0.1.0` was not previously calculated, but a checksum could now be calculated
307300
308301
this could be indicative of a few possible situations:
309302
310-
* the source `[..]` did not previously support checksums,
303+
* the source `registry `crates-io`` did not previously support checksums,
311304
but was replaced with one that does
312305
* newer Cargo implementations know how to checksum this source, but this
313306
older implementation does not
314307
* the lock file is corrupt
315308
316-
",
317-
)
318-
.run();
309+
310+
"#]]).run();
319311
}
320312

321313
// If the checksum is listed in the lock file yet we cannot calculate it (e.g.,
@@ -370,25 +362,20 @@ source = "git+{0}"
370362

371363
let p = p.build();
372364

373-
p.cargo("fetch")
374-
.with_status(101)
375-
.with_stderr(
376-
"\
377-
[UPDATING] git repository `[..]`
378-
error: checksum for `bar v0.1.0 ([..])` could not be calculated, but a \
379-
checksum is listed in the existing lock file[..]
365+
p.cargo("fetch").with_status(101).with_stderr_data(str![[r#"
366+
[UPDATING] git repository `[ROOTURL]/bar`
367+
[ERROR] checksum for `bar v0.1.0 ([ROOTURL]/bar)` could not be calculated, but a checksum is listed in the existing lock file
380368
381369
this could be indicative of a few possible situations:
382370
383-
* the source `[..]` supports checksums,
371+
* the source `[ROOTURL]/bar` supports checksums,
384372
but was replaced with one that doesn't
385373
* the lock file is corrupt
386374
387-
unable to verify that `bar v0.1.0 ([..])` is the same as when the lockfile was generated
375+
unable to verify that `bar v0.1.0 ([ROOTURL]/bar)` is the same as when the lockfile was generated
388376
389-
",
390-
)
391-
.run();
377+
378+
"#]]).run();
392379
}
393380

394381
#[cargo_test]
@@ -527,14 +514,12 @@ fn locked_correct_error() {
527514

528515
p.cargo("check --locked")
529516
.with_status(101)
530-
.with_stderr(
531-
"\
532-
[UPDATING] `[..]` index
533-
error: the lock file [CWD]/Cargo.lock needs to be updated but --locked was passed to prevent this
534-
If you want to try to generate the lock file without accessing the network, \
535-
remove the --locked flag and use --offline instead.
536-
",
537-
)
517+
.with_stderr_data(str![[r#"
518+
[UPDATING] `dummy-registry` index
519+
[ERROR] the lock file [ROOT]/foo/Cargo.lock needs to be updated but --locked was passed to prevent this
520+
If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.
521+
522+
"#]])
538523
.run();
539524
}
540525

@@ -731,18 +716,13 @@ fn lock_from_the_future() {
731716
.file("Cargo.lock", "version = 10000000")
732717
.build();
733718

734-
p.cargo("fetch")
735-
.with_stderr(
736-
"\
737-
error: failed to parse lock file at: [..]
719+
p.cargo("fetch").with_stderr_data(str![[r#"
720+
[ERROR] failed to parse lock file at: [ROOT]/foo/Cargo.lock
738721
739722
Caused by:
740-
lock file version `10000000` was found, but this version of Cargo does not \
741-
understand this lock file, perhaps Cargo needs to be updated?
742-
",
743-
)
744-
.with_status(101)
745-
.run();
723+
lock file version `10000000` was found, but this version of Cargo does not understand this lock file, perhaps Cargo needs to be updated?
724+
725+
"#]]).with_status(101).run();
746726
}
747727

748728
#[cargo_test]
@@ -904,16 +884,15 @@ dependencies = [
904884
.build();
905885
p.cargo("check")
906886
.with_status(101)
907-
.with_stderr(
908-
"\
909-
[..]
910-
[ERROR] failed to select a version for the requirement `bar = \"*\"` (locked to 0.1.0)
887+
.with_stderr_data(str![[r#"
888+
[UPDATING] `dummy-registry` index
889+
[ERROR] failed to select a version for the requirement `bar = "*"` (locked to 0.1.0)
911890
candidate versions found which didn't match: 0.0.1
912891
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
913-
required by package `test v0.0.0 ([..])`
892+
required by package `test v0.0.0 ([ROOT]/foo)`
914893
perhaps a crate was updated and forgotten to be re-vendored?
915-
",
916-
)
894+
895+
"#]])
917896
.run();
918897
}
919898

@@ -935,31 +914,25 @@ fn next_version_is_always_unstable() {
935914
.file("Cargo.lock", "version = 5")
936915
.build();
937916

938-
p.cargo("fetch")
939-
.with_status(101)
940-
.with_stderr(
941-
"\
942-
error: failed to parse lock file at: [CWD]/Cargo.lock
917+
p.cargo("fetch").with_status(101).with_stderr_data(str![[r#"
918+
[ERROR] failed to parse lock file at: [ROOT]/foo/Cargo.lock
943919
944920
Caused by:
945-
lock file version `5` was found, but this version of Cargo does not \
946-
understand this lock file, perhaps Cargo needs to be updated?
947-
",
948-
)
949-
.run();
921+
lock file version `5` was found, but this version of Cargo does not understand this lock file, perhaps Cargo needs to be updated?
922+
923+
"#]]).run();
950924

951925
// On nightly, let the user know about the `-Z` flag.
952926
p.cargo("fetch")
953927
.masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"])
954928
.with_status(101)
955-
.with_stderr(
956-
"\
957-
error: failed to parse lock file at: [CWD]/Cargo.lock
929+
.with_stderr_data(str![[r#"
930+
[ERROR] failed to parse lock file at: [ROOT]/foo/Cargo.lock
958931
959932
Caused by:
960933
lock file version `5` requires `-Znext-lockfile-bump`
961-
",
962-
)
934+
935+
"#]])
963936
.run();
964937
}
965938

@@ -1062,15 +1035,15 @@ dependencies = [
10621035
.build();
10631036

10641037
p.cargo("check")
1065-
.with_stderr(format!(
1038+
.with_stderr_data(format!(
10661039
"\
1067-
[UPDATING] git repository `{url}`
1040+
[UPDATING] git repository `[ROOTURL]/dep1`
10681041
[LOCKING] 2 packages to latest compatible versions
1069-
[ADDING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..])
1070-
[ADDING] foo v0.0.1 ([CWD])
1071-
[CHECKING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..])
1072-
[CHECKING] foo v0.0.1 ([CWD])
1073-
[FINISHED] `dev` profile [..]
1042+
[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1043+
[ADDING] foo v0.0.1 ([ROOT]/foo)
1044+
[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1045+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
1046+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10741047
"
10751048
))
10761049
.run();
@@ -1082,10 +1055,10 @@ dependencies = [
10821055
// was URL-encoded. Therefore Cargo thinks they are from different source
10831056
// and clones the repository again.
10841057
p.cargo("check")
1085-
.with_stderr(format!(
1058+
.with_stderr_data(format!(
10861059
"\
1087-
[UPDATING] git repository `{url}`
1088-
[FINISHED] `dev` profile [..]
1060+
[UPDATING] git repository `[ROOTURL]/dep1`
1061+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
10891062
"
10901063
))
10911064
.run();
@@ -1158,15 +1131,15 @@ dependencies = [
11581131
.build();
11591132

11601133
p.cargo("check")
1161-
.with_stderr(format!(
1134+
.with_stderr_data(format!(
11621135
"\
1163-
[UPDATING] git repository `{url}`
1136+
[UPDATING] git repository `[ROOTURL]/dep1`
11641137
[LOCKING] 2 packages to latest compatible versions
1165-
[ADDING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..])
1166-
[ADDING] foo v0.0.1 ([CWD])
1167-
[CHECKING] dep1 v0.5.0 ({url}?{ref_kind}={git_ref}#[..])
1168-
[CHECKING] foo v0.0.1 ([CWD])
1169-
[FINISHED] `dev` profile [..]
1138+
[ADDING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1139+
[ADDING] foo v0.0.1 ([ROOT]/foo)
1140+
[CHECKING] dep1 v0.5.0 ([ROOTURL]/dep1?{ref_kind}={git_ref}#[..])
1141+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
1142+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
11701143
"
11711144
))
11721145
.run();
@@ -1177,7 +1150,11 @@ dependencies = [
11771150
// Unlike v3_and_git_url_encoded, v4 encodes URL parameters so no git
11781151
// repository re-clone happen.
11791152
p.cargo("check")
1180-
.with_stderr("[FINISHED] `dev` profile [..]")
1153+
.with_stderr_data(
1154+
"\
1155+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1156+
",
1157+
)
11811158
.run();
11821159
}
11831160

0 commit comments

Comments
 (0)