File tree 7 files changed +43
-6
lines changed
test_crates/crate_in_workspace
7 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -216,7 +216,11 @@ impl Scope {
216
216
217
217
meta. packages
218
218
. iter ( )
219
- . filter ( |& p| base_ids. contains ( & p. id ) )
219
+ . filter ( |& p| {
220
+ // The package has to not have been explicitly excluded,
221
+ // and also has to have a library target (an API we can check).
222
+ base_ids. contains ( & p. id ) && p. targets . iter ( ) . any ( |target| target. is_lib ( ) )
223
+ } )
220
224
. collect ( )
221
225
}
222
226
}
@@ -437,6 +441,12 @@ impl Check {
437
441
RustdocSource :: Root ( project_root) => {
438
442
let metadata = manifest_metadata ( project_root) ?;
439
443
let selected = self . scope . selected_packages ( & metadata) ;
444
+ if selected. is_empty ( ) {
445
+ anyhow:: bail!(
446
+ "no crates with library targets selected, nothing to semver-check"
447
+ ) ;
448
+ }
449
+
440
450
selected
441
451
. iter ( )
442
452
. map ( |selected| {
Original file line number Diff line number Diff line change 1
1
[workspace ]
2
- members = [" crate1 " ]
2
+ members = [" lib_crate " , " non_lib_crate " ]
3
3
4
4
[workspace .package ]
5
5
version = " 0.1.0"
Original file line number Diff line number Diff line change 1
1
[package ]
2
2
publish = false
3
- name = " crate_in_workspace_crate1 "
3
+ name = " lib_crate "
4
4
version = { workspace = true }
5
5
6
6
[dependencies ]
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " non_lib_crate"
3
+ edition = " 2021"
4
+ version.workspace = true
5
+
6
+ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
+
8
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ fn main ( ) { }
Original file line number Diff line number Diff line change @@ -24,14 +24,16 @@ fn lib_target_with_dashes() {
24
24
. success ( ) ;
25
25
}
26
26
27
- /// Ensure that proc macro crates can be semver-checked correctly.
27
+ /// Ensure that proc macro crates without a lib target produce the correct error message
28
+ /// since they have no library API and therefore nothing we can semver-check.
28
29
#[ test]
29
30
fn proc_macro_target ( ) {
30
31
let mut cmd = Command :: cargo_bin ( "cargo-semver-checks" ) . unwrap ( ) ;
31
32
cmd. current_dir ( "test_crates/proc_macro_crate" )
32
33
. args ( [ "semver-checks" , "check-release" , "--baseline-root=." ] )
33
34
. assert ( )
34
- . success ( ) ;
35
+ . stderr ( "Error: no crates with library targets selected, nothing to semver-check\n " )
36
+ . failure ( ) ;
35
37
}
36
38
37
39
/// Ensure that crates whose lib targets have a different name can be semver-checked correctly.
@@ -69,11 +71,27 @@ fn crate_in_workspace() {
69
71
"check-release" ,
70
72
"--manifest-path=./Cargo.toml" ,
71
73
"-p" ,
72
- "crate1 " ,
74
+ "lib_crate " ,
73
75
"--baseline-root=." ,
74
76
] )
75
77
. assert ( )
76
78
. success ( ) ;
79
+
80
+ // Run at workspace level then point out a crate without a lib target.
81
+ // This should produce an error and a non-zero exit code.
82
+ let mut cmd = Command :: cargo_bin ( "cargo-semver-checks" ) . unwrap ( ) ;
83
+ cmd. current_dir ( "test_crates/crate_in_workspace" )
84
+ . args ( [
85
+ "semver-checks" ,
86
+ "check-release" ,
87
+ "--manifest-path=./Cargo.toml" ,
88
+ "-p" ,
89
+ "non_lib_crate" ,
90
+ "--baseline-root=." ,
91
+ ] )
92
+ . assert ( )
93
+ . stderr ( "Error: no crates with library targets selected, nothing to semver-check\n " )
94
+ . failure ( ) ;
77
95
}
78
96
79
97
/// This test ensures that the `--release-type` flag works correctly,
You can’t perform that action at this time.
0 commit comments