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