1 //! Tests for --unit-graph option.
2 
3 use cargo_test_support::project;
4 use cargo_test_support::registry::Package;
5 
6 #[cargo_test]
gated()7 fn gated() {
8     let p = project().file("src/lib.rs", "").build();
9     p.cargo("build --unit-graph")
10         .with_status(101)
11         .with_stderr(
12             "\
13 [ERROR] the `--unit-graph` flag is unstable[..]
14 See [..]
15 See [..]
16 ",
17         )
18         .run();
19 }
20 
21 #[cargo_test]
simple()22 fn simple() {
23     Package::new("a", "1.0.0")
24         .dep("b", "1.0")
25         .feature("feata", &["b/featb"])
26         .publish();
27     Package::new("b", "1.0.0")
28         .dep("c", "1.0")
29         .feature("featb", &["c/featc"])
30         .publish();
31     Package::new("c", "1.0.0").feature("featc", &[]).publish();
32 
33     let p = project()
34         .file(
35             "Cargo.toml",
36             r#"
37             [package]
38             name = "foo"
39             version = "0.1.0"
40 
41             [dependencies]
42             a = "1.0"
43             "#,
44         )
45         .file("src/lib.rs", "")
46         .build();
47 
48     p.cargo("build --features a/feata --unit-graph -Zunstable-options")
49         .masquerade_as_nightly_cargo()
50         .with_json(
51             r#"{
52               "roots": [
53                 3
54               ],
55               "units": [
56                 {
57                   "dependencies": [
58                     {
59                       "extern_crate_name": "b",
60                       "index": 1,
61                       "noprelude": false,
62                       "public": false
63                     }
64                   ],
65                   "features": [
66                     "feata"
67                   ],
68                   "mode": "build",
69                   "pkg_id": "a 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
70                   "platform": null,
71                   "profile": {
72                     "codegen_backend": null,
73                     "codegen_units": null,
74                     "debug_assertions": true,
75                     "debuginfo": 2,
76                     "incremental": false,
77                     "lto": "false",
78                     "name": "dev",
79                     "opt_level": "0",
80                     "overflow_checks": true,
81                     "panic": "unwind",
82                     "rpath": false,
83                     "split_debuginfo": "{...}",
84                     "strip": "none"
85                   },
86                   "target": {
87                     "crate_types": [
88                       "lib"
89                     ],
90                     "doc": true,
91                     "doctest": true,
92                     "edition": "2015",
93                     "kind": [
94                       "lib"
95                     ],
96                     "name": "a",
97                     "src_path": "[..]/a-1.0.0/src/lib.rs",
98                     "test": true
99                   }
100                 },
101                 {
102                   "dependencies": [
103                     {
104                       "extern_crate_name": "c",
105                       "index": 2,
106                       "noprelude": false,
107                       "public": false
108                     }
109                   ],
110                   "features": [
111                     "featb"
112                   ],
113                   "mode": "build",
114                   "pkg_id": "b 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
115                   "platform": null,
116                   "profile": {
117                     "codegen_backend": null,
118                     "codegen_units": null,
119                     "debug_assertions": true,
120                     "debuginfo": 2,
121                     "incremental": false,
122                     "lto": "false",
123                     "name": "dev",
124                     "opt_level": "0",
125                     "overflow_checks": true,
126                     "panic": "unwind",
127                     "rpath": false,
128                     "split_debuginfo": "{...}",
129                     "strip": "none"
130                   },
131                   "target": {
132                     "crate_types": [
133                       "lib"
134                     ],
135                     "doc": true,
136                     "doctest": true,
137                     "edition": "2015",
138                     "kind": [
139                       "lib"
140                     ],
141                     "name": "b",
142                     "src_path": "[..]/b-1.0.0/src/lib.rs",
143                     "test": true
144                   }
145                 },
146                 {
147                   "dependencies": [],
148                   "features": [
149                     "featc"
150                   ],
151                   "mode": "build",
152                   "pkg_id": "c 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
153                   "platform": null,
154                   "profile": {
155                     "codegen_backend": null,
156                     "codegen_units": null,
157                     "debug_assertions": true,
158                     "debuginfo": 2,
159                     "incremental": false,
160                     "lto": "false",
161                     "name": "dev",
162                     "opt_level": "0",
163                     "overflow_checks": true,
164                     "panic": "unwind",
165                     "rpath": false,
166                     "split_debuginfo": "{...}",
167                     "strip": "none"
168                   },
169                   "target": {
170                     "crate_types": [
171                       "lib"
172                     ],
173                     "doc": true,
174                     "doctest": true,
175                     "edition": "2015",
176                     "kind": [
177                       "lib"
178                     ],
179                     "name": "c",
180                     "src_path": "[..]/c-1.0.0/src/lib.rs",
181                     "test": true
182                   }
183                 },
184                 {
185                   "dependencies": [
186                     {
187                       "extern_crate_name": "a",
188                       "index": 0,
189                       "noprelude": false,
190                       "public": false
191                     }
192                   ],
193                   "features": [],
194                   "mode": "build",
195                   "pkg_id": "foo 0.1.0 (path+file://[..]/foo)",
196                   "platform": null,
197                   "profile": {
198                     "codegen_backend": null,
199                     "codegen_units": null,
200                     "debug_assertions": true,
201                     "debuginfo": 2,
202                     "incremental": false,
203                     "lto": "false",
204                     "name": "dev",
205                     "opt_level": "0",
206                     "overflow_checks": true,
207                     "panic": "unwind",
208                     "rpath": false,
209                     "split_debuginfo": "{...}",
210                     "strip": "none"
211                   },
212                   "target": {
213                     "crate_types": [
214                       "lib"
215                     ],
216                     "doc": true,
217                     "doctest": true,
218                     "edition": "2015",
219                     "kind": [
220                       "lib"
221                     ],
222                     "name": "foo",
223                     "src_path": "[..]/foo/src/lib.rs",
224                     "test": true
225                   }
226                 }
227               ],
228               "version": 1
229             }
230             "#,
231         )
232         .run();
233 }
234