|
1 | 1 | //! Tests for the `cargo sync-lockfile` command.
|
2 | 2 |
|
3 |
| -use cargo_test_support::registry::Package; |
4 |
| -use cargo_test_support::rustc_host; |
5 |
| -use cargo_test_support::{basic_manifest, cross_compile, project}; |
| 3 | +use cargo_test_support::project; |
6 | 4 |
|
7 | 5 | #[cargo_test]
|
8 |
| -fn no_deps() { |
9 |
| - let p = project() |
10 |
| - .file("src/main.rs", "mod a; fn main() {}") |
11 |
| - .file("src/a.rs", "") |
12 |
| - .build(); |
13 |
| - |
14 |
| - p.cargo("sync-lockfile").with_stdout("").run(); |
15 |
| -} |
16 |
| - |
17 |
| -#[cargo_test] |
18 |
| -fn sync_all_platform_dependencies_when_no_target_is_given() { |
19 |
| - if cross_compile::disabled() { |
20 |
| - return; |
21 |
| - } |
22 |
| - |
23 |
| - Package::new("d1", "1.2.3") |
24 |
| - .file("Cargo.toml", &basic_manifest("d1", "1.2.3")) |
25 |
| - .file("src/lib.rs", "") |
26 |
| - .publish(); |
27 |
| - |
28 |
| - Package::new("d2", "0.1.2") |
29 |
| - .file("Cargo.toml", &basic_manifest("d2", "0.1.2")) |
30 |
| - .file("src/lib.rs", "") |
31 |
| - .publish(); |
32 |
| - |
33 |
| - let target = cross_compile::alternate(); |
34 |
| - let host = rustc_host(); |
35 |
| - let p = project() |
36 |
| - .file( |
37 |
| - "Cargo.toml", |
38 |
| - &format!( |
39 |
| - r#" |
| 6 | +fn sync_after_generate() { |
| 7 | + let p = project().file("src/main.rs", "fn main() {}").build(); |
| 8 | + p.cargo("generate-lockfile").run(); |
| 9 | + let lock1 = p.read_lockfile(); |
| 10 | + |
| 11 | + // add a dep |
| 12 | + p.change_file( |
| 13 | + "Cargo.toml", |
| 14 | + r#" |
40 | 15 | [package]
|
41 | 16 | name = "foo"
|
42 |
| - version = "0.0.1" |
43 | 17 | authors = []
|
44 |
| -
|
45 |
| - [target.{host}.dependencies] |
46 |
| - d1 = "1.2.3" |
47 |
| -
|
48 |
| - [target.{target}.dependencies] |
49 |
| - d2 = "0.1.2" |
| 18 | + version = "0.0.2" |
50 | 19 | "#,
|
51 |
| - host = host, |
52 |
| - target = target |
53 |
| - ), |
54 |
| - ) |
55 |
| - .file("src/lib.rs", "") |
56 |
| - .build(); |
57 |
| - |
58 |
| - p.cargo("sync-lockfile") |
59 |
| - .with_stderr_contains("[DOWNLOADED] d1 v1.2.3 [..]") |
60 |
| - .with_stderr_contains("[DOWNLOADED] d2 v0.1.2 [..]") |
61 |
| - .run(); |
62 |
| -} |
63 |
| - |
64 |
| -#[cargo_test] |
65 |
| -fn sync_platform_specific_dependencies() { |
66 |
| - if cross_compile::disabled() { |
67 |
| - return; |
68 |
| - } |
69 |
| - |
70 |
| - Package::new("d1", "1.2.3") |
71 |
| - .file("Cargo.toml", &basic_manifest("d1", "1.2.3")) |
72 |
| - .file("src/lib.rs", "") |
73 |
| - .publish(); |
74 |
| - |
75 |
| - Package::new("d2", "0.1.2") |
76 |
| - .file("Cargo.toml", &basic_manifest("d2", "0.1.2")) |
77 |
| - .file("src/lib.rs", "") |
78 |
| - .publish(); |
79 |
| - |
80 |
| - let target = cross_compile::alternate(); |
81 |
| - let host = rustc_host(); |
82 |
| - let p = project() |
83 |
| - .file( |
84 |
| - "Cargo.toml", |
85 |
| - &format!( |
86 |
| - r#" |
87 |
| - [package] |
88 |
| - name = "foo" |
89 |
| - version = "0.0.1" |
90 |
| - authors = [] |
91 |
| -
|
92 |
| - [target.{host}.dependencies] |
93 |
| - d1 = "1.2.3" |
94 |
| -
|
95 |
| - [target.{target}.dependencies] |
96 |
| - d2 = "0.1.2" |
97 |
| - "#, |
98 |
| - host = host, |
99 |
| - target = target |
100 |
| - ), |
101 |
| - ) |
102 |
| - .file("src/lib.rs", "") |
103 |
| - .build(); |
104 |
| - |
105 |
| - p.cargo("sync-lockfile --target") |
106 |
| - .arg(&host) |
107 |
| - .with_stderr_contains("[DOWNLOADED] d1 v1.2.3 [..]") |
108 |
| - .with_stderr_does_not_contain("[DOWNLOADED] d2 v0.1.2 [..]") |
109 |
| - .run(); |
110 |
| - |
111 |
| - p.cargo("sync-lockfile --target") |
112 |
| - .arg(&target) |
113 |
| - .with_stderr_contains("[DOWNLOADED] d2 v0.1.2[..]") |
114 |
| - .with_stderr_does_not_contain("[DOWNLOADED] d1 v1.2.3 [..]") |
115 |
| - .run(); |
116 |
| -} |
117 |
| - |
118 |
| -#[cargo_test] |
119 |
| -fn sync_warning() { |
120 |
| - let p = project() |
121 |
| - .file( |
122 |
| - "Cargo.toml", |
123 |
| - r#" |
124 |
| - [package] |
125 |
| - name = "foo" |
126 |
| - version = "1.0.0" |
127 |
| - misspelled = "wut" |
128 |
| - "#, |
129 |
| - ) |
130 |
| - .file("src/lib.rs", "") |
131 |
| - .build(); |
132 |
| - p.cargo("sync-lockfile") |
133 |
| - .with_stderr("[WARNING] unused manifest key: package.misspelled") |
134 |
| - .run(); |
| 20 | + ); |
| 21 | + p.cargo("sync-lockfile").run(); |
| 22 | + let lock2 = p.read_lockfile(); |
| 23 | + assert_ne!(lock1, lock2); |
| 24 | + assert!(lock1.contains("0.0.1")); |
| 25 | + assert!(lock2.contains("0.0.2")); |
| 26 | + assert!(!lock1.contains("0.0.2")); |
| 27 | + assert!(!lock2.contains("0.0.1")); |
135 | 28 | }
|
0 commit comments