xref: /aosp_15_r20/external/bazelbuild-rules_rust/crate_universe/src/test.rs (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan //! A module containing common test helpers
2*d4726bddSHONG Yifan 
mock_cargo_metadata_package() -> cargo_metadata::Package3*d4726bddSHONG Yifan pub(crate) fn mock_cargo_metadata_package() -> cargo_metadata::Package {
4*d4726bddSHONG Yifan     serde_json::from_value(serde_json::json!({
5*d4726bddSHONG Yifan         "name": "mock-pkg",
6*d4726bddSHONG Yifan         "version": "3.3.3",
7*d4726bddSHONG Yifan         "id": "mock-pkg 3.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
8*d4726bddSHONG Yifan         "license": "Unlicense/MIT",
9*d4726bddSHONG Yifan         "license_file": null,
10*d4726bddSHONG Yifan         "description": "Fast multiple substring searching.",
11*d4726bddSHONG Yifan         "source": "registry+https://github.com/rust-lang/crates.io-index",
12*d4726bddSHONG Yifan         "dependencies": [],
13*d4726bddSHONG Yifan         "targets": [],
14*d4726bddSHONG Yifan         "features": {},
15*d4726bddSHONG Yifan         "manifest_path": "/tmp/mock-pkg-3.3.3/Cargo.toml",
16*d4726bddSHONG Yifan         "metadata": null,
17*d4726bddSHONG Yifan         "publish": null,
18*d4726bddSHONG Yifan         "authors": [],
19*d4726bddSHONG Yifan         "categories": [],
20*d4726bddSHONG Yifan         "keywords": [],
21*d4726bddSHONG Yifan         "readme": "README.md",
22*d4726bddSHONG Yifan         "repository": "",
23*d4726bddSHONG Yifan         "homepage": "",
24*d4726bddSHONG Yifan         "documentation": null,
25*d4726bddSHONG Yifan         "edition": "2021",
26*d4726bddSHONG Yifan         "links": null,
27*d4726bddSHONG Yifan         "default_run": null
28*d4726bddSHONG Yifan     }))
29*d4726bddSHONG Yifan     .unwrap()
30*d4726bddSHONG Yifan }
31*d4726bddSHONG Yifan 
mock_cargo_lock_package() -> cargo_lock::Package32*d4726bddSHONG Yifan pub(crate) fn mock_cargo_lock_package() -> cargo_lock::Package {
33*d4726bddSHONG Yifan     toml::from_str(&textwrap::dedent(
34*d4726bddSHONG Yifan         r#"
35*d4726bddSHONG Yifan         name = "mock-pkg"
36*d4726bddSHONG Yifan         version = "3.3.3"
37*d4726bddSHONG Yifan         source = "registry+https://github.com/rust-lang/crates.io-index"
38*d4726bddSHONG Yifan         checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
39*d4726bddSHONG Yifan         dependencies = []
40*d4726bddSHONG Yifan         "#,
41*d4726bddSHONG Yifan     ))
42*d4726bddSHONG Yifan     .unwrap()
43*d4726bddSHONG Yifan }
44*d4726bddSHONG Yifan 
45*d4726bddSHONG Yifan pub(crate) mod metadata {
alias() -> cargo_metadata::Metadata46*d4726bddSHONG Yifan     pub(crate) fn alias() -> cargo_metadata::Metadata {
47*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
48*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
49*d4726bddSHONG Yifan             "/test_data/metadata/aliases/metadata.json"
50*d4726bddSHONG Yifan         )))
51*d4726bddSHONG Yifan         .unwrap()
52*d4726bddSHONG Yifan     }
53*d4726bddSHONG Yifan 
build_scripts() -> cargo_metadata::Metadata54*d4726bddSHONG Yifan     pub(crate) fn build_scripts() -> cargo_metadata::Metadata {
55*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
56*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
57*d4726bddSHONG Yifan             "/test_data/metadata/build_scripts/metadata.json"
58*d4726bddSHONG Yifan         )))
59*d4726bddSHONG Yifan         .unwrap()
60*d4726bddSHONG Yifan     }
61*d4726bddSHONG Yifan 
crate_types() -> cargo_metadata::Metadata62*d4726bddSHONG Yifan     pub(crate) fn crate_types() -> cargo_metadata::Metadata {
63*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
64*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
65*d4726bddSHONG Yifan             "/test_data/metadata/crate_types/metadata.json"
66*d4726bddSHONG Yifan         )))
67*d4726bddSHONG Yifan         .unwrap()
68*d4726bddSHONG Yifan     }
69*d4726bddSHONG Yifan 
multi_cfg_dep() -> cargo_metadata::Metadata70*d4726bddSHONG Yifan     pub(crate) fn multi_cfg_dep() -> cargo_metadata::Metadata {
71*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
72*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
73*d4726bddSHONG Yifan             "/test_data/metadata/multi_cfg_dep/metadata.json"
74*d4726bddSHONG Yifan         )))
75*d4726bddSHONG Yifan         .unwrap()
76*d4726bddSHONG Yifan     }
77*d4726bddSHONG Yifan 
multi_kind_proc_macro_dep() -> cargo_metadata::Metadata78*d4726bddSHONG Yifan     pub(crate) fn multi_kind_proc_macro_dep() -> cargo_metadata::Metadata {
79*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
80*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
81*d4726bddSHONG Yifan             "/test_data/metadata/multi_kind_proc_macro_dep/metadata.json"
82*d4726bddSHONG Yifan         )))
83*d4726bddSHONG Yifan         .unwrap()
84*d4726bddSHONG Yifan     }
85*d4726bddSHONG Yifan 
no_deps() -> cargo_metadata::Metadata86*d4726bddSHONG Yifan     pub(crate) fn no_deps() -> cargo_metadata::Metadata {
87*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
88*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
89*d4726bddSHONG Yifan             "/test_data/metadata/no_deps/metadata.json"
90*d4726bddSHONG Yifan         )))
91*d4726bddSHONG Yifan         .unwrap()
92*d4726bddSHONG Yifan     }
93*d4726bddSHONG Yifan 
optional_deps_disabled() -> cargo_metadata::Metadata94*d4726bddSHONG Yifan     pub(crate) fn optional_deps_disabled() -> cargo_metadata::Metadata {
95*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
96*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
97*d4726bddSHONG Yifan             "/test_data/metadata/crate_optional_deps_disabled/metadata.json"
98*d4726bddSHONG Yifan         )))
99*d4726bddSHONG Yifan         .unwrap()
100*d4726bddSHONG Yifan     }
101*d4726bddSHONG Yifan 
renamed_optional_deps_disabled() -> cargo_metadata::Metadata102*d4726bddSHONG Yifan     pub(crate) fn renamed_optional_deps_disabled() -> cargo_metadata::Metadata {
103*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
104*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
105*d4726bddSHONG Yifan             "/test_data/metadata/crate_renamed_optional_deps_disabled/metadata.json"
106*d4726bddSHONG Yifan         )))
107*d4726bddSHONG Yifan         .unwrap()
108*d4726bddSHONG Yifan     }
109*d4726bddSHONG Yifan 
optional_deps_disabled_build_dep_enabled() -> cargo_metadata::Metadata110*d4726bddSHONG Yifan     pub(crate) fn optional_deps_disabled_build_dep_enabled() -> cargo_metadata::Metadata {
111*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
112*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
113*d4726bddSHONG Yifan             "/test_data/metadata/crate_optional_deps_disabled_build_dep_enabled/metadata.json"
114*d4726bddSHONG Yifan         )))
115*d4726bddSHONG Yifan         .unwrap()
116*d4726bddSHONG Yifan     }
117*d4726bddSHONG Yifan 
optional_deps_enabled() -> cargo_metadata::Metadata118*d4726bddSHONG Yifan     pub(crate) fn optional_deps_enabled() -> cargo_metadata::Metadata {
119*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
120*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
121*d4726bddSHONG Yifan             "/test_data/metadata/crate_optional_deps_enabled/metadata.json"
122*d4726bddSHONG Yifan         )))
123*d4726bddSHONG Yifan         .unwrap()
124*d4726bddSHONG Yifan     }
125*d4726bddSHONG Yifan 
renamed_optional_deps_enabled() -> cargo_metadata::Metadata126*d4726bddSHONG Yifan     pub(crate) fn renamed_optional_deps_enabled() -> cargo_metadata::Metadata {
127*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
128*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
129*d4726bddSHONG Yifan             "/test_data/metadata/crate_renamed_optional_deps_enabled/metadata.json"
130*d4726bddSHONG Yifan         )))
131*d4726bddSHONG Yifan         .unwrap()
132*d4726bddSHONG Yifan     }
133*d4726bddSHONG Yifan 
common() -> cargo_metadata::Metadata134*d4726bddSHONG Yifan     pub(crate) fn common() -> cargo_metadata::Metadata {
135*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
136*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
137*d4726bddSHONG Yifan             "/test_data/metadata/common/metadata.json"
138*d4726bddSHONG Yifan         )))
139*d4726bddSHONG Yifan         .unwrap()
140*d4726bddSHONG Yifan     }
141*d4726bddSHONG Yifan 
example_proc_macro_dep() -> cargo_metadata::Metadata142*d4726bddSHONG Yifan     pub(crate) fn example_proc_macro_dep() -> cargo_metadata::Metadata {
143*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
144*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
145*d4726bddSHONG Yifan             "/test_data/metadata/example_proc_macro_dep/metadata.json"
146*d4726bddSHONG Yifan         )))
147*d4726bddSHONG Yifan         .unwrap()
148*d4726bddSHONG Yifan     }
149*d4726bddSHONG Yifan 
git_repos() -> cargo_metadata::Metadata150*d4726bddSHONG Yifan     pub(crate) fn git_repos() -> cargo_metadata::Metadata {
151*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
152*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
153*d4726bddSHONG Yifan             "/test_data/metadata/git_repos/metadata.json"
154*d4726bddSHONG Yifan         )))
155*d4726bddSHONG Yifan         .unwrap()
156*d4726bddSHONG Yifan     }
157*d4726bddSHONG Yifan 
has_package_metadata() -> cargo_metadata::Metadata158*d4726bddSHONG Yifan     pub(crate) fn has_package_metadata() -> cargo_metadata::Metadata {
159*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
160*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
161*d4726bddSHONG Yifan             "/test_data/metadata/has_package_metadata/metadata.json"
162*d4726bddSHONG Yifan         )))
163*d4726bddSHONG Yifan         .unwrap()
164*d4726bddSHONG Yifan     }
165*d4726bddSHONG Yifan 
resolver_2_deps_metadata() -> cargo_metadata::Metadata166*d4726bddSHONG Yifan     pub(crate) fn resolver_2_deps_metadata() -> cargo_metadata::Metadata {
167*d4726bddSHONG Yifan         serde_json::from_str(include_str!(concat!(
168*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
169*d4726bddSHONG Yifan             "/test_data/metadata/resolver_2_deps/metadata.json"
170*d4726bddSHONG Yifan         )))
171*d4726bddSHONG Yifan         .unwrap()
172*d4726bddSHONG Yifan     }
173*d4726bddSHONG Yifan }
174*d4726bddSHONG Yifan 
175*d4726bddSHONG Yifan pub(crate) mod lockfile {
176*d4726bddSHONG Yifan     use std::str::FromStr;
177*d4726bddSHONG Yifan 
alias() -> cargo_lock::Lockfile178*d4726bddSHONG Yifan     pub(crate) fn alias() -> cargo_lock::Lockfile {
179*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
180*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
181*d4726bddSHONG Yifan             "/test_data/metadata/aliases/Cargo.lock"
182*d4726bddSHONG Yifan         )))
183*d4726bddSHONG Yifan         .unwrap()
184*d4726bddSHONG Yifan     }
185*d4726bddSHONG Yifan 
build_scripts() -> cargo_lock::Lockfile186*d4726bddSHONG Yifan     pub(crate) fn build_scripts() -> cargo_lock::Lockfile {
187*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
188*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
189*d4726bddSHONG Yifan             "/test_data/metadata/build_scripts/Cargo.lock"
190*d4726bddSHONG Yifan         )))
191*d4726bddSHONG Yifan         .unwrap()
192*d4726bddSHONG Yifan     }
193*d4726bddSHONG Yifan 
crate_types() -> cargo_lock::Lockfile194*d4726bddSHONG Yifan     pub(crate) fn crate_types() -> cargo_lock::Lockfile {
195*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
196*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
197*d4726bddSHONG Yifan             "/test_data/metadata/crate_types/Cargo.lock"
198*d4726bddSHONG Yifan         )))
199*d4726bddSHONG Yifan         .unwrap()
200*d4726bddSHONG Yifan     }
201*d4726bddSHONG Yifan 
multi_cfg_dep() -> cargo_lock::Lockfile202*d4726bddSHONG Yifan     pub(crate) fn multi_cfg_dep() -> cargo_lock::Lockfile {
203*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
204*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
205*d4726bddSHONG Yifan             "/test_data/metadata/multi_cfg_dep/Cargo.lock"
206*d4726bddSHONG Yifan         )))
207*d4726bddSHONG Yifan         .unwrap()
208*d4726bddSHONG Yifan     }
209*d4726bddSHONG Yifan 
no_deps() -> cargo_lock::Lockfile210*d4726bddSHONG Yifan     pub(crate) fn no_deps() -> cargo_lock::Lockfile {
211*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
212*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
213*d4726bddSHONG Yifan             "/test_data/metadata/no_deps/Cargo.lock"
214*d4726bddSHONG Yifan         )))
215*d4726bddSHONG Yifan         .unwrap()
216*d4726bddSHONG Yifan     }
217*d4726bddSHONG Yifan 
common() -> cargo_lock::Lockfile218*d4726bddSHONG Yifan     pub(crate) fn common() -> cargo_lock::Lockfile {
219*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
220*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
221*d4726bddSHONG Yifan             "/test_data/metadata/common/Cargo.lock"
222*d4726bddSHONG Yifan         )))
223*d4726bddSHONG Yifan         .unwrap()
224*d4726bddSHONG Yifan     }
225*d4726bddSHONG Yifan 
git_repos() -> cargo_lock::Lockfile226*d4726bddSHONG Yifan     pub(crate) fn git_repos() -> cargo_lock::Lockfile {
227*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
228*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
229*d4726bddSHONG Yifan             "/test_data/metadata/git_repos/Cargo.lock"
230*d4726bddSHONG Yifan         )))
231*d4726bddSHONG Yifan         .unwrap()
232*d4726bddSHONG Yifan     }
233*d4726bddSHONG Yifan 
has_package_metadata() -> cargo_lock::Lockfile234*d4726bddSHONG Yifan     pub(crate) fn has_package_metadata() -> cargo_lock::Lockfile {
235*d4726bddSHONG Yifan         cargo_lock::Lockfile::from_str(include_str!(concat!(
236*d4726bddSHONG Yifan             env!("CARGO_MANIFEST_DIR"),
237*d4726bddSHONG Yifan             "/test_data/metadata/has_package_metadata/Cargo.lock"
238*d4726bddSHONG Yifan         )))
239*d4726bddSHONG Yifan         .unwrap()
240*d4726bddSHONG Yifan     }
241*d4726bddSHONG Yifan }
242