Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 12 additions & 38 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" | \
Expand All @@ -148,7 +149,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
Expand All @@ -157,17 +158,14 @@ 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 --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
Expand All @@ -180,21 +178,21 @@ 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
echo "testing incompatible overloads: $test_name"
# 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=$?
Expand All @@ -204,31 +202,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):
Expand All @@ -246,7 +222,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
Expand All @@ -262,4 +237,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
7 changes: 3 additions & 4 deletions cpp-overload-test/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
9 changes: 9 additions & 0 deletions cpp-overload-test/examples/stdcpp-forward-list.rs
Original file line number Diff line number Diff line change
@@ -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");
}
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions cpp-overload-test/src/bin/std-forward-list-fail.rs

This file was deleted.

11 changes: 11 additions & 0 deletions cpp-overload-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading