blob: 1009b7e71b3fd0506f40277cbcd7f24629a73400 [file] [log] [blame]
Avi Drissmandfd880852022-09-15 20:11:091// Copyright 2022 The Chromium Authors
Collin Baker829a71252022-06-24 19:08:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use rust_gtest_interop::prelude::*;
6
7use gnrt_lib::manifest::*;
8
9#[gtest(ManifestTest, ParseSingleFullDependency)]
10fn test() {
11 expect_eq!(
12 toml::de::from_str(concat!(
13 "version = \"1.0.0\"\n",
14 "features = [\"foo\", \"bar\"]\n",
15 "allow-first-party-usage = false\n",
16 "build-script-outputs = [\"stuff.rs\"]\n",
danakj79e36022022-11-25 17:21:5617 "gn-variables-lib = \"\"\"
18 deps = []
19 configs = []
20 \"\"\""
Collin Baker829a71252022-06-24 19:08:2321 )),
22 Ok(FullDependency {
Collin Baker5e2e2022022-06-30 21:34:4323 version: Some(VersionConstraint("1.0.0".to_string())),
Collin Baker829a71252022-06-24 19:08:2324 features: vec!["foo".to_string(), "bar".to_string()],
25 allow_first_party_usage: false,
26 build_script_outputs: vec!["stuff.rs".to_string()],
danakj79e36022022-11-25 17:21:5627 gn_variables_lib: Some(
28 " deps = []\n configs = []\n ".to_string()
29 )
Collin Baker829a71252022-06-24 19:08:2330 })
31 );
32
33 expect_eq!(
34 toml::de::from_str(concat!(
35 "version = \"3.14.159\"\n",
36 "build-script-outputs = [\"generated.rs\"]\n",
37 )),
38 Ok(FullDependency {
Collin Baker5e2e2022022-06-30 21:34:4339 version: Some(VersionConstraint("3.14.159".to_string())),
Collin Baker829a71252022-06-24 19:08:2340 features: vec![],
41 allow_first_party_usage: true,
42 build_script_outputs: vec!["generated.rs".to_string()],
danakj79e36022022-11-25 17:21:5643 gn_variables_lib: None,
Collin Baker829a71252022-06-24 19:08:2344 })
45 );
46}
47
48#[gtest(ManifestTest, ParseManifest)]
49fn test() {
50 let manifest: ThirdPartyManifest = toml::de::from_str(concat!(
51 "[dependencies]\n",
52 "cxx = \"1\"\n",
53 "serde = \"1\"\n",
54 "rustversion = {version = \"1\", build-script-outputs = [\"version.rs\"]}",
55 "\n",
56 "[dependencies.unicode-linebreak]\n",
57 "version = \"0.1\"\n",
58 "allow-first-party-usage = false\n",
59 "build-script-outputs = [ \"table.rs\" ]\n",
60 "\n",
danakj79e36022022-11-25 17:21:5661 "[dependencies.special-stuff]\n",
62 "version = \"0.1\"\n",
63 "gn-variables-lib = \"hello = \\\"world\\\"\"\n",
64 "\n",
Collin Baker829a71252022-06-24 19:08:2365 "[dev-dependencies]\n",
66 "syn = {version = \"1\", features = [\"full\"]}\n",
67 ))
68 .unwrap();
69
70 expect_eq!(
71 manifest.dependency_spec.dependencies.get("cxx"),
Collin Baker5e2e2022022-06-30 21:34:4372 Some(&Dependency::Short(VersionConstraint("1".to_string())))
Collin Baker829a71252022-06-24 19:08:2373 );
74 expect_eq!(
75 manifest.dependency_spec.dependencies.get("serde"),
Collin Baker5e2e2022022-06-30 21:34:4376 Some(&Dependency::Short(VersionConstraint("1".to_string())))
Collin Baker829a71252022-06-24 19:08:2377 );
78
79 expect_eq!(
80 manifest.dependency_spec.dependencies.get("rustversion"),
81 Some(&Dependency::Full(FullDependency {
Collin Baker5e2e2022022-06-30 21:34:4382 version: Some(VersionConstraint("1".to_string())),
Collin Baker829a71252022-06-24 19:08:2383 features: vec![],
84 allow_first_party_usage: true,
85 build_script_outputs: vec!["version.rs".to_string()],
danakj79e36022022-11-25 17:21:5686 gn_variables_lib: None,
Collin Baker829a71252022-06-24 19:08:2387 }))
88 );
89
90 expect_eq!(
91 manifest.dependency_spec.dependencies.get("unicode-linebreak"),
92 Some(&Dependency::Full(FullDependency {
Collin Baker5e2e2022022-06-30 21:34:4393 version: Some(VersionConstraint("0.1".to_string())),
Collin Baker829a71252022-06-24 19:08:2394 features: vec![],
95 allow_first_party_usage: false,
96 build_script_outputs: vec!["table.rs".to_string()],
danakj79e36022022-11-25 17:21:5697 gn_variables_lib: None,
98 }))
99 );
100
101 expect_eq!(
102 manifest.dependency_spec.dependencies.get("special-stuff"),
103 Some(&Dependency::Full(FullDependency {
104 version: Some(VersionConstraint("0.1".to_string())),
105 features: vec![],
106 allow_first_party_usage: true,
107 build_script_outputs: vec![],
108 gn_variables_lib: Some("hello = \"world\"".to_string()),
Collin Baker829a71252022-06-24 19:08:23109 }))
110 );
111
112 expect_eq!(
113 manifest.dependency_spec.dev_dependencies.get("syn"),
114 Some(&Dependency::Full(FullDependency {
Collin Baker5e2e2022022-06-30 21:34:43115 version: Some(VersionConstraint("1".to_string())),
Collin Baker829a71252022-06-24 19:08:23116 features: vec!["full".to_string()],
117 allow_first_party_usage: true,
118 build_script_outputs: vec![],
danakj79e36022022-11-25 17:21:56119 gn_variables_lib: None,
Collin Baker829a71252022-06-24 19:08:23120 }))
121 );
122}
123
124#[gtest(ManifestTest, SerializeManifestWithPatches)]
125fn test() {
126 let manifest = CargoManifest {
127 package: CargoPackage {
128 name: "chromium".to_string(),
Collin Baker5e2e2022022-06-30 21:34:43129 version: Version::new(0, 1, 0),
Collin Baker8801618f2022-07-01 14:57:00130 authors: Vec::new(),
Collin Baker8a5b68722022-07-27 02:18:33131 edition: Edition("2021".to_string()),
Collin Baker8801618f2022-07-01 14:57:00132 description: None,
danakj171b5392022-09-29 21:26:54133 license: "funtimes".to_string(),
Collin Baker829a71252022-06-24 19:08:23134 },
135 workspace: None,
136 dependency_spec: DependencySpec {
137 dependencies: DependencySet::new(),
138 dev_dependencies: DependencySet::new(),
139 build_dependencies: DependencySet::new(),
140 },
141 patches: vec![(
142 "crates-io".to_string(),
143 vec![(
144 "foo_v1".to_string(),
145 CargoPatch {
146 path: "third_party/rust/foo/v1/crate".to_string(),
147 package: "foo".to_string(),
148 },
149 )]
150 .into_iter()
151 .collect(),
152 )]
153 .into_iter()
154 .collect(),
155 };
156
157 expect_eq!(
158 toml::to_string(&manifest).unwrap(),
159 "[package]
160name = \"chromium\"
161version = \"0.1.0\"
162edition = \"2021\"
danakj171b5392022-09-29 21:26:54163license = \"funtimes\"
Collin Baker829a71252022-06-24 19:08:23164[patch.crates-io.foo_v1]
165path = \"third_party/rust/foo/v1/crate\"
166package = \"foo\"
167"
168 )
169}
Collin Baker8801618f2022-07-01 14:57:00170
171#[gtest(ManifestTest, PackageManifest)]
172fn test() {
173 let manifest: CargoManifest = toml::de::from_str(concat!(
174 "[package]
175name = \"foo\"
176version = \"1.2.3\"
177authors = [\"alice@foo.com\", \"bob@foo.com\"]
178edition = \"2021\"
179description = \"A library to foo the bars\"
danakj171b5392022-09-29 21:26:54180license = \"funtimes\"
Collin Baker8801618f2022-07-01 14:57:00181"
182 ))
183 .unwrap();
184
185 expect_eq!(
186 manifest.package,
187 CargoPackage {
188 name: "foo".to_string(),
189 version: Version::new(1, 2, 3),
190 authors: vec!["[email protected]".to_string(), "[email protected]".to_string()],
191 edition: Edition("2021".to_string()),
192 description: Some("A library to foo the bars".to_string()),
danakj171b5392022-09-29 21:26:54193 license: "funtimes".to_string(),
Collin Baker8801618f2022-07-01 14:57:00194 }
195 )
196}