Skip to content

Commit

Permalink
add no lib targets test (#847)
Browse files Browse the repository at this point in the history
* Add snapshot testing with `insta`

* temporary dead code allows

* explicitly disable backtraces

* use `insta_cmd` for command snapshots

* move snapshot tests to lib tests

* add snapshot bin test harness

* Revert "move snapshot tests to lib tests"

This reverts commit 72f99bc.

* Add test for no lib targets in the workspace

* move snapshot outputs to lib tests

* move snapshots directory to lib tests

* Revert "move snapshots directory to lib tests"

This reverts commit b56a113.

* Revert "move snapshot outputs to lib tests"

This reverts commit 8b6494c.

* add test files

* Add snapshot testing with `insta`

* temporary dead code allows

* explicitly disable backtraces

* use `insta_cmd` for command snapshots

* move snapshot tests to lib tests

* add snapshot bin test harness

* fix docs

* clippy fixes

* fix merge ;(

* ...

* remove old test file

* unformat Cargo.toml

* clean up
  • Loading branch information
suaviloquence authored Aug 16, 2024
1 parent 329c42f commit 0ed4827
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ impl fmt::Display for CommandResult {
/// `test_outputs/snapshot_tests/{test_name}-{"args" | "output"}.snap
/// - `invocation` is a list of arguments of the command line invocation,
/// starting with `["cargo", "semver-checks"]`.
#[allow(dead_code)] // TODO
fn assert_integration_test(test_name: &str, invocation: &[&str]) {
// remove the backtrace environment variable, as this may cause non-
// reproducible snapshots.
Expand Down Expand Up @@ -176,3 +175,23 @@ fn assert_integration_test(test_name: &str, invocation: &[&str]) {

insta::assert_snapshot!(format!("{test_name}-output"), result);
}

/// [#163](/~https://github.com/obi1kenobi/cargo-semver-checks/issues/163)
///
/// Running `cargo semver-checks --workspace` on a workspace that doesn't
/// have any library targets should be an error.
#[test]
fn workspace_no_lib_targets_error() {
assert_integration_test(
"workspace_no_lib_targets",
&[
"cargo",
"semver-checks",
"--manifest-path",
"test_crates/manifest_tests/no_lib_targets/new",
"--baseline-root",
"test_crates/manifest_tests/no_lib_targets/old",
"--workspace",
],
);
}
3 changes: 3 additions & 0 deletions test_crates/manifest_tests/no_lib_targets/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["bin_only"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "bin_only"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
3 changes: 3 additions & 0 deletions test_crates/manifest_tests/no_lib_targets/old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["bin_only"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "bin_only"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: src/snapshot_tests.rs
expression: check
---
Check(
scope: Scope(
mode: DenyList(PackageSelection(
selection: Workspace,
excluded_packages: [],
)),
),
current: Rustdoc(
source: Root("test_crates/manifest_tests/no_lib_targets/new"),
),
baseline: Rustdoc(
source: Root("test_crates/manifest_tests/no_lib_targets/old"),
),
release_type: None,
current_feature_config: FeatureConfig(
features_group: Heuristic,
extra_features: [],
is_baseline: false,
),
baseline_feature_config: FeatureConfig(
features_group: Heuristic,
extra_features: [],
is_baseline: true,
),
build_target: None,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: src/snapshot_tests.rs
expression: result
---
--- error ---
no crates with library targets selected, nothing to semver-check
note: only library targets contain an API surface that can be checked for semver
note: skipped the following crates since they have no library target: bin_only

0 comments on commit 0ed4827

Please sign in to comment.