]> git.lizzy.rs Git - rust.git/blob - crates/project-model/src/tests.rs
ddfea0ce4c4f1af0f188cdb83b984790a7802342
[rust.git] / crates / project-model / src / tests.rs
1 use std::{
2     ops::Deref,
3     path::{Path, PathBuf},
4 };
5
6 use base_db::{CrateGraph, FileId};
7 use cfg::{CfgAtom, CfgDiff};
8 use expect_test::{expect, Expect};
9 use paths::{AbsPath, AbsPathBuf};
10 use serde::de::DeserializeOwned;
11
12 use crate::{
13     CargoWorkspace, CfgOverrides, ProjectJson, ProjectJsonData, ProjectWorkspace, Sysroot,
14     WorkspaceBuildScripts,
15 };
16
17 fn load_cargo(file: &str) -> CrateGraph {
18     load_cargo_with_overrides(file, CfgOverrides::default())
19 }
20
21 fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGraph {
22     let meta = get_test_json_file(file);
23     let cargo_workspace = CargoWorkspace::new(meta);
24     let project_workspace = ProjectWorkspace::Cargo {
25         cargo: cargo_workspace,
26         build_scripts: WorkspaceBuildScripts::default(),
27         sysroot: None,
28         rustc: None,
29         rustc_cfg: Vec::new(),
30         cfg_overrides,
31     };
32     to_crate_graph(project_workspace)
33 }
34
35 fn load_rust_project(file: &str) -> CrateGraph {
36     let data = get_test_json_file(file);
37     let project = rooted_project_json(data);
38     let sysroot = Some(get_fake_sysroot());
39     let project_workspace = ProjectWorkspace::Json { project, sysroot, rustc_cfg: Vec::new() };
40     to_crate_graph(project_workspace)
41 }
42
43 fn get_test_json_file<T: DeserializeOwned>(file: &str) -> T {
44     let file = get_test_path(file);
45     let data = std::fs::read_to_string(file).unwrap();
46     let mut json = data.parse::<serde_json::Value>().unwrap();
47     fixup_paths(&mut json);
48     return serde_json::from_value(json).unwrap();
49
50     fn fixup_paths(val: &mut serde_json::Value) {
51         match val {
52             serde_json::Value::String(s) => replace_root(s, true),
53             serde_json::Value::Array(vals) => vals.iter_mut().for_each(fixup_paths),
54             serde_json::Value::Object(kvals) => kvals.values_mut().for_each(fixup_paths),
55             serde_json::Value::Null | serde_json::Value::Bool(_) | serde_json::Value::Number(_) => {
56             }
57         }
58     }
59 }
60
61 fn replace_root(s: &mut String, direction: bool) {
62     if direction {
63         let root = if cfg!(windows) { r#"C:\\ROOT\"# } else { "/ROOT/" };
64         *s = s.replace("$ROOT$", root)
65     } else {
66         let root = if cfg!(windows) { r#"C:\\\\ROOT\\"# } else { "/ROOT/" };
67         *s = s.replace(root, "$ROOT$")
68     }
69 }
70
71 fn get_test_path(file: &str) -> PathBuf {
72     let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
73     base.join("test_data").join(file)
74 }
75
76 fn get_fake_sysroot() -> Sysroot {
77     let sysroot_path = get_test_path("fake-sysroot");
78     let sysroot_src_dir = AbsPathBuf::assert(sysroot_path);
79     Sysroot::load(sysroot_src_dir).unwrap()
80 }
81
82 fn rooted_project_json(data: ProjectJsonData) -> ProjectJson {
83     let mut root = "$ROOT$".to_string();
84     replace_root(&mut root, true);
85     let path = Path::new(&root);
86     let base = AbsPath::assert(path);
87     ProjectJson::new(base, data)
88 }
89
90 fn to_crate_graph(project_workspace: ProjectWorkspace) -> CrateGraph {
91     project_workspace.to_crate_graph(&mut |_, _| Ok(Vec::new()), &mut {
92         let mut counter = 0;
93         move |_path| {
94             counter += 1;
95             Some(FileId(counter))
96         }
97     })
98 }
99
100 fn check_crate_graph(crate_graph: CrateGraph, expect: Expect) {
101     let mut crate_graph = format!("{:#?}", crate_graph);
102     replace_root(&mut crate_graph, false);
103     expect.assert_eq(&crate_graph);
104 }
105
106 #[test]
107 fn cargo_hello_world_project_model_with_wildcard_overrides() {
108     let cfg_overrides = CfgOverrides::Wildcard(
109         CfgDiff::new(Vec::new(), vec![CfgAtom::Flag("test".into())]).unwrap(),
110     );
111     let crate_graph = load_cargo_with_overrides("hello-world-metadata.json", cfg_overrides);
112     check_crate_graph(
113         crate_graph,
114         expect![[r#"
115             CrateGraph {
116                 arena: {
117                     CrateId(
118                         0,
119                     ): CrateData {
120                         root_file_id: FileId(
121                             1,
122                         ),
123                         edition: Edition2018,
124                         version: Some(
125                             "0.1.0",
126                         ),
127                         display_name: Some(
128                             CrateDisplayName {
129                                 crate_name: CrateName(
130                                     "hello_world",
131                                 ),
132                                 canonical_name: "hello-world",
133                             },
134                         ),
135                         cfg_options: CfgOptions(
136                             [
137                                 "debug_assertions",
138                             ],
139                         ),
140                         potential_cfg_options: CfgOptions(
141                             [
142                                 "debug_assertions",
143                             ],
144                         ),
145                         env: Env {
146                             entries: {
147                                 "CARGO_PKG_LICENSE": "",
148                                 "CARGO_PKG_VERSION_MAJOR": "0",
149                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
150                                 "CARGO_PKG_VERSION": "0.1.0",
151                                 "CARGO_PKG_AUTHORS": "",
152                                 "CARGO_CRATE_NAME": "hello_world",
153                                 "CARGO_PKG_LICENSE_FILE": "",
154                                 "CARGO_PKG_HOMEPAGE": "",
155                                 "CARGO_PKG_DESCRIPTION": "",
156                                 "CARGO_PKG_NAME": "hello-world",
157                                 "CARGO_PKG_VERSION_PATCH": "0",
158                                 "CARGO": "cargo",
159                                 "CARGO_PKG_REPOSITORY": "",
160                                 "CARGO_PKG_VERSION_MINOR": "1",
161                                 "CARGO_PKG_VERSION_PRE": "",
162                             },
163                         },
164                         dependencies: [
165                             Dependency {
166                                 crate_id: CrateId(
167                                     4,
168                                 ),
169                                 name: CrateName(
170                                     "libc",
171                                 ),
172                                 prelude: true,
173                             },
174                         ],
175                         proc_macro: Err(
176                             "crate has not (yet) been built",
177                         ),
178                         origin: CratesIo {
179                             repo: None,
180                         },
181                         is_proc_macro: false,
182                     },
183                     CrateId(
184                         2,
185                     ): CrateData {
186                         root_file_id: FileId(
187                             3,
188                         ),
189                         edition: Edition2018,
190                         version: Some(
191                             "0.1.0",
192                         ),
193                         display_name: Some(
194                             CrateDisplayName {
195                                 crate_name: CrateName(
196                                     "an_example",
197                                 ),
198                                 canonical_name: "an-example",
199                             },
200                         ),
201                         cfg_options: CfgOptions(
202                             [
203                                 "debug_assertions",
204                             ],
205                         ),
206                         potential_cfg_options: CfgOptions(
207                             [
208                                 "debug_assertions",
209                             ],
210                         ),
211                         env: Env {
212                             entries: {
213                                 "CARGO_PKG_LICENSE": "",
214                                 "CARGO_PKG_VERSION_MAJOR": "0",
215                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
216                                 "CARGO_PKG_VERSION": "0.1.0",
217                                 "CARGO_PKG_AUTHORS": "",
218                                 "CARGO_CRATE_NAME": "hello_world",
219                                 "CARGO_PKG_LICENSE_FILE": "",
220                                 "CARGO_PKG_HOMEPAGE": "",
221                                 "CARGO_PKG_DESCRIPTION": "",
222                                 "CARGO_PKG_NAME": "hello-world",
223                                 "CARGO_PKG_VERSION_PATCH": "0",
224                                 "CARGO": "cargo",
225                                 "CARGO_PKG_REPOSITORY": "",
226                                 "CARGO_PKG_VERSION_MINOR": "1",
227                                 "CARGO_PKG_VERSION_PRE": "",
228                             },
229                         },
230                         dependencies: [
231                             Dependency {
232                                 crate_id: CrateId(
233                                     0,
234                                 ),
235                                 name: CrateName(
236                                     "hello_world",
237                                 ),
238                                 prelude: true,
239                             },
240                             Dependency {
241                                 crate_id: CrateId(
242                                     4,
243                                 ),
244                                 name: CrateName(
245                                     "libc",
246                                 ),
247                                 prelude: true,
248                             },
249                         ],
250                         proc_macro: Err(
251                             "crate has not (yet) been built",
252                         ),
253                         origin: CratesIo {
254                             repo: None,
255                         },
256                         is_proc_macro: false,
257                     },
258                     CrateId(
259                         4,
260                     ): CrateData {
261                         root_file_id: FileId(
262                             5,
263                         ),
264                         edition: Edition2015,
265                         version: Some(
266                             "0.2.98",
267                         ),
268                         display_name: Some(
269                             CrateDisplayName {
270                                 crate_name: CrateName(
271                                     "libc",
272                                 ),
273                                 canonical_name: "libc",
274                             },
275                         ),
276                         cfg_options: CfgOptions(
277                             [
278                                 "debug_assertions",
279                                 "feature=default",
280                                 "feature=std",
281                             ],
282                         ),
283                         potential_cfg_options: CfgOptions(
284                             [
285                                 "debug_assertions",
286                                 "feature=align",
287                                 "feature=const-extern-fn",
288                                 "feature=default",
289                                 "feature=extra_traits",
290                                 "feature=rustc-dep-of-std",
291                                 "feature=std",
292                                 "feature=use_std",
293                             ],
294                         ),
295                         env: Env {
296                             entries: {
297                                 "CARGO_PKG_LICENSE": "",
298                                 "CARGO_PKG_VERSION_MAJOR": "0",
299                                 "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
300                                 "CARGO_PKG_VERSION": "0.2.98",
301                                 "CARGO_PKG_AUTHORS": "",
302                                 "CARGO_CRATE_NAME": "libc",
303                                 "CARGO_PKG_LICENSE_FILE": "",
304                                 "CARGO_PKG_HOMEPAGE": "",
305                                 "CARGO_PKG_DESCRIPTION": "",
306                                 "CARGO_PKG_NAME": "libc",
307                                 "CARGO_PKG_VERSION_PATCH": "98",
308                                 "CARGO": "cargo",
309                                 "CARGO_PKG_REPOSITORY": "",
310                                 "CARGO_PKG_VERSION_MINOR": "2",
311                                 "CARGO_PKG_VERSION_PRE": "",
312                             },
313                         },
314                         dependencies: [],
315                         proc_macro: Err(
316                             "crate has not (yet) been built",
317                         ),
318                         origin: CratesIo {
319                             repo: Some(
320                                 "https://github.com/rust-lang/libc",
321                             ),
322                         },
323                         is_proc_macro: false,
324                     },
325                     CrateId(
326                         1,
327                     ): CrateData {
328                         root_file_id: FileId(
329                             2,
330                         ),
331                         edition: Edition2018,
332                         version: Some(
333                             "0.1.0",
334                         ),
335                         display_name: Some(
336                             CrateDisplayName {
337                                 crate_name: CrateName(
338                                     "hello_world",
339                                 ),
340                                 canonical_name: "hello-world",
341                             },
342                         ),
343                         cfg_options: CfgOptions(
344                             [
345                                 "debug_assertions",
346                             ],
347                         ),
348                         potential_cfg_options: CfgOptions(
349                             [
350                                 "debug_assertions",
351                             ],
352                         ),
353                         env: Env {
354                             entries: {
355                                 "CARGO_PKG_LICENSE": "",
356                                 "CARGO_PKG_VERSION_MAJOR": "0",
357                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
358                                 "CARGO_PKG_VERSION": "0.1.0",
359                                 "CARGO_PKG_AUTHORS": "",
360                                 "CARGO_CRATE_NAME": "hello_world",
361                                 "CARGO_PKG_LICENSE_FILE": "",
362                                 "CARGO_PKG_HOMEPAGE": "",
363                                 "CARGO_PKG_DESCRIPTION": "",
364                                 "CARGO_PKG_NAME": "hello-world",
365                                 "CARGO_PKG_VERSION_PATCH": "0",
366                                 "CARGO": "cargo",
367                                 "CARGO_PKG_REPOSITORY": "",
368                                 "CARGO_PKG_VERSION_MINOR": "1",
369                                 "CARGO_PKG_VERSION_PRE": "",
370                             },
371                         },
372                         dependencies: [
373                             Dependency {
374                                 crate_id: CrateId(
375                                     0,
376                                 ),
377                                 name: CrateName(
378                                     "hello_world",
379                                 ),
380                                 prelude: true,
381                             },
382                             Dependency {
383                                 crate_id: CrateId(
384                                     4,
385                                 ),
386                                 name: CrateName(
387                                     "libc",
388                                 ),
389                                 prelude: true,
390                             },
391                         ],
392                         proc_macro: Err(
393                             "crate has not (yet) been built",
394                         ),
395                         origin: CratesIo {
396                             repo: None,
397                         },
398                         is_proc_macro: false,
399                     },
400                     CrateId(
401                         3,
402                     ): CrateData {
403                         root_file_id: FileId(
404                             4,
405                         ),
406                         edition: Edition2018,
407                         version: Some(
408                             "0.1.0",
409                         ),
410                         display_name: Some(
411                             CrateDisplayName {
412                                 crate_name: CrateName(
413                                     "it",
414                                 ),
415                                 canonical_name: "it",
416                             },
417                         ),
418                         cfg_options: CfgOptions(
419                             [
420                                 "debug_assertions",
421                             ],
422                         ),
423                         potential_cfg_options: CfgOptions(
424                             [
425                                 "debug_assertions",
426                             ],
427                         ),
428                         env: Env {
429                             entries: {
430                                 "CARGO_PKG_LICENSE": "",
431                                 "CARGO_PKG_VERSION_MAJOR": "0",
432                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
433                                 "CARGO_PKG_VERSION": "0.1.0",
434                                 "CARGO_PKG_AUTHORS": "",
435                                 "CARGO_CRATE_NAME": "hello_world",
436                                 "CARGO_PKG_LICENSE_FILE": "",
437                                 "CARGO_PKG_HOMEPAGE": "",
438                                 "CARGO_PKG_DESCRIPTION": "",
439                                 "CARGO_PKG_NAME": "hello-world",
440                                 "CARGO_PKG_VERSION_PATCH": "0",
441                                 "CARGO": "cargo",
442                                 "CARGO_PKG_REPOSITORY": "",
443                                 "CARGO_PKG_VERSION_MINOR": "1",
444                                 "CARGO_PKG_VERSION_PRE": "",
445                             },
446                         },
447                         dependencies: [
448                             Dependency {
449                                 crate_id: CrateId(
450                                     0,
451                                 ),
452                                 name: CrateName(
453                                     "hello_world",
454                                 ),
455                                 prelude: true,
456                             },
457                             Dependency {
458                                 crate_id: CrateId(
459                                     4,
460                                 ),
461                                 name: CrateName(
462                                     "libc",
463                                 ),
464                                 prelude: true,
465                             },
466                         ],
467                         proc_macro: Err(
468                             "crate has not (yet) been built",
469                         ),
470                         origin: CratesIo {
471                             repo: None,
472                         },
473                         is_proc_macro: false,
474                     },
475                 },
476             }"#]],
477     )
478 }
479
480 #[test]
481 fn cargo_hello_world_project_model_with_selective_overrides() {
482     let cfg_overrides = {
483         CfgOverrides::Selective(
484             std::iter::once((
485                 "libc".to_owned(),
486                 CfgDiff::new(Vec::new(), vec![CfgAtom::Flag("test".into())]).unwrap(),
487             ))
488             .collect(),
489         )
490     };
491     let crate_graph = load_cargo_with_overrides("hello-world-metadata.json", cfg_overrides);
492     check_crate_graph(
493         crate_graph,
494         expect![[r#"
495             CrateGraph {
496                 arena: {
497                     CrateId(
498                         0,
499                     ): CrateData {
500                         root_file_id: FileId(
501                             1,
502                         ),
503                         edition: Edition2018,
504                         version: Some(
505                             "0.1.0",
506                         ),
507                         display_name: Some(
508                             CrateDisplayName {
509                                 crate_name: CrateName(
510                                     "hello_world",
511                                 ),
512                                 canonical_name: "hello-world",
513                             },
514                         ),
515                         cfg_options: CfgOptions(
516                             [
517                                 "debug_assertions",
518                                 "test",
519                             ],
520                         ),
521                         potential_cfg_options: CfgOptions(
522                             [
523                                 "debug_assertions",
524                                 "test",
525                             ],
526                         ),
527                         env: Env {
528                             entries: {
529                                 "CARGO_PKG_LICENSE": "",
530                                 "CARGO_PKG_VERSION_MAJOR": "0",
531                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
532                                 "CARGO_PKG_VERSION": "0.1.0",
533                                 "CARGO_PKG_AUTHORS": "",
534                                 "CARGO_CRATE_NAME": "hello_world",
535                                 "CARGO_PKG_LICENSE_FILE": "",
536                                 "CARGO_PKG_HOMEPAGE": "",
537                                 "CARGO_PKG_DESCRIPTION": "",
538                                 "CARGO_PKG_NAME": "hello-world",
539                                 "CARGO_PKG_VERSION_PATCH": "0",
540                                 "CARGO": "cargo",
541                                 "CARGO_PKG_REPOSITORY": "",
542                                 "CARGO_PKG_VERSION_MINOR": "1",
543                                 "CARGO_PKG_VERSION_PRE": "",
544                             },
545                         },
546                         dependencies: [
547                             Dependency {
548                                 crate_id: CrateId(
549                                     4,
550                                 ),
551                                 name: CrateName(
552                                     "libc",
553                                 ),
554                                 prelude: true,
555                             },
556                         ],
557                         proc_macro: Err(
558                             "crate has not (yet) been built",
559                         ),
560                         origin: CratesIo {
561                             repo: None,
562                         },
563                         is_proc_macro: false,
564                     },
565                     CrateId(
566                         2,
567                     ): CrateData {
568                         root_file_id: FileId(
569                             3,
570                         ),
571                         edition: Edition2018,
572                         version: Some(
573                             "0.1.0",
574                         ),
575                         display_name: Some(
576                             CrateDisplayName {
577                                 crate_name: CrateName(
578                                     "an_example",
579                                 ),
580                                 canonical_name: "an-example",
581                             },
582                         ),
583                         cfg_options: CfgOptions(
584                             [
585                                 "debug_assertions",
586                                 "test",
587                             ],
588                         ),
589                         potential_cfg_options: CfgOptions(
590                             [
591                                 "debug_assertions",
592                                 "test",
593                             ],
594                         ),
595                         env: Env {
596                             entries: {
597                                 "CARGO_PKG_LICENSE": "",
598                                 "CARGO_PKG_VERSION_MAJOR": "0",
599                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
600                                 "CARGO_PKG_VERSION": "0.1.0",
601                                 "CARGO_PKG_AUTHORS": "",
602                                 "CARGO_CRATE_NAME": "hello_world",
603                                 "CARGO_PKG_LICENSE_FILE": "",
604                                 "CARGO_PKG_HOMEPAGE": "",
605                                 "CARGO_PKG_DESCRIPTION": "",
606                                 "CARGO_PKG_NAME": "hello-world",
607                                 "CARGO_PKG_VERSION_PATCH": "0",
608                                 "CARGO": "cargo",
609                                 "CARGO_PKG_REPOSITORY": "",
610                                 "CARGO_PKG_VERSION_MINOR": "1",
611                                 "CARGO_PKG_VERSION_PRE": "",
612                             },
613                         },
614                         dependencies: [
615                             Dependency {
616                                 crate_id: CrateId(
617                                     0,
618                                 ),
619                                 name: CrateName(
620                                     "hello_world",
621                                 ),
622                                 prelude: true,
623                             },
624                             Dependency {
625                                 crate_id: CrateId(
626                                     4,
627                                 ),
628                                 name: CrateName(
629                                     "libc",
630                                 ),
631                                 prelude: true,
632                             },
633                         ],
634                         proc_macro: Err(
635                             "crate has not (yet) been built",
636                         ),
637                         origin: CratesIo {
638                             repo: None,
639                         },
640                         is_proc_macro: false,
641                     },
642                     CrateId(
643                         4,
644                     ): CrateData {
645                         root_file_id: FileId(
646                             5,
647                         ),
648                         edition: Edition2015,
649                         version: Some(
650                             "0.2.98",
651                         ),
652                         display_name: Some(
653                             CrateDisplayName {
654                                 crate_name: CrateName(
655                                     "libc",
656                                 ),
657                                 canonical_name: "libc",
658                             },
659                         ),
660                         cfg_options: CfgOptions(
661                             [
662                                 "debug_assertions",
663                                 "feature=default",
664                                 "feature=std",
665                             ],
666                         ),
667                         potential_cfg_options: CfgOptions(
668                             [
669                                 "debug_assertions",
670                                 "feature=align",
671                                 "feature=const-extern-fn",
672                                 "feature=default",
673                                 "feature=extra_traits",
674                                 "feature=rustc-dep-of-std",
675                                 "feature=std",
676                                 "feature=use_std",
677                             ],
678                         ),
679                         env: Env {
680                             entries: {
681                                 "CARGO_PKG_LICENSE": "",
682                                 "CARGO_PKG_VERSION_MAJOR": "0",
683                                 "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
684                                 "CARGO_PKG_VERSION": "0.2.98",
685                                 "CARGO_PKG_AUTHORS": "",
686                                 "CARGO_CRATE_NAME": "libc",
687                                 "CARGO_PKG_LICENSE_FILE": "",
688                                 "CARGO_PKG_HOMEPAGE": "",
689                                 "CARGO_PKG_DESCRIPTION": "",
690                                 "CARGO_PKG_NAME": "libc",
691                                 "CARGO_PKG_VERSION_PATCH": "98",
692                                 "CARGO": "cargo",
693                                 "CARGO_PKG_REPOSITORY": "",
694                                 "CARGO_PKG_VERSION_MINOR": "2",
695                                 "CARGO_PKG_VERSION_PRE": "",
696                             },
697                         },
698                         dependencies: [],
699                         proc_macro: Err(
700                             "crate has not (yet) been built",
701                         ),
702                         origin: CratesIo {
703                             repo: Some(
704                                 "https://github.com/rust-lang/libc",
705                             ),
706                         },
707                         is_proc_macro: false,
708                     },
709                     CrateId(
710                         1,
711                     ): CrateData {
712                         root_file_id: FileId(
713                             2,
714                         ),
715                         edition: Edition2018,
716                         version: Some(
717                             "0.1.0",
718                         ),
719                         display_name: Some(
720                             CrateDisplayName {
721                                 crate_name: CrateName(
722                                     "hello_world",
723                                 ),
724                                 canonical_name: "hello-world",
725                             },
726                         ),
727                         cfg_options: CfgOptions(
728                             [
729                                 "debug_assertions",
730                                 "test",
731                             ],
732                         ),
733                         potential_cfg_options: CfgOptions(
734                             [
735                                 "debug_assertions",
736                                 "test",
737                             ],
738                         ),
739                         env: Env {
740                             entries: {
741                                 "CARGO_PKG_LICENSE": "",
742                                 "CARGO_PKG_VERSION_MAJOR": "0",
743                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
744                                 "CARGO_PKG_VERSION": "0.1.0",
745                                 "CARGO_PKG_AUTHORS": "",
746                                 "CARGO_CRATE_NAME": "hello_world",
747                                 "CARGO_PKG_LICENSE_FILE": "",
748                                 "CARGO_PKG_HOMEPAGE": "",
749                                 "CARGO_PKG_DESCRIPTION": "",
750                                 "CARGO_PKG_NAME": "hello-world",
751                                 "CARGO_PKG_VERSION_PATCH": "0",
752                                 "CARGO": "cargo",
753                                 "CARGO_PKG_REPOSITORY": "",
754                                 "CARGO_PKG_VERSION_MINOR": "1",
755                                 "CARGO_PKG_VERSION_PRE": "",
756                             },
757                         },
758                         dependencies: [
759                             Dependency {
760                                 crate_id: CrateId(
761                                     0,
762                                 ),
763                                 name: CrateName(
764                                     "hello_world",
765                                 ),
766                                 prelude: true,
767                             },
768                             Dependency {
769                                 crate_id: CrateId(
770                                     4,
771                                 ),
772                                 name: CrateName(
773                                     "libc",
774                                 ),
775                                 prelude: true,
776                             },
777                         ],
778                         proc_macro: Err(
779                             "crate has not (yet) been built",
780                         ),
781                         origin: CratesIo {
782                             repo: None,
783                         },
784                         is_proc_macro: false,
785                     },
786                     CrateId(
787                         3,
788                     ): CrateData {
789                         root_file_id: FileId(
790                             4,
791                         ),
792                         edition: Edition2018,
793                         version: Some(
794                             "0.1.0",
795                         ),
796                         display_name: Some(
797                             CrateDisplayName {
798                                 crate_name: CrateName(
799                                     "it",
800                                 ),
801                                 canonical_name: "it",
802                             },
803                         ),
804                         cfg_options: CfgOptions(
805                             [
806                                 "debug_assertions",
807                                 "test",
808                             ],
809                         ),
810                         potential_cfg_options: CfgOptions(
811                             [
812                                 "debug_assertions",
813                                 "test",
814                             ],
815                         ),
816                         env: Env {
817                             entries: {
818                                 "CARGO_PKG_LICENSE": "",
819                                 "CARGO_PKG_VERSION_MAJOR": "0",
820                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
821                                 "CARGO_PKG_VERSION": "0.1.0",
822                                 "CARGO_PKG_AUTHORS": "",
823                                 "CARGO_CRATE_NAME": "hello_world",
824                                 "CARGO_PKG_LICENSE_FILE": "",
825                                 "CARGO_PKG_HOMEPAGE": "",
826                                 "CARGO_PKG_DESCRIPTION": "",
827                                 "CARGO_PKG_NAME": "hello-world",
828                                 "CARGO_PKG_VERSION_PATCH": "0",
829                                 "CARGO": "cargo",
830                                 "CARGO_PKG_REPOSITORY": "",
831                                 "CARGO_PKG_VERSION_MINOR": "1",
832                                 "CARGO_PKG_VERSION_PRE": "",
833                             },
834                         },
835                         dependencies: [
836                             Dependency {
837                                 crate_id: CrateId(
838                                     0,
839                                 ),
840                                 name: CrateName(
841                                     "hello_world",
842                                 ),
843                                 prelude: true,
844                             },
845                             Dependency {
846                                 crate_id: CrateId(
847                                     4,
848                                 ),
849                                 name: CrateName(
850                                     "libc",
851                                 ),
852                                 prelude: true,
853                             },
854                         ],
855                         proc_macro: Err(
856                             "crate has not (yet) been built",
857                         ),
858                         origin: CratesIo {
859                             repo: None,
860                         },
861                         is_proc_macro: false,
862                     },
863                 },
864             }"#]],
865     )
866 }
867
868 #[test]
869 fn cargo_hello_world_project_model() {
870     let crate_graph = load_cargo("hello-world-metadata.json");
871     check_crate_graph(
872         crate_graph,
873         expect![[r#"
874             CrateGraph {
875                 arena: {
876                     CrateId(
877                         0,
878                     ): CrateData {
879                         root_file_id: FileId(
880                             1,
881                         ),
882                         edition: Edition2018,
883                         version: Some(
884                             "0.1.0",
885                         ),
886                         display_name: Some(
887                             CrateDisplayName {
888                                 crate_name: CrateName(
889                                     "hello_world",
890                                 ),
891                                 canonical_name: "hello-world",
892                             },
893                         ),
894                         cfg_options: CfgOptions(
895                             [
896                                 "debug_assertions",
897                                 "test",
898                             ],
899                         ),
900                         potential_cfg_options: CfgOptions(
901                             [
902                                 "debug_assertions",
903                                 "test",
904                             ],
905                         ),
906                         env: Env {
907                             entries: {
908                                 "CARGO_PKG_LICENSE": "",
909                                 "CARGO_PKG_VERSION_MAJOR": "0",
910                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
911                                 "CARGO_PKG_VERSION": "0.1.0",
912                                 "CARGO_PKG_AUTHORS": "",
913                                 "CARGO_CRATE_NAME": "hello_world",
914                                 "CARGO_PKG_LICENSE_FILE": "",
915                                 "CARGO_PKG_HOMEPAGE": "",
916                                 "CARGO_PKG_DESCRIPTION": "",
917                                 "CARGO_PKG_NAME": "hello-world",
918                                 "CARGO_PKG_VERSION_PATCH": "0",
919                                 "CARGO": "cargo",
920                                 "CARGO_PKG_REPOSITORY": "",
921                                 "CARGO_PKG_VERSION_MINOR": "1",
922                                 "CARGO_PKG_VERSION_PRE": "",
923                             },
924                         },
925                         dependencies: [
926                             Dependency {
927                                 crate_id: CrateId(
928                                     4,
929                                 ),
930                                 name: CrateName(
931                                     "libc",
932                                 ),
933                                 prelude: true,
934                             },
935                         ],
936                         proc_macro: Err(
937                             "crate has not (yet) been built",
938                         ),
939                         origin: CratesIo {
940                             repo: None,
941                         },
942                         is_proc_macro: false,
943                     },
944                     CrateId(
945                         2,
946                     ): CrateData {
947                         root_file_id: FileId(
948                             3,
949                         ),
950                         edition: Edition2018,
951                         version: Some(
952                             "0.1.0",
953                         ),
954                         display_name: Some(
955                             CrateDisplayName {
956                                 crate_name: CrateName(
957                                     "an_example",
958                                 ),
959                                 canonical_name: "an-example",
960                             },
961                         ),
962                         cfg_options: CfgOptions(
963                             [
964                                 "debug_assertions",
965                                 "test",
966                             ],
967                         ),
968                         potential_cfg_options: CfgOptions(
969                             [
970                                 "debug_assertions",
971                                 "test",
972                             ],
973                         ),
974                         env: Env {
975                             entries: {
976                                 "CARGO_PKG_LICENSE": "",
977                                 "CARGO_PKG_VERSION_MAJOR": "0",
978                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
979                                 "CARGO_PKG_VERSION": "0.1.0",
980                                 "CARGO_PKG_AUTHORS": "",
981                                 "CARGO_CRATE_NAME": "hello_world",
982                                 "CARGO_PKG_LICENSE_FILE": "",
983                                 "CARGO_PKG_HOMEPAGE": "",
984                                 "CARGO_PKG_DESCRIPTION": "",
985                                 "CARGO_PKG_NAME": "hello-world",
986                                 "CARGO_PKG_VERSION_PATCH": "0",
987                                 "CARGO": "cargo",
988                                 "CARGO_PKG_REPOSITORY": "",
989                                 "CARGO_PKG_VERSION_MINOR": "1",
990                                 "CARGO_PKG_VERSION_PRE": "",
991                             },
992                         },
993                         dependencies: [
994                             Dependency {
995                                 crate_id: CrateId(
996                                     0,
997                                 ),
998                                 name: CrateName(
999                                     "hello_world",
1000                                 ),
1001                                 prelude: true,
1002                             },
1003                             Dependency {
1004                                 crate_id: CrateId(
1005                                     4,
1006                                 ),
1007                                 name: CrateName(
1008                                     "libc",
1009                                 ),
1010                                 prelude: true,
1011                             },
1012                         ],
1013                         proc_macro: Err(
1014                             "crate has not (yet) been built",
1015                         ),
1016                         origin: CratesIo {
1017                             repo: None,
1018                         },
1019                         is_proc_macro: false,
1020                     },
1021                     CrateId(
1022                         4,
1023                     ): CrateData {
1024                         root_file_id: FileId(
1025                             5,
1026                         ),
1027                         edition: Edition2015,
1028                         version: Some(
1029                             "0.2.98",
1030                         ),
1031                         display_name: Some(
1032                             CrateDisplayName {
1033                                 crate_name: CrateName(
1034                                     "libc",
1035                                 ),
1036                                 canonical_name: "libc",
1037                             },
1038                         ),
1039                         cfg_options: CfgOptions(
1040                             [
1041                                 "debug_assertions",
1042                                 "feature=default",
1043                                 "feature=std",
1044                             ],
1045                         ),
1046                         potential_cfg_options: CfgOptions(
1047                             [
1048                                 "debug_assertions",
1049                                 "feature=align",
1050                                 "feature=const-extern-fn",
1051                                 "feature=default",
1052                                 "feature=extra_traits",
1053                                 "feature=rustc-dep-of-std",
1054                                 "feature=std",
1055                                 "feature=use_std",
1056                             ],
1057                         ),
1058                         env: Env {
1059                             entries: {
1060                                 "CARGO_PKG_LICENSE": "",
1061                                 "CARGO_PKG_VERSION_MAJOR": "0",
1062                                 "CARGO_MANIFEST_DIR": "$ROOT$.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.98",
1063                                 "CARGO_PKG_VERSION": "0.2.98",
1064                                 "CARGO_PKG_AUTHORS": "",
1065                                 "CARGO_CRATE_NAME": "libc",
1066                                 "CARGO_PKG_LICENSE_FILE": "",
1067                                 "CARGO_PKG_HOMEPAGE": "",
1068                                 "CARGO_PKG_DESCRIPTION": "",
1069                                 "CARGO_PKG_NAME": "libc",
1070                                 "CARGO_PKG_VERSION_PATCH": "98",
1071                                 "CARGO": "cargo",
1072                                 "CARGO_PKG_REPOSITORY": "",
1073                                 "CARGO_PKG_VERSION_MINOR": "2",
1074                                 "CARGO_PKG_VERSION_PRE": "",
1075                             },
1076                         },
1077                         dependencies: [],
1078                         proc_macro: Err(
1079                             "crate has not (yet) been built",
1080                         ),
1081                         origin: CratesIo {
1082                             repo: Some(
1083                                 "https://github.com/rust-lang/libc",
1084                             ),
1085                         },
1086                         is_proc_macro: false,
1087                     },
1088                     CrateId(
1089                         1,
1090                     ): CrateData {
1091                         root_file_id: FileId(
1092                             2,
1093                         ),
1094                         edition: Edition2018,
1095                         version: Some(
1096                             "0.1.0",
1097                         ),
1098                         display_name: Some(
1099                             CrateDisplayName {
1100                                 crate_name: CrateName(
1101                                     "hello_world",
1102                                 ),
1103                                 canonical_name: "hello-world",
1104                             },
1105                         ),
1106                         cfg_options: CfgOptions(
1107                             [
1108                                 "debug_assertions",
1109                                 "test",
1110                             ],
1111                         ),
1112                         potential_cfg_options: CfgOptions(
1113                             [
1114                                 "debug_assertions",
1115                                 "test",
1116                             ],
1117                         ),
1118                         env: Env {
1119                             entries: {
1120                                 "CARGO_PKG_LICENSE": "",
1121                                 "CARGO_PKG_VERSION_MAJOR": "0",
1122                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
1123                                 "CARGO_PKG_VERSION": "0.1.0",
1124                                 "CARGO_PKG_AUTHORS": "",
1125                                 "CARGO_CRATE_NAME": "hello_world",
1126                                 "CARGO_PKG_LICENSE_FILE": "",
1127                                 "CARGO_PKG_HOMEPAGE": "",
1128                                 "CARGO_PKG_DESCRIPTION": "",
1129                                 "CARGO_PKG_NAME": "hello-world",
1130                                 "CARGO_PKG_VERSION_PATCH": "0",
1131                                 "CARGO": "cargo",
1132                                 "CARGO_PKG_REPOSITORY": "",
1133                                 "CARGO_PKG_VERSION_MINOR": "1",
1134                                 "CARGO_PKG_VERSION_PRE": "",
1135                             },
1136                         },
1137                         dependencies: [
1138                             Dependency {
1139                                 crate_id: CrateId(
1140                                     0,
1141                                 ),
1142                                 name: CrateName(
1143                                     "hello_world",
1144                                 ),
1145                                 prelude: true,
1146                             },
1147                             Dependency {
1148                                 crate_id: CrateId(
1149                                     4,
1150                                 ),
1151                                 name: CrateName(
1152                                     "libc",
1153                                 ),
1154                                 prelude: true,
1155                             },
1156                         ],
1157                         proc_macro: Err(
1158                             "crate has not (yet) been built",
1159                         ),
1160                         origin: CratesIo {
1161                             repo: None,
1162                         },
1163                         is_proc_macro: false,
1164                     },
1165                     CrateId(
1166                         3,
1167                     ): CrateData {
1168                         root_file_id: FileId(
1169                             4,
1170                         ),
1171                         edition: Edition2018,
1172                         version: Some(
1173                             "0.1.0",
1174                         ),
1175                         display_name: Some(
1176                             CrateDisplayName {
1177                                 crate_name: CrateName(
1178                                     "it",
1179                                 ),
1180                                 canonical_name: "it",
1181                             },
1182                         ),
1183                         cfg_options: CfgOptions(
1184                             [
1185                                 "debug_assertions",
1186                                 "test",
1187                             ],
1188                         ),
1189                         potential_cfg_options: CfgOptions(
1190                             [
1191                                 "debug_assertions",
1192                                 "test",
1193                             ],
1194                         ),
1195                         env: Env {
1196                             entries: {
1197                                 "CARGO_PKG_LICENSE": "",
1198                                 "CARGO_PKG_VERSION_MAJOR": "0",
1199                                 "CARGO_MANIFEST_DIR": "$ROOT$hello-world",
1200                                 "CARGO_PKG_VERSION": "0.1.0",
1201                                 "CARGO_PKG_AUTHORS": "",
1202                                 "CARGO_CRATE_NAME": "hello_world",
1203                                 "CARGO_PKG_LICENSE_FILE": "",
1204                                 "CARGO_PKG_HOMEPAGE": "",
1205                                 "CARGO_PKG_DESCRIPTION": "",
1206                                 "CARGO_PKG_NAME": "hello-world",
1207                                 "CARGO_PKG_VERSION_PATCH": "0",
1208                                 "CARGO": "cargo",
1209                                 "CARGO_PKG_REPOSITORY": "",
1210                                 "CARGO_PKG_VERSION_MINOR": "1",
1211                                 "CARGO_PKG_VERSION_PRE": "",
1212                             },
1213                         },
1214                         dependencies: [
1215                             Dependency {
1216                                 crate_id: CrateId(
1217                                     0,
1218                                 ),
1219                                 name: CrateName(
1220                                     "hello_world",
1221                                 ),
1222                                 prelude: true,
1223                             },
1224                             Dependency {
1225                                 crate_id: CrateId(
1226                                     4,
1227                                 ),
1228                                 name: CrateName(
1229                                     "libc",
1230                                 ),
1231                                 prelude: true,
1232                             },
1233                         ],
1234                         proc_macro: Err(
1235                             "crate has not (yet) been built",
1236                         ),
1237                         origin: CratesIo {
1238                             repo: None,
1239                         },
1240                         is_proc_macro: false,
1241                     },
1242                 },
1243             }"#]],
1244     )
1245 }
1246
1247 #[test]
1248 fn rust_project_hello_world_project_model() {
1249     let crate_graph = load_rust_project("hello-world-project.json");
1250     check_crate_graph(
1251         crate_graph,
1252         expect![[r#"
1253             CrateGraph {
1254                 arena: {
1255                     CrateId(
1256                         0,
1257                     ): CrateData {
1258                         root_file_id: FileId(
1259                             1,
1260                         ),
1261                         edition: Edition2018,
1262                         version: None,
1263                         display_name: Some(
1264                             CrateDisplayName {
1265                                 crate_name: CrateName(
1266                                     "alloc",
1267                                 ),
1268                                 canonical_name: "alloc",
1269                             },
1270                         ),
1271                         cfg_options: CfgOptions(
1272                             [],
1273                         ),
1274                         potential_cfg_options: CfgOptions(
1275                             [],
1276                         ),
1277                         env: Env {
1278                             entries: {},
1279                         },
1280                         dependencies: [
1281                             Dependency {
1282                                 crate_id: CrateId(
1283                                     1,
1284                                 ),
1285                                 name: CrateName(
1286                                     "core",
1287                                 ),
1288                                 prelude: true,
1289                             },
1290                         ],
1291                         proc_macro: Err(
1292                             "no proc macro loaded for sysroot crate",
1293                         ),
1294                         origin: Lang(
1295                             Alloc,
1296                         ),
1297                         is_proc_macro: false,
1298                     },
1299                     CrateId(
1300                         10,
1301                     ): CrateData {
1302                         root_file_id: FileId(
1303                             11,
1304                         ),
1305                         edition: Edition2018,
1306                         version: None,
1307                         display_name: Some(
1308                             CrateDisplayName {
1309                                 crate_name: CrateName(
1310                                     "unwind",
1311                                 ),
1312                                 canonical_name: "unwind",
1313                             },
1314                         ),
1315                         cfg_options: CfgOptions(
1316                             [],
1317                         ),
1318                         potential_cfg_options: CfgOptions(
1319                             [],
1320                         ),
1321                         env: Env {
1322                             entries: {},
1323                         },
1324                         dependencies: [],
1325                         proc_macro: Err(
1326                             "no proc macro loaded for sysroot crate",
1327                         ),
1328                         origin: Lang(
1329                             Other,
1330                         ),
1331                         is_proc_macro: false,
1332                     },
1333                     CrateId(
1334                         7,
1335                     ): CrateData {
1336                         root_file_id: FileId(
1337                             8,
1338                         ),
1339                         edition: Edition2018,
1340                         version: None,
1341                         display_name: Some(
1342                             CrateDisplayName {
1343                                 crate_name: CrateName(
1344                                     "std_detect",
1345                                 ),
1346                                 canonical_name: "std_detect",
1347                             },
1348                         ),
1349                         cfg_options: CfgOptions(
1350                             [],
1351                         ),
1352                         potential_cfg_options: CfgOptions(
1353                             [],
1354                         ),
1355                         env: Env {
1356                             entries: {},
1357                         },
1358                         dependencies: [],
1359                         proc_macro: Err(
1360                             "no proc macro loaded for sysroot crate",
1361                         ),
1362                         origin: Lang(
1363                             Other,
1364                         ),
1365                         is_proc_macro: false,
1366                     },
1367                     CrateId(
1368                         4,
1369                     ): CrateData {
1370                         root_file_id: FileId(
1371                             5,
1372                         ),
1373                         edition: Edition2018,
1374                         version: None,
1375                         display_name: Some(
1376                             CrateDisplayName {
1377                                 crate_name: CrateName(
1378                                     "proc_macro",
1379                                 ),
1380                                 canonical_name: "proc_macro",
1381                             },
1382                         ),
1383                         cfg_options: CfgOptions(
1384                             [],
1385                         ),
1386                         potential_cfg_options: CfgOptions(
1387                             [],
1388                         ),
1389                         env: Env {
1390                             entries: {},
1391                         },
1392                         dependencies: [
1393                             Dependency {
1394                                 crate_id: CrateId(
1395                                     6,
1396                                 ),
1397                                 name: CrateName(
1398                                     "std",
1399                                 ),
1400                                 prelude: true,
1401                             },
1402                         ],
1403                         proc_macro: Err(
1404                             "no proc macro loaded for sysroot crate",
1405                         ),
1406                         origin: Lang(
1407                             Other,
1408                         ),
1409                         is_proc_macro: false,
1410                     },
1411                     CrateId(
1412                         1,
1413                     ): CrateData {
1414                         root_file_id: FileId(
1415                             2,
1416                         ),
1417                         edition: Edition2018,
1418                         version: None,
1419                         display_name: Some(
1420                             CrateDisplayName {
1421                                 crate_name: CrateName(
1422                                     "core",
1423                                 ),
1424                                 canonical_name: "core",
1425                             },
1426                         ),
1427                         cfg_options: CfgOptions(
1428                             [],
1429                         ),
1430                         potential_cfg_options: CfgOptions(
1431                             [],
1432                         ),
1433                         env: Env {
1434                             entries: {},
1435                         },
1436                         dependencies: [],
1437                         proc_macro: Err(
1438                             "no proc macro loaded for sysroot crate",
1439                         ),
1440                         origin: Lang(
1441                             Core,
1442                         ),
1443                         is_proc_macro: false,
1444                     },
1445                     CrateId(
1446                         11,
1447                     ): CrateData {
1448                         root_file_id: FileId(
1449                             12,
1450                         ),
1451                         edition: Edition2018,
1452                         version: None,
1453                         display_name: Some(
1454                             CrateDisplayName {
1455                                 crate_name: CrateName(
1456                                     "hello_world",
1457                                 ),
1458                                 canonical_name: "hello_world",
1459                             },
1460                         ),
1461                         cfg_options: CfgOptions(
1462                             [],
1463                         ),
1464                         potential_cfg_options: CfgOptions(
1465                             [],
1466                         ),
1467                         env: Env {
1468                             entries: {},
1469                         },
1470                         dependencies: [
1471                             Dependency {
1472                                 crate_id: CrateId(
1473                                     1,
1474                                 ),
1475                                 name: CrateName(
1476                                     "core",
1477                                 ),
1478                                 prelude: true,
1479                             },
1480                             Dependency {
1481                                 crate_id: CrateId(
1482                                     0,
1483                                 ),
1484                                 name: CrateName(
1485                                     "alloc",
1486                                 ),
1487                                 prelude: true,
1488                             },
1489                             Dependency {
1490                                 crate_id: CrateId(
1491                                     6,
1492                                 ),
1493                                 name: CrateName(
1494                                     "std",
1495                                 ),
1496                                 prelude: true,
1497                             },
1498                             Dependency {
1499                                 crate_id: CrateId(
1500                                     9,
1501                                 ),
1502                                 name: CrateName(
1503                                     "test",
1504                                 ),
1505                                 prelude: false,
1506                             },
1507                         ],
1508                         proc_macro: Err(
1509                             "no proc macro dylib present",
1510                         ),
1511                         origin: CratesIo {
1512                             repo: None,
1513                         },
1514                         is_proc_macro: false,
1515                     },
1516                     CrateId(
1517                         8,
1518                     ): CrateData {
1519                         root_file_id: FileId(
1520                             9,
1521                         ),
1522                         edition: Edition2018,
1523                         version: None,
1524                         display_name: Some(
1525                             CrateDisplayName {
1526                                 crate_name: CrateName(
1527                                     "term",
1528                                 ),
1529                                 canonical_name: "term",
1530                             },
1531                         ),
1532                         cfg_options: CfgOptions(
1533                             [],
1534                         ),
1535                         potential_cfg_options: CfgOptions(
1536                             [],
1537                         ),
1538                         env: Env {
1539                             entries: {},
1540                         },
1541                         dependencies: [],
1542                         proc_macro: Err(
1543                             "no proc macro loaded for sysroot crate",
1544                         ),
1545                         origin: Lang(
1546                             Other,
1547                         ),
1548                         is_proc_macro: false,
1549                     },
1550                     CrateId(
1551                         5,
1552                     ): CrateData {
1553                         root_file_id: FileId(
1554                             6,
1555                         ),
1556                         edition: Edition2018,
1557                         version: None,
1558                         display_name: Some(
1559                             CrateDisplayName {
1560                                 crate_name: CrateName(
1561                                     "profiler_builtins",
1562                                 ),
1563                                 canonical_name: "profiler_builtins",
1564                             },
1565                         ),
1566                         cfg_options: CfgOptions(
1567                             [],
1568                         ),
1569                         potential_cfg_options: CfgOptions(
1570                             [],
1571                         ),
1572                         env: Env {
1573                             entries: {},
1574                         },
1575                         dependencies: [],
1576                         proc_macro: Err(
1577                             "no proc macro loaded for sysroot crate",
1578                         ),
1579                         origin: Lang(
1580                             Other,
1581                         ),
1582                         is_proc_macro: false,
1583                     },
1584                     CrateId(
1585                         2,
1586                     ): CrateData {
1587                         root_file_id: FileId(
1588                             3,
1589                         ),
1590                         edition: Edition2018,
1591                         version: None,
1592                         display_name: Some(
1593                             CrateDisplayName {
1594                                 crate_name: CrateName(
1595                                     "panic_abort",
1596                                 ),
1597                                 canonical_name: "panic_abort",
1598                             },
1599                         ),
1600                         cfg_options: CfgOptions(
1601                             [],
1602                         ),
1603                         potential_cfg_options: CfgOptions(
1604                             [],
1605                         ),
1606                         env: Env {
1607                             entries: {},
1608                         },
1609                         dependencies: [],
1610                         proc_macro: Err(
1611                             "no proc macro loaded for sysroot crate",
1612                         ),
1613                         origin: Lang(
1614                             Other,
1615                         ),
1616                         is_proc_macro: false,
1617                     },
1618                     CrateId(
1619                         9,
1620                     ): CrateData {
1621                         root_file_id: FileId(
1622                             10,
1623                         ),
1624                         edition: Edition2018,
1625                         version: None,
1626                         display_name: Some(
1627                             CrateDisplayName {
1628                                 crate_name: CrateName(
1629                                     "test",
1630                                 ),
1631                                 canonical_name: "test",
1632                             },
1633                         ),
1634                         cfg_options: CfgOptions(
1635                             [],
1636                         ),
1637                         potential_cfg_options: CfgOptions(
1638                             [],
1639                         ),
1640                         env: Env {
1641                             entries: {},
1642                         },
1643                         dependencies: [],
1644                         proc_macro: Err(
1645                             "no proc macro loaded for sysroot crate",
1646                         ),
1647                         origin: Lang(
1648                             Test,
1649                         ),
1650                         is_proc_macro: false,
1651                     },
1652                     CrateId(
1653                         6,
1654                     ): CrateData {
1655                         root_file_id: FileId(
1656                             7,
1657                         ),
1658                         edition: Edition2018,
1659                         version: None,
1660                         display_name: Some(
1661                             CrateDisplayName {
1662                                 crate_name: CrateName(
1663                                     "std",
1664                                 ),
1665                                 canonical_name: "std",
1666                             },
1667                         ),
1668                         cfg_options: CfgOptions(
1669                             [],
1670                         ),
1671                         potential_cfg_options: CfgOptions(
1672                             [],
1673                         ),
1674                         env: Env {
1675                             entries: {},
1676                         },
1677                         dependencies: [
1678                             Dependency {
1679                                 crate_id: CrateId(
1680                                     0,
1681                                 ),
1682                                 name: CrateName(
1683                                     "alloc",
1684                                 ),
1685                                 prelude: true,
1686                             },
1687                             Dependency {
1688                                 crate_id: CrateId(
1689                                     1,
1690                                 ),
1691                                 name: CrateName(
1692                                     "core",
1693                                 ),
1694                                 prelude: true,
1695                             },
1696                             Dependency {
1697                                 crate_id: CrateId(
1698                                     2,
1699                                 ),
1700                                 name: CrateName(
1701                                     "panic_abort",
1702                                 ),
1703                                 prelude: true,
1704                             },
1705                             Dependency {
1706                                 crate_id: CrateId(
1707                                     3,
1708                                 ),
1709                                 name: CrateName(
1710                                     "panic_unwind",
1711                                 ),
1712                                 prelude: true,
1713                             },
1714                             Dependency {
1715                                 crate_id: CrateId(
1716                                     5,
1717                                 ),
1718                                 name: CrateName(
1719                                     "profiler_builtins",
1720                                 ),
1721                                 prelude: true,
1722                             },
1723                             Dependency {
1724                                 crate_id: CrateId(
1725                                     7,
1726                                 ),
1727                                 name: CrateName(
1728                                     "std_detect",
1729                                 ),
1730                                 prelude: true,
1731                             },
1732                             Dependency {
1733                                 crate_id: CrateId(
1734                                     8,
1735                                 ),
1736                                 name: CrateName(
1737                                     "term",
1738                                 ),
1739                                 prelude: true,
1740                             },
1741                             Dependency {
1742                                 crate_id: CrateId(
1743                                     9,
1744                                 ),
1745                                 name: CrateName(
1746                                     "test",
1747                                 ),
1748                                 prelude: true,
1749                             },
1750                             Dependency {
1751                                 crate_id: CrateId(
1752                                     10,
1753                                 ),
1754                                 name: CrateName(
1755                                     "unwind",
1756                                 ),
1757                                 prelude: true,
1758                             },
1759                         ],
1760                         proc_macro: Err(
1761                             "no proc macro loaded for sysroot crate",
1762                         ),
1763                         origin: Lang(
1764                             Std,
1765                         ),
1766                         is_proc_macro: false,
1767                     },
1768                     CrateId(
1769                         3,
1770                     ): CrateData {
1771                         root_file_id: FileId(
1772                             4,
1773                         ),
1774                         edition: Edition2018,
1775                         version: None,
1776                         display_name: Some(
1777                             CrateDisplayName {
1778                                 crate_name: CrateName(
1779                                     "panic_unwind",
1780                                 ),
1781                                 canonical_name: "panic_unwind",
1782                             },
1783                         ),
1784                         cfg_options: CfgOptions(
1785                             [],
1786                         ),
1787                         potential_cfg_options: CfgOptions(
1788                             [],
1789                         ),
1790                         env: Env {
1791                             entries: {},
1792                         },
1793                         dependencies: [],
1794                         proc_macro: Err(
1795                             "no proc macro loaded for sysroot crate",
1796                         ),
1797                         origin: Lang(
1798                             Other,
1799                         ),
1800                         is_proc_macro: false,
1801                     },
1802                 },
1803             }"#]],
1804     );
1805 }
1806
1807 #[test]
1808 fn rust_project_is_proc_macro_has_proc_macro_dep() {
1809     let crate_graph = load_rust_project("is-proc-macro-project.json");
1810     // Since the project only defines one crate (outside the sysroot crates),
1811     // it should be the one with the biggest Id.
1812     let crate_id = crate_graph.iter().max().unwrap();
1813     let crate_data = &crate_graph[crate_id];
1814     // Assert that the project crate with `is_proc_macro` has a dependency
1815     // on the proc_macro sysroot crate.
1816     crate_data.dependencies.iter().find(|&dep| dep.name.deref() == "proc_macro").unwrap();
1817 }