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