From 6e5d78acf899dbb232060cfc525b7444a3d2f7e5 Mon Sep 17 00:00:00 2001 From: Max Carr Date: Thu, 22 Aug 2024 19:26:33 -0700 Subject: [PATCH] Add snapshot test for when a workspace member's baseline has a compile 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 --- src/snapshot_tests.rs | 33 ++++++++++++ .../new/Cargo.toml | 3 ++ .../new/error/Cargo.toml | 6 +++ .../new/error/src/lib.rs | 5 ++ .../new/no-error/Cargo.toml | 6 +++ .../new/no-error/src/lib.rs | 4 ++ .../old/Cargo.toml | 3 ++ .../old/error/Cargo.toml | 6 +++ .../old/error/src/lib.rs | 4 ++ .../old/no-error/Cargo.toml | 6 +++ .../old/no-error/src/lib.rs | 3 ++ ...orkspace_baseline_compile_error-input.snap | 30 +++++++++++ ...rkspace_baseline_compile_error-output.snap | 54 +++++++++++++++++++ 13 files changed, 163 insertions(+) create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/new/Cargo.toml create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/new/error/Cargo.toml create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/new/error/src/lib.rs create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/Cargo.toml create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/src/lib.rs create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/old/Cargo.toml create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/old/error/Cargo.toml create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/old/error/src/lib.rs create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/Cargo.toml create mode 100644 test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/src/lib.rs create mode 100644 test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-input.snap create mode 100644 test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-output.snap diff --git a/src/snapshot_tests.rs b/src/snapshot_tests.rs index 2238e0c2..48c182ce 100644 --- a/src/snapshot_tests.rs +++ b/src/snapshot_tests.rs @@ -50,6 +50,7 @@ use std::{ use cargo_semver_checks::{Check, GlobalConfig}; use clap::Parser as _; +use semver::Version; use crate::Cargo; @@ -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", + ], + ); +} diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/new/Cargo.toml b/test_crates/manifest_tests/workspace_baseline_compile_error/new/Cargo.toml new file mode 100644 index 00000000..4bcdf030 --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/new/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["error", "no-error"] diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/new/error/Cargo.toml b/test_crates/manifest_tests/workspace_baseline_compile_error/new/error/Cargo.toml new file mode 100644 index 00000000..b8706605 --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/new/error/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "error" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/new/error/src/lib.rs b/test_crates/manifest_tests/workspace_baseline_compile_error/new/error/src/lib.rs new file mode 100644 index 00000000..e22c39c9 --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/new/error/src/lib.rs @@ -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."); diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/Cargo.toml b/test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/Cargo.toml new file mode 100644 index 00000000..d198c31c --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "no-error" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/src/lib.rs b/test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/src/lib.rs new file mode 100644 index 00000000..196a25ef --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/new/no-error/src/lib.rs @@ -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() {} diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/old/Cargo.toml b/test_crates/manifest_tests/workspace_baseline_compile_error/old/Cargo.toml new file mode 100644 index 00000000..4bcdf030 --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/old/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["error", "no-error"] diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/Cargo.toml b/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/Cargo.toml new file mode 100644 index 00000000..b8706605 --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "error" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/src/lib.rs b/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/src/lib.rs new file mode 100644 index 00000000..c016ca13 --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/old/error/src/lib.rs @@ -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."); diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/Cargo.toml b/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/Cargo.toml new file mode 100644 index 00000000..d198c31c --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "no-error" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/src/lib.rs b/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/src/lib.rs new file mode 100644 index 00000000..654859ed --- /dev/null +++ b/test_crates/manifest_tests/workspace_baseline_compile_error/old/no-error/src/lib.rs @@ -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() {} diff --git a/test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-input.snap b/test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-input.snap new file mode 100644 index 00000000..3fafd558 --- /dev/null +++ b/test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-input.snap @@ -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, +) diff --git a/test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-output.snap b/test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-output.snap new file mode 100644 index 00000000..f832410e --- /dev/null +++ b/test_outputs/snapshot_tests/cargo_semver_checks__snapshot_tests__workspace_baseline_compile_error-output.snap @@ -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