summaryrefslogtreecommitdiff
path: root/chromium/tools/crates/gnrt/manifest_unittest.rs
blob: 83b4d560991ea099617ce886ff3a0ce262464602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use rust_gtest_interop::prelude::*;

use gnrt_lib::manifest::*;

#[gtest(ManifestTest, ParseSingleFullDependency)]
fn test() {
    expect_eq!(
        toml::de::from_str(concat!(
            "version = \"1.0.0\"\n",
            "features = [\"foo\", \"bar\"]\n",
            "allow-first-party-usage = false\n",
            "build-script-outputs = [\"stuff.rs\"]\n",
        )),
        Ok(FullDependency {
            version: Some(VersionConstraint("1.0.0".to_string())),
            features: vec!["foo".to_string(), "bar".to_string()],
            allow_first_party_usage: false,
            build_script_outputs: vec!["stuff.rs".to_string()],
        })
    );

    expect_eq!(
        toml::de::from_str(concat!(
            "version = \"3.14.159\"\n",
            "build-script-outputs = [\"generated.rs\"]\n",
        )),
        Ok(FullDependency {
            version: Some(VersionConstraint("3.14.159".to_string())),
            features: vec![],
            allow_first_party_usage: true,
            build_script_outputs: vec!["generated.rs".to_string()],
        })
    );
}

#[gtest(ManifestTest, ParseManifest)]
fn test() {
    let manifest: ThirdPartyManifest = toml::de::from_str(concat!(
        "[dependencies]\n",
        "cxx = \"1\"\n",
        "serde = \"1\"\n",
        "rustversion = {version = \"1\", build-script-outputs = [\"version.rs\"]}",
        "\n",
        "[dependencies.unicode-linebreak]\n",
        "version = \"0.1\"\n",
        "allow-first-party-usage = false\n",
        "build-script-outputs = [ \"table.rs\" ]\n",
        "\n",
        "[dev-dependencies]\n",
        "syn = {version = \"1\", features = [\"full\"]}\n",
    ))
    .unwrap();

    expect_eq!(
        manifest.dependency_spec.dependencies.get("cxx"),
        Some(&Dependency::Short(VersionConstraint("1".to_string())))
    );
    expect_eq!(
        manifest.dependency_spec.dependencies.get("serde"),
        Some(&Dependency::Short(VersionConstraint("1".to_string())))
    );

    expect_eq!(
        manifest.dependency_spec.dependencies.get("rustversion"),
        Some(&Dependency::Full(FullDependency {
            version: Some(VersionConstraint("1".to_string())),
            features: vec![],
            allow_first_party_usage: true,
            build_script_outputs: vec!["version.rs".to_string()],
        }))
    );

    expect_eq!(
        manifest.dependency_spec.dependencies.get("unicode-linebreak"),
        Some(&Dependency::Full(FullDependency {
            version: Some(VersionConstraint("0.1".to_string())),
            features: vec![],
            allow_first_party_usage: false,
            build_script_outputs: vec!["table.rs".to_string()],
        }))
    );

    expect_eq!(
        manifest.dependency_spec.dev_dependencies.get("syn"),
        Some(&Dependency::Full(FullDependency {
            version: Some(VersionConstraint("1".to_string())),
            features: vec!["full".to_string()],
            allow_first_party_usage: true,
            build_script_outputs: vec![],
        }))
    );
}

#[gtest(ManifestTest, SerializeManifestWithPatches)]
fn test() {
    let manifest = CargoManifest {
        package: CargoPackage {
            name: "chromium".to_string(),
            version: Version::new(0, 1, 0),
            authors: Vec::new(),
            edition: Edition("2021".to_string()),
            description: None,
            license: "funtimes".to_string(),
        },
        workspace: None,
        dependency_spec: DependencySpec {
            dependencies: DependencySet::new(),
            dev_dependencies: DependencySet::new(),
            build_dependencies: DependencySet::new(),
        },
        patches: vec![(
            "crates-io".to_string(),
            vec![(
                "foo_v1".to_string(),
                CargoPatch {
                    path: "third_party/rust/foo/v1/crate".to_string(),
                    package: "foo".to_string(),
                },
            )]
            .into_iter()
            .collect(),
        )]
        .into_iter()
        .collect(),
    };

    expect_eq!(
        toml::to_string(&manifest).unwrap(),
        "[package]
name = \"chromium\"
version = \"0.1.0\"
edition = \"2021\"
license = \"funtimes\"
[patch.crates-io.foo_v1]
path = \"third_party/rust/foo/v1/crate\"
package = \"foo\"
"
    )
}

#[gtest(ManifestTest, PackageManifest)]
fn test() {
    let manifest: CargoManifest = toml::de::from_str(concat!(
        "[package]
name = \"foo\"
version = \"1.2.3\"
authors = [\"alice@foo.com\", \"bob@foo.com\"]
edition = \"2021\"
description = \"A library to foo the bars\"
license = \"funtimes\"
"
    ))
    .unwrap();

    expect_eq!(
        manifest.package,
        CargoPackage {
            name: "foo".to_string(),
            version: Version::new(1, 2, 3),
            authors: vec!["alice@foo.com".to_string(), "bob@foo.com".to_string()],
            edition: Edition("2021".to_string()),
            description: Some("A library to foo the bars".to_string()),
            license: "funtimes".to_string(),
        }
    )
}