From e1b1e216c506a01a1f4ca579adae02f85b8db82b Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 22 Nov 2019 14:38:49 -0800 Subject: ci: bring back build tests (#1813) This directory was deleted when `cargo hack` was introduced, however there were some tests that were still useful (macro failure output). Also, additional build tests will be added over time. --- Cargo.toml | 1 + azure-pipelines.yml | 8 +++++ ci/azure-test-build.yml | 17 +++++++++ tests-build/Cargo.toml | 15 ++++++++ tests-build/README.md | 2 ++ tests-build/src/lib.rs | 2 ++ tests-build/tests/fail/macros_invalid_input.rs | 25 +++++++++++++ tests-build/tests/fail/macros_invalid_input.stderr | 41 ++++++++++++++++++++++ tests-build/tests/macros.rs | 9 +++++ 9 files changed, 120 insertions(+) create mode 100644 ci/azure-test-build.yml create mode 100644 tests-build/Cargo.toml create mode 100644 tests-build/README.md create mode 100644 tests-build/src/lib.rs create mode 100644 tests-build/tests/fail/macros_invalid_input.rs create mode 100644 tests-build/tests/fail/macros_invalid_input.stderr create mode 100644 tests-build/tests/macros.rs diff --git a/Cargo.toml b/Cargo.toml index 9c0250f1..4a2a71ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,6 @@ members = [ # Internal "examples", + "tests-build", "tests-integration", ] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2f102b0a..e4a87658 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,6 +30,13 @@ jobs: - tokio-util - examples +# Run tests from `tests-build`. This requires a different process +- template: ci/azure-test-build.yml + parameters: + name: test_build + displayName: Test build permutations + rust: stable + # Run loom tests - template: ci/azure-loom.yml parameters: @@ -93,6 +100,7 @@ jobs: - clippy - test_tokio - test_linux + - test_build - loom - cross - minrust diff --git a/ci/azure-test-build.yml b/ci/azure-test-build.yml new file mode 100644 index 00000000..944b9e24 --- /dev/null +++ b/ci/azure-test-build.yml @@ -0,0 +1,17 @@ +jobs: +- job: ${{ parameters.name }} + displayName: ${{ parameters.displayName }} + pool: + vmImage: 'Ubuntu 16.04' + + steps: + - template: azure-install-rust.yml + parameters: + rust_version: ${{ parameters.rust }} + + - script: cargo install cargo-hack + displayName: Install cargo-hack + + - script: cargo hack test --each-feature + displayName: cargo hack test --each-feature + workingDirectory: $(Build.SourcesDirectory)/tests-build diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml new file mode 100644 index 00000000..68231d71 --- /dev/null +++ b/tests-build/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "tests-build" +version = "0.1.0" +authors = ["Tokio Contributors "] +edition = "2018" +publish = false + +[features] +full = ["tokio/full"] + +[dependencies] +tokio = { path = "../tokio", optional = true } + +[dev-dependencies] +trybuild = "1.0" diff --git a/tests-build/README.md b/tests-build/README.md new file mode 100644 index 00000000..f491e2bc --- /dev/null +++ b/tests-build/README.md @@ -0,0 +1,2 @@ +Tests the various combination of feature flags. This is broken out to a separate +crate to work around limitations with cargo features. diff --git a/tests-build/src/lib.rs b/tests-build/src/lib.rs new file mode 100644 index 00000000..7b019cc7 --- /dev/null +++ b/tests-build/src/lib.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "tokio")] +pub use tokio; diff --git a/tests-build/tests/fail/macros_invalid_input.rs b/tests-build/tests/fail/macros_invalid_input.rs new file mode 100644 index 00000000..5b1a8adc --- /dev/null +++ b/tests-build/tests/fail/macros_invalid_input.rs @@ -0,0 +1,25 @@ +use tests_build::tokio; + +#[tokio::main] +fn main_is_not_async() {} + +#[tokio::main(foo)] +async fn main_attr_has_unknown_args() {} + +#[tokio::main(threadpool::bar)] +async fn main_attr_has_path_args() {} + +#[tokio::test] +fn test_is_not_async() {} + +#[tokio::test] +async fn test_fn_has_args(_x: u8) {} + +#[tokio::test(foo)] +async fn test_attr_has_args() {} + +#[tokio::test] +#[test] +async fn test_has_second_test_attr() {} + +fn main() {} diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr new file mode 100644 index 00000000..96fdcb17 --- /dev/null +++ b/tests-build/tests/fail/macros_invalid_input.stderr @@ -0,0 +1,41 @@ +error: the async keyword is missing from the function declaration + --> $DIR/macros_invalid_input.rs:4:1 + | +4 | fn main_is_not_async() {} + | ^^ + +error: Unknown attribute foo is specified; expected `basic_scheduler` or `threaded_scheduler` + --> $DIR/macros_invalid_input.rs:6:15 + | +6 | #[tokio::main(foo)] + | ^^^ + +error: Must have specified ident + --> $DIR/macros_invalid_input.rs:9:15 + | +9 | #[tokio::main(threadpool::bar)] + | ^^^^^^^^^^^^^^^ + +error: the async keyword is missing from the function declaration + --> $DIR/macros_invalid_input.rs:13:1 + | +13 | fn test_is_not_async() {} + | ^^ + +error: the test function cannot accept arguments + --> $DIR/macros_invalid_input.rs:16:27 + | +16 | async fn test_fn_has_args(_x: u8) {} + | ^^^^^^ + +error: Unknown attribute foo is specified; expected `basic_scheduler` or `threaded_scheduler` + --> $DIR/macros_invalid_input.rs:18:15 + | +18 | #[tokio::test(foo)] + | ^^^ + +error: second test attribute is supplied + --> $DIR/macros_invalid_input.rs:22:1 + | +22 | #[test] + | ^^^^^^^ diff --git a/tests-build/tests/macros.rs b/tests-build/tests/macros.rs new file mode 100644 index 00000000..170db227 --- /dev/null +++ b/tests-build/tests/macros.rs @@ -0,0 +1,9 @@ +#[test] +fn compile_fail() { + let t = trybuild::TestCases::new(); + + #[cfg(feature = "full")] + t.compile_fail("tests/fail/macros_invalid_input.rs"); + + drop(t); +} -- cgit v1.2.3