Skip to content

Commit 1cfd71a

Browse files
committed
Add UI cases to check SBOM output
* check UI cases for sbom output * use locally published package instead of fetching crate from crates.io index
1 parent 54e7cd6 commit 1cfd71a

File tree

21 files changed

+237
-4
lines changed

21 files changed

+237
-4
lines changed

tests/testsuite/cargo_build/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
mod help;
2+
mod sbom_single_binary;
3+
mod sbom_with_build_dependencies;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
sbom = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "foo"
3+
version = "0.0.1"
4+
authors = []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::current_dir;
3+
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
5+
use cargo_test_support::Project;
6+
7+
#[cargo_test]
8+
fn case() {
9+
let project: Project = Project::from_template(current_dir!().join("in"));
10+
let project_root = project.root();
11+
let cwd = &project_root;
12+
13+
snapbox::cmd::Command::cargo_ui()
14+
.arg("build")
15+
.masquerade_as_nightly_cargo(&["-Zsbom"])
16+
.args(&["-Z", "sbom"])
17+
.current_dir(cwd)
18+
.assert()
19+
.success()
20+
.stdout_matches(file!("stdout.log"))
21+
.stderr_matches(file!("stderr.log"));
22+
23+
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
24+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"format_version": 1,
3+
"package_id": "path+[ROOTURL]/case#[email protected]",
4+
"name": "foo",
5+
"version": "0.0.1",
6+
"source": "[ROOT]/case",
7+
"target": {
8+
"kind": [
9+
"bin"
10+
],
11+
"crate_type": "bin",
12+
"name": "foo",
13+
"edition": "2015"
14+
},
15+
"profile": {
16+
"name": "dev",
17+
"opt_level": "0",
18+
"lto": "false",
19+
"codegen_backend": null,
20+
"codegen_units": null,
21+
"debuginfo": 2,
22+
"split_debuginfo": "unpacked",
23+
"debug_assertions": true,
24+
"overflow_checks": true,
25+
"rpath": false,
26+
"incremental": false,
27+
"panic": "unwind",
28+
"strip": {
29+
"deferred": "None"
30+
}
31+
},
32+
"packages": [],
33+
"features": [],
34+
"rustc": {
35+
"version": "[..]",
36+
"wrapper": null,
37+
"commit_hash": "9b00956e56009bab2aa15d7bff10916599e3d6d6",
38+
"host": "[..]"
39+
}
40+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[..] foo v0.0.1 ([ROOT]/case)
2+
[..] `dev` profile [unoptimized + debuginfo] target(s) in [..]

tests/testsuite/cargo_build/sbom_single_binary/stdout.log

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
sbom = true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "foo"
3+
version = "0.0.1"
4+
authors = []
5+
6+
[dependencies]
7+
bar = { path = "./bar" }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "bar"
3+
version = "0.1.0"
4+
build = "build.rs"
5+
6+
[build-dependencies]
7+
baz = { path = "../baz" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("cargo::rustc-cfg=foo");
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn bar() -> i32 {
2+
2
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "baz"
3+
version = "0.1.0"
4+
authors = []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn hello() {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
let _i = bar::bar();
3+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::current_dir;
3+
use cargo_test_support::file;
4+
use cargo_test_support::prelude::*;
5+
use cargo_test_support::Project;
6+
7+
#[cargo_test]
8+
fn case() {
9+
let project: Project = Project::from_template(current_dir!().join("in"));
10+
let project_root = project.root();
11+
let cwd = &project_root;
12+
13+
snapbox::cmd::Command::cargo_ui()
14+
.arg("build")
15+
.masquerade_as_nightly_cargo(&["-Zsbom"])
16+
.args(&["-Z", "sbom"])
17+
.current_dir(cwd)
18+
.assert()
19+
.success()
20+
.stdout_matches(file!("stdout.log"))
21+
.stderr_matches(file!("stderr.log"));
22+
23+
assert_ui().subset_matches(current_dir!().join("out"), &project_root);
24+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"format_version": 1,
3+
"package_id": "path+[ROOTURL]/case#[email protected]",
4+
"name": "foo",
5+
"version": "0.0.1",
6+
"source": "[ROOT]/case",
7+
"target": {
8+
"kind": [
9+
"bin"
10+
],
11+
"crate_type": "bin",
12+
"name": "foo",
13+
"edition": "2015"
14+
},
15+
"profile": {
16+
"name": "dev",
17+
"opt_level": "0",
18+
"lto": "false",
19+
"codegen_backend": null,
20+
"codegen_units": null,
21+
"debuginfo": 2,
22+
"split_debuginfo": "unpacked",
23+
"debug_assertions": true,
24+
"overflow_checks": true,
25+
"rpath": false,
26+
"incremental": false,
27+
"panic": "unwind",
28+
"strip": {
29+
"deferred": "None"
30+
}
31+
},
32+
"packages": [
33+
{
34+
"package_id": "bar 0.1.0 (path+[ROOTURL]/case/bar)",
35+
"package": "bar",
36+
"version": "0.1.0",
37+
"features": [],
38+
"build_type": "normal",
39+
"extern_crate_name": "bar",
40+
"dependencies": [
41+
{
42+
"name": "bar",
43+
"package_id": "bar 0.1.0 (path+[ROOTURL]/case/bar)",
44+
"version": "0.1.0",
45+
"features": []
46+
}
47+
]
48+
},
49+
{
50+
"package_id": "bar 0.1.0 (path+[ROOTURL]/case/bar)",
51+
"package": "bar",
52+
"version": "0.1.0",
53+
"features": [],
54+
"build_type": "build",
55+
"extern_crate_name": "build_script_build",
56+
"dependencies": [
57+
{
58+
"name": "bar",
59+
"package_id": "bar 0.1.0 (path+[ROOTURL]/case/bar)",
60+
"version": "0.1.0",
61+
"features": []
62+
}
63+
]
64+
},
65+
{
66+
"package_id": "bar 0.1.0 (path+[ROOTURL]/case/bar)",
67+
"package": "bar",
68+
"version": "0.1.0",
69+
"features": [],
70+
"build_type": "normal",
71+
"extern_crate_name": "build_script_build",
72+
"dependencies": [
73+
{
74+
"name": "baz",
75+
"package_id": "baz 0.1.0 (path+[ROOTURL]/case/baz)",
76+
"version": "0.1.0",
77+
"features": []
78+
}
79+
]
80+
},
81+
{
82+
"package_id": "baz 0.1.0 (path+[ROOTURL]/case/baz)",
83+
"package": "baz",
84+
"version": "0.1.0",
85+
"features": [],
86+
"build_type": "normal",
87+
"extern_crate_name": "baz",
88+
"dependencies": []
89+
}
90+
],
91+
"features": [],
92+
"rustc": {
93+
"version": "[..]",
94+
"wrapper": null,
95+
"commit_hash": "9b00956e56009bab2aa15d7bff10916599e3d6d6",
96+
"host": "[..]"
97+
}
98+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[..] 3 packages to latest compatible versions
2+
[..] baz v0.1.0 ([ROOT]/case/baz)
3+
[..] bar v0.1.0 ([ROOT]/case/bar)
4+
[..] foo v0.0.1 ([ROOT]/case)
5+
[..] `dev` profile [unoptimized + debuginfo] target(s) in [..]

tests/testsuite/cargo_build/sbom_with_build_dependencies/stdout.log

Whitespace-only changes.

tests/testsuite/sbom.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tests for cargo-sbom precursor files.
22
3-
use cargo_test_support::{basic_bin_manifest, project, ProjectBuilder};
3+
use cargo_test_support::{basic_bin_manifest, project, registry::Package, ProjectBuilder};
44

55
fn configured_project() -> ProjectBuilder {
66
project().file(
@@ -89,8 +89,8 @@ fn build_sbom_project_bin_and_lib() {
8989

9090
assert!(p.bin("foo").with_extension("cargo-sbom.json").is_file());
9191
assert_eq!(
92-
1,
93-
p.glob(p.target_debug_dir().join("libfoo.cargo-sbom.json"))
92+
2,
93+
p.glob(p.target_debug_dir().join("*.cargo-sbom.json"))
9494
.count()
9595
);
9696
}
@@ -149,14 +149,15 @@ fn build_sbom_with_build_dependencies() {
149149
build = "build.rs"
150150
151151
[build-dependencies]
152-
cc = "1.0.46"
152+
baz = "0.0.1"
153153
"#,
154154
)
155155
.file(
156156
"bar/build.rs",
157157
r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#,
158158
)
159159
.build();
160+
Package::new("baz", "0.0.1").publish();
160161

161162
p.cargo("build -Zsbom")
162163
.masquerade_as_nightly_cargo(&["sbom"])

0 commit comments

Comments
 (0)