From 74dafa0b00573135f22cc3c9adf88476d97d849e Mon Sep 17 00:00:00 2001 From: Sebastian Ziebell Date: Fri, 5 Apr 2024 11:00:18 +0200 Subject: [PATCH] Add test with custom build script --- tests/testsuite/sbom.rs | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/sbom.rs b/tests/testsuite/sbom.rs index 4a7010331110..99668b6ffd76 100644 --- a/tests/testsuite/sbom.rs +++ b/tests/testsuite/sbom.rs @@ -119,5 +119,49 @@ fn build_sbom_with_simple_build_script() { assert!(path.is_file()); let json = read_json(path).expect("Failed to read JSON"); - dbg!(&json); + // TODO: check SBOM output +} + +#[cargo_test] +fn build_sbom_with_build_dependencies() { + let p = configured_project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = { path = "./bar" } + "#, + ) + .file("src/main.rs", "fn main() { let _i = bar::bar(); }") + .file("bar/src/lib.rs", "pub fn bar() -> i32 { 2 }") + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.0" + build = "build.rs" + + [build-dependencies] + cc = "1.0.46" + "#, + ) + .file( + "bar/build.rs", + r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#, + ) + .build(); + + p.cargo("build -Zsbom") + .stream() + .masquerade_as_nightly_cargo(&["sbom"]) + .run(); + let path = p.bin("foo").with_extension("cargo-sbom.json"); + let json = read_json(path).expect("Failed to read JSON"); + // TODO: check SBOM output }