Skip to content

Commit

Permalink
Add snapshot test for when a workspace member's baseline has a compil…
Browse files Browse the repository at this point in the history
…e error. (#882)

* add test when a workspace member's baseline has a compile error

* rerun snapshot

* experiment: set CARGO_TERM_VERBOSE to false explicitly

* try quiet

* skip test on < cargo 1.78
  • Loading branch information
suaviloquence authored Aug 23, 2024
1 parent c2dfe22 commit 6e5d78a
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use std::{

use cargo_semver_checks::{Check, GlobalConfig};
use clap::Parser as _;
use semver::Version;

use crate::Cargo;

Expand Down Expand Up @@ -303,3 +304,35 @@ fn workspace_publish_false_workspace_flag() {
],
)
}

/// When a workspace has a crate with a compile error in the baseline version
/// and the user request to semver-check the `--workspace`, which has other workspace
/// members that do not have compile errors.
///
/// Currently, the workspace `semver-checks` all non-error workspace members but returns
/// an error at the end.
#[test]
fn workspace_baseline_compile_error() {
// HACK: the `cargo doc` error output changed from cargo 1.77 to 1.78, and the snapshot
// does not work for older versions
if rustc_version::version().map_or(true, |version| version < Version::new(1, 78, 0)) {
eprintln!(
"Skipping this test as `cargo doc` output is different in earlier versions.
Consider rerunning with cargo >= 1.78"
);
return;
}

assert_integration_test(
"workspace_baseline_compile_error",
&[
"cargo",
"semver-checks",
"--baseline-root",
"test_crates/manifest_tests/workspace_baseline_compile_error/old",
"--manifest-path",
"test_crates/manifest_tests/workspace_baseline_compile_error/new",
"--workspace",
],
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["error", "no-error"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "error"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Has a compile error in the baseline version,
//! so we can't generate the rustdoc JSON to
//! run semver-checks on
// in baseline:
// compile_error!("This crate has a compiler error.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "no-error"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! This crate removes the function `my_fn` in the new version
//! which is a `function_missing` major semver error.
// removed in new version:
// pub fn my_fn() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = ["error", "no-error"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "error"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Has a compile error in the baseline version,
//! so we can't generate the rustdoc JSON to
//! run semver-checks on
compile_error!("This crate has a compiler error.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "no-error"
version = "0.1.0"
edition = "2021"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! This crate removes the function `my_fn` in the new version
//! which is a `function_missing` major semver error.
pub fn my_fn() {}
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/workspace_baseline_compile_error/new"),
),
baseline: Rustdoc(
source: Root("test_crates/manifest_tests/workspace_baseline_compile_error/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,54 @@
---
source: src/snapshot_tests.rs
expression: result
---
--- error ---
aborting due to failure to build rustdoc for crate error v0.1.0
--- stdout ---

--- failure function_missing: pub fn removed or renamed ---

Description:
A publicly-visible function cannot be imported by its prior path. A `pub use` may have been removed, or the function itself may have been renamed or removed entirely.
ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.34.0/src/lints/function_missing.ron

Failed in:
function no_error::my_fn, previously in file [ROOT]/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/src/lib.rs:3

--- stderr ---
Parsing error v0.1.0 (current)
Parsed [TIME] (current)
Parsing error v0.1.0 (baseline)
error: running cargo-doc on crate error failed with output:
-----
Documenting error v0.1.0 ([ROOT]/test_crates/manifest_tests/workspace_baseline_compile_error/old/error)
error: This crate has a compiler error.
--> [ROOT]/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/src/lib.rs:4:1
|
4 | compile_error!("This crate has a compiler error.");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not document `error`

-----

error: failed to build rustdoc for crate error v0.1.0
note: this is usually due to a compilation error in the crate,
and is unlikely to be a bug in cargo-semver-checks
note: the following command can be used to reproduce the compilation error:
cargo new --lib example &&
cd example &&
echo '[workspace]' >> Cargo.toml &&
cargo add --path test_crates/manifest_tests/workspace_baseline_compile_error/old/error --no-default-features &&
cargo check

Parsing no-error v0.1.0 (current)
Parsed [TIME] (current)
Parsing no-error v0.1.0 (baseline)
Parsed [TIME] (baseline)
Checking no-error v0.1.0 -> v0.1.0 (no change)
Checked [TIME] [TOTAL] checks: [PASS] pass, 1 fail, 0 warn, 0 skip

Summary semver requires new major version: 1 major and 0 minor checks failed
Finished [TIME] no-error

0 comments on commit 6e5d78a

Please sign in to comment.