From 66cf7ae012703c2c060dc24bbe3748a66055ac40 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 22 Sep 2026 14:53:01 +0200 Subject: [PATCH 1/2] Refactor C++ tests for multiple classes --- .github/workflows/check.yml | 45 +++---------------- cpp-overload-test/build.rs | 7 ++- .../examples/stdcpp-forward-list.rs | 9 ++++ .../stdcpp-forward-list.stderr} | 6 +-- .../src/bin/std-forward-list-fail.rs | 3 -- cpp-overload-test/src/lib.rs | 11 +++++ .../forward_list.rs} | 5 +-- 7 files changed, 35 insertions(+), 51 deletions(-) create mode 100644 cpp-overload-test/examples/stdcpp-forward-list.rs rename cpp-overload-test/{src/bin/std-forward-list-fail.stderr => examples/stdcpp-forward-list.stderr} (59%) delete mode 100644 cpp-overload-test/src/bin/std-forward-list-fail.rs create mode 100644 cpp-overload-test/src/lib.rs rename cpp-overload-test/src/{bin/std-forward-list-ok.rs => stdcpp/forward_list.rs} (96%) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c207191..caa18ad 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -148,7 +148,7 @@ jobs: done cpp-overload-test-ok: - name: 9. Check Ok C++ overloads + name: 9. Check C++ overloads runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -157,17 +157,10 @@ jobs: toolchain: nightly # Use the same components in every step for caching components: cargo,clippy,rustfmt + # FIXME: turn this into a script so contributors can run it locally. - name: Check C++ overload ok cases - # FIXME: turn this into a script so contributors can run it locally. run: | - set -o pipefail - TEST_NAMES=$(find cpp-overload-test/src/bin -name "*-ok.rs" | \ - sed 's|.*/\([^/]*\).rs|\1|g' ) - echo "testing ok: $TEST_NAMES" - for test_name in $TEST_NAMES; do - echo "testing ok: $test_name" - cargo build --all-features --package cpp-overload-test --bin "$test_name" - done + cargo build --all-features --package cpp-overload-test cpp-overload-test-fail: name: 10. Must-fail C++ overloads @@ -180,13 +173,13 @@ jobs: # Use the same components in every step for caching components: cargo,clippy,rustfmt - name: Check C++ overload fail cases - # To bless (update the expected output), change '/tmp' to 'cpp-overload-test/src/bin', + # To bless (update the expected output), change '/tmp' to 'cpp-overload-test/examples', # and disable color output. # FIXME: turn this into a script so contributors can run it locally. run: | export CARGO_TERM_COLOR=never set -o pipefail - TEST_NAMES=$(find cpp-overload-test/src/bin -name "*-fail.rs" | \ + TEST_NAMES=$(find cpp-overload-test/examples -name "*.rs" | \ sed 's|.*/\([^/]*\).rs|\1|g' ) echo "testing incompatible overloads: $TEST_NAMES" for test_name in $TEST_NAMES; do @@ -194,7 +187,7 @@ jobs: # We expect cargo to fail, so don't exit the shell when it does set +e # Ignore build progress, if it's cached then the built crates change - cargo build --all-features --package cpp-overload-test --bin "$test_name" 2>&1 | \ + cargo build --all-features --package cpp-overload-test --example "$test_name" 2>&1 | \ grep --invert-match -e 'Updating .* index' -e 'Downloading .*' -e 'Downloaded .*' -e 'Compiling [^ ]* .*' \ > "/tmp/$test_name.stderr" CARGO_EXIT_CODE=$? @@ -204,31 +197,9 @@ jobs: exit 1 fi echo "comparing incompatible overload diagnostics for: $test_name" - diff --unified=5 "cpp-overload-test/src/bin/$test_name.stderr" /tmp/"$test_name.stderr" + diff --unified=5 "cpp-overload-test/examples/$test_name.stderr" /tmp/"$test_name.stderr" done - cpp-overload-file-names: - name: 11. Incorrect C++ overload file names - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 - with: - toolchain: nightly - # Use the same components in every step for caching - components: cargo,clippy,rustfmt - - name: Check C++ overload file names - # FIXME: turn this into a script so contributors can run it locally. - run: | - set -o pipefail - TEST_NAMES=$(find cpp-overload-test/src/bin -name "*.rs" -not -name "*-ok.rs" -not -name "*-fail.rs" | \ - sed 's|.*/\([^/]*\).rs|\1|g' ) - echo "incorrect file names: $TEST_NAMES" - if [[ -n "$TEST_NAMES" ]]; then - echo "error: incorrect file names found: all Rust files must be named *-ok.rs or *-fail.rs" - exit 1 - fi - all: name: All checks # Always run this job, even if earlier steps were skipped (or failed): @@ -246,7 +217,6 @@ jobs: - diagnostics-rust - cpp-overload-test-ok - cpp-overload-test-fail - - cpp-overload-file-names steps: - name: Fail if any other job failed # Every job status needs to be checked here, because `always()` stops failures from propagating automatically @@ -262,4 +232,3 @@ jobs: [[ "${{ needs.diagnostics-rust.result }}" == "success" ]] || exit 1 [[ "${{ needs.cpp-overload-test-ok.result }}" == "success" ]] || exit 1 [[ "${{ needs.cpp-overload-test-fail.result }}" == "success" ]] || exit 1 - [[ "${{ needs.cpp-overload-file-names.result }}" == "success" ]] || exit 1 diff --git a/cpp-overload-test/build.rs b/cpp-overload-test/build.rs index e493821..507c620 100644 --- a/cpp-overload-test/build.rs +++ b/cpp-overload-test/build.rs @@ -1,6 +1,5 @@ fn main() { - cpp_build::build("src/bin/std-forward-list-ok.rs"); - // FIXME: move these into the crate root instead of examples, `cpp_build` doesn't work with - // multiple examples. - //cpp_build::build("src/bin/std-forward-list-fail.rs"); + // `cpp_build` doesn't work with multiple example/binary builds in the same crate, so we use + // lib.rs submodules for successful overloads. + cpp_build::build("src/lib.rs"); } diff --git a/cpp-overload-test/examples/stdcpp-forward-list.rs b/cpp-overload-test/examples/stdcpp-forward-list.rs new file mode 100644 index 0000000..37620c9 --- /dev/null +++ b/cpp-overload-test/examples/stdcpp-forward-list.rs @@ -0,0 +1,9 @@ +//! Test C++ overloads that can't be represented in Rust, and record the macro diagnostics. +//! +//! The `cpp!` macro doesn't work here, because of technical limitations it can only run one build +//! per crate. (Examples and binaries are built separately from `lib.rs`.) +//! To add C++ code here, use /* ... */ code comment blocks. + +fn main() { + const _: () = panic!("There are no failing overloads for C++ `std::forward_list` yet"); +} diff --git a/cpp-overload-test/src/bin/std-forward-list-fail.stderr b/cpp-overload-test/examples/stdcpp-forward-list.stderr similarity index 59% rename from cpp-overload-test/src/bin/std-forward-list-fail.stderr rename to cpp-overload-test/examples/stdcpp-forward-list.stderr index be75e88..b165653 100644 --- a/cpp-overload-test/src/bin/std-forward-list-fail.stderr +++ b/cpp-overload-test/examples/stdcpp-forward-list.stderr @@ -1,8 +1,8 @@ error[E0080]: evaluation panicked: There are no failing overloads for C++ `std::forward_list` yet - --> cpp-overload-test/src/bin/std-forward-list-fail.rs:2:19 + --> cpp-overload-test/examples/stdcpp-forward-list.rs:8:19 | -2 | const _: () = panic!("There are no failing overloads for C++ `std::forward_list` yet"); +8 | const _: () = panic!("There are no failing overloads for C++ `std::forward_list` yet"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::_` failed here For more information about this error, try `rustc --explain E0080`. -error: could not compile `cpp-overload-test` (bin "std-forward-list-fail") due to 1 previous error +error: could not compile `cpp-overload-test` (example "stdcpp-forward-list") due to 1 previous error diff --git a/cpp-overload-test/src/bin/std-forward-list-fail.rs b/cpp-overload-test/src/bin/std-forward-list-fail.rs deleted file mode 100644 index 7dbbbd2..0000000 --- a/cpp-overload-test/src/bin/std-forward-list-fail.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - const _: () = panic!("There are no failing overloads for C++ `std::forward_list` yet"); -} diff --git a/cpp-overload-test/src/lib.rs b/cpp-overload-test/src/lib.rs new file mode 100644 index 0000000..5c30d60 --- /dev/null +++ b/cpp-overload-test/src/lib.rs @@ -0,0 +1,11 @@ +//! Test C++ overloads that can be successfully represented in Rust. +//! Each type in the C++ standard library has a module under `stdcpp`. + +#![feature(splat, tuple_trait)] +#![allow(incomplete_features)] + +/// The C++ standard library. +pub mod stdcpp { + // Add new modules for each type here, in alphabetical order. + pub mod forward_list; +} diff --git a/cpp-overload-test/src/bin/std-forward-list-ok.rs b/cpp-overload-test/src/stdcpp/forward_list.rs similarity index 96% rename from cpp-overload-test/src/bin/std-forward-list-ok.rs rename to cpp-overload-test/src/stdcpp/forward_list.rs index a70b396..25872aa 100644 --- a/cpp-overload-test/src/bin/std-forward-list-ok.rs +++ b/cpp-overload-test/src/stdcpp/forward_list.rs @@ -1,5 +1,4 @@ -#![feature(splat, tuple_trait)] -#![allow(incomplete_features)] +//! Test that C++ overloads for `std::forward_list` can be successfully represented in Rust. #![allow(unused_braces)] use cpp::cpp; @@ -105,7 +104,7 @@ overload! { } } -fn main() { +pub fn test_forward_list() { let mut default_list = StdForwardList::new(); let _with_capacity = StdForwardList::new(10); let _repeat_with = StdForwardList::new(42, 100); From be9fac1020c67f3cc49702b57210e121ccf3eef3 Mon Sep 17 00:00:00 2001 From: teor Date: Tue, 22 Sep 2026 15:02:21 +0200 Subject: [PATCH 2/2] Add missing CI for non-default crates --- .github/workflows/check.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index caa18ad..4482b7a 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -124,6 +124,7 @@ jobs: # and disable color output. # FIXME: turn this into a script so we can run it locally. run: | + cargo fmt --package splat-overload-diagnostics -- --check export CARGO_TERM_COLOR=never set -o pipefail TEST_NAMES=$(find splat-overload-diagnostics/src/bin -name "*.rs" | \ @@ -160,7 +161,11 @@ jobs: # FIXME: turn this into a script so contributors can run it locally. - name: Check C++ overload ok cases run: | - cargo build --all-features --package cpp-overload-test + cargo build --all-features --package cpp-overload-test --lib + cargo clippy --all-features --package cpp-overload-test -- --deny warnings + cargo test --all-features --package cpp-overload-test --lib + cargo test --doc --all-features --package cpp-overload-test + cargo fmt --package cpp-overload-test -- --check cpp-overload-test-fail: name: 10. Must-fail C++ overloads