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