Skip to content

Commit 27003f3

Browse files
committed
Add test to read JSON
Still needs to check output.
1 parent b16b37b commit 27003f3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/testsuite/sbom.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
//! Tests for cargo-sbom precursor files.
22
3+
use std::{fs::File, io::BufReader, path::Path};
4+
35
use cargo_test_support::{basic_bin_manifest, project, ProjectBuilder};
46

7+
fn read_json<P: AsRef<Path>>(path: P) -> anyhow::Result<serde_json::Value> {
8+
let file = File::open(path)?;
9+
let reader = BufReader::new(file);
10+
Ok(serde_json::from_reader(reader)?)
11+
}
12+
513
fn configured_project() -> ProjectBuilder {
614
project().file(
715
".cargo/config.toml",
@@ -73,3 +81,32 @@ fn build_sbom_project_bin_and_lib() {
7381
.count()
7482
);
7583
}
84+
85+
#[cargo_test]
86+
fn build_sbom_with_simple_build_script() {
87+
let p = configured_project()
88+
.file(
89+
"Cargo.toml",
90+
r#"
91+
[package]
92+
name = "foo"
93+
version = "0.0.1"
94+
authors = []
95+
build = "build.rs"
96+
"#,
97+
)
98+
.file("src/main.rs", "#[cfg(foo)] fn main() {}")
99+
.file(
100+
"build.rs",
101+
r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#,
102+
)
103+
.build();
104+
105+
p.cargo("build").stream().run();
106+
107+
let path = p.bin("foo").with_extension("cargo-sbom.json");
108+
assert!(path.is_file());
109+
110+
let json = read_json(path).expect("Failed to read JSON");
111+
dbg!(&json);
112+
}

0 commit comments

Comments
 (0)