1
1
//! Tests for cargo-sbom precursor files.
2
2
3
- use std:: { fs:: File , io:: BufReader , path:: Path } ;
4
-
5
3
use cargo_test_support:: { basic_bin_manifest, project, ProjectBuilder } ;
6
4
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
-
13
5
fn configured_project ( ) -> ProjectBuilder {
14
6
project ( ) . file (
15
7
".cargo/config.toml" ,
@@ -21,15 +13,29 @@ fn configured_project() -> ProjectBuilder {
21
13
}
22
14
23
15
#[ cargo_test]
24
- fn build_sbom_using_cargo_config ( ) {
25
- let p = project ( )
26
- . file (
27
- ".cargo/config.toml" ,
28
- r#"
29
- [build]
30
- sbom = true
31
- "# ,
16
+ fn build_sbom_without_passing_unstable_flag ( ) {
17
+ let p = configured_project ( )
18
+ . file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
19
+ . file ( "src/main.rs" , r#"fn main() {}"# )
20
+ . build ( ) ;
21
+
22
+ p. cargo ( "build" )
23
+ . masquerade_as_nightly_cargo ( & [ "sbom" ] )
24
+ . with_stderr (
25
+ "\
26
+ warning: ignoring 'sbom' config, pass `-Zsbom` to enable it\n \
27
+ [COMPILING] foo v0.5.0 ([..])\n \
28
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]\n ",
32
29
)
30
+ . run ( ) ;
31
+
32
+ let file = p. bin ( "foo" ) . with_extension ( "cargo-sbom.json" ) ;
33
+ assert ! ( !file. exists( ) ) ;
34
+ }
35
+
36
+ #[ cargo_test]
37
+ fn build_sbom_using_cargo_config ( ) {
38
+ let p = configured_project ( )
33
39
. file ( "Cargo.toml" , & basic_bin_manifest ( "foo" ) )
34
40
. file ( "src/main.rs" , r#"fn main() {}"# )
35
41
. build ( ) ;
@@ -115,9 +121,6 @@ fn build_sbom_with_simple_build_script() {
115
121
116
122
let path = p. bin ( "foo" ) . with_extension ( "cargo-sbom.json" ) ;
117
123
assert ! ( path. is_file( ) ) ;
118
-
119
- let _json = read_json ( path) . expect ( "Failed to read JSON" ) ;
120
- // TODO: check SBOM output
121
124
}
122
125
123
126
#[ cargo_test]
@@ -158,7 +161,7 @@ fn build_sbom_with_build_dependencies() {
158
161
p. cargo ( "build -Zsbom" )
159
162
. masquerade_as_nightly_cargo ( & [ "sbom" ] )
160
163
. run ( ) ;
164
+
161
165
let path = p. bin ( "foo" ) . with_extension ( "cargo-sbom.json" ) ;
162
- let _json = read_json ( path) . expect ( "Failed to read JSON" ) ;
163
- // TODO: check SBOM output
166
+ assert ! ( path. is_file( ) ) ;
164
167
}
0 commit comments