File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1
1
//! Tests for cargo-sbom precursor files.
2
2
3
+ use std:: { fs:: File , io:: BufReader , path:: Path } ;
4
+
3
5
use cargo_test_support:: { basic_bin_manifest, project, ProjectBuilder } ;
4
6
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
+
5
13
fn configured_project ( ) -> ProjectBuilder {
6
14
project ( ) . file (
7
15
".cargo/config.toml" ,
@@ -73,3 +81,32 @@ fn build_sbom_project_bin_and_lib() {
73
81
. count( )
74
82
) ;
75
83
}
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
+ }
You can’t perform that action at this time.
0 commit comments