diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30864bc1f..d082e91c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -121,5 +121,4 @@ jobs: cargo run --profile debug-ci -- contract new --target-dir ${{ runner.temp }} foobar && cargo run --profile debug-ci -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml && cargo run --profile debug-ci -- contract check --manifest-path=${{ runner.temp }}/foobar/Cargo.toml && - cargo run --profile debug-ci -- contract test --manifest-path=${{ runner.temp }}/foobar/Cargo.toml && cargo run --profile debug-ci -- contract build --manifest-path=${{ runner.temp }}/foobar/Cargo.toml --release diff --git a/CHANGELOG.md b/CHANGELOG.md index 1747808d8..29f129858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Respect the lockfile [#948](https://github.com/paritytech/cargo-contract/pull/948) +### Removed +- Remove the `test` command [#958](https://github.com/paritytech/cargo-contract/pull/958) + ## [2.0.0-rc.1] - 2023-02-01 Second release candidate compatible with `ink! 4.0.0-rc`. diff --git a/README.md b/README.md index b27fc15d5..1e0502cbe 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,6 @@ deploying the contract on-chain. Checks that the code builds as WebAssembly. This command does not output any `.contract` artifact to the `target/` directory. -##### `cargo contract test` - -Runs test suites defined for a smart contract off-chain. - ##### `cargo contract upload` Upload a contract to a `pallet-contracts` enabled chain. See [extrinsics](docs/extrinsics.md). diff --git a/crates/cargo-contract/src/cmd/mod.rs b/crates/cargo-contract/src/cmd/mod.rs index c88b2d004..00f9e25f5 100644 --- a/crates/cargo-contract/src/cmd/mod.rs +++ b/crates/cargo-contract/src/cmd/mod.rs @@ -16,7 +16,6 @@ pub mod build; pub mod decode; -pub mod test; pub(crate) use self::{ build::{ @@ -24,7 +23,6 @@ pub(crate) use self::{ CheckCommand, }, decode::DecodeCommand, - test::TestCommand, }; mod extrinsics; diff --git a/crates/cargo-contract/src/cmd/test.rs b/crates/cargo-contract/src/cmd/test.rs deleted file mode 100644 index 8f2cac68b..000000000 --- a/crates/cargo-contract/src/cmd/test.rs +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2018-2022 Parity Technologies (UK) Ltd. -// This file is part of cargo-contract. -// -// cargo-contract is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// cargo-contract is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with cargo-contract. If not, see . - -use anyhow::Result; -use colored::Colorize; -use contract_build::{ - maybe_println, - util, - Features, - ManifestPath, - Verbosity, - VerbosityFlags, -}; -use std::{ - convert::TryFrom, - path::PathBuf, -}; - -/// Executes smart contract tests off-chain by delegating to `cargo test`. -#[derive(Debug, clap::Args)] -#[clap(name = "test")] -pub struct TestCommand { - /// Path to the `Cargo.toml` of the contract to test. - #[clap(long, value_parser)] - manifest_path: Option, - #[clap(flatten)] - verbosity: VerbosityFlags, - #[clap(flatten)] - features: Features, -} - -impl TestCommand { - pub fn exec(&self) -> Result { - let manifest_path = ManifestPath::try_from(self.manifest_path.as_ref())?; - let verbosity = TryFrom::<&VerbosityFlags>::try_from(&self.verbosity)?; - - execute(&manifest_path, verbosity, &self.features) - } -} - -/// Result of the test runs. -pub struct TestResult { - /// The `cargo test` child process standard output stream buffer. - pub stdout: Vec, - /// The verbosity flags. - pub verbosity: Verbosity, -} - -impl TestResult { - pub fn display(&self) -> Result { - Ok(String::from_utf8(self.stdout.clone())?) - } -} - -/// Executes `cargo test`. -pub(crate) fn execute( - manifest_path: &ManifestPath, - verbosity: Verbosity, - features: &Features, -) -> Result { - maybe_println!( - verbosity, - " {} {}", - format!("[{}/{}]", 1, 1).bold(), - "Running tests".bright_green().bold() - ); - - let mut args = Vec::new(); - features.append_to_args(&mut args); - - let stdout = - util::invoke_cargo("test", args, manifest_path.directory(), verbosity, vec![])?; - - Ok(TestResult { stdout, verbosity }) -} - -#[cfg(feature = "test-ci-only")] -#[cfg(test)] -mod tests_ci_only { - use contract_build::{ - Features, - ManifestPath, - Verbosity, - }; - use regex::Regex; - - #[test] - fn passing_tests_yield_stdout() { - let tmp_dir = tempfile::Builder::new() - .prefix("cargo-contract.test.") - .tempdir() - .expect("temporary directory creation failed"); - - let project_name = "test_project"; - contract_build::new_contract_project(project_name, Some(&tmp_dir)) - .expect("new project creation failed"); - let working_dir = tmp_dir.path().join(project_name); - let manifest_path = ManifestPath::new(working_dir.join("Cargo.toml")) - .expect("invalid manifest path"); - - let ok_output_pattern = - Regex::new(r"test result: ok. \d+ passed; 0 failed; \d+ ignored") - .expect("regex pattern compilation failed"); - - let res = - super::execute(&manifest_path, Verbosity::Default, &Features::default()) - .expect("test execution failed"); - - assert!(ok_output_pattern.is_match(&String::from_utf8_lossy(&res.stdout))); - } -} diff --git a/crates/cargo-contract/src/main.rs b/crates/cargo-contract/src/main.rs index 977de648f..3959bff1b 100644 --- a/crates/cargo-contract/src/main.rs +++ b/crates/cargo-contract/src/main.rs @@ -25,7 +25,6 @@ use self::cmd::{ DecodeCommand, ErrorVariant, InstantiateCommand, - TestCommand, UploadCommand, }; use contract_build::{ @@ -111,9 +110,6 @@ enum Command { /// Check that the code builds as Wasm; does not output any `.contract` artifact to the `target/` directory #[clap(name = "check")] Check(CheckCommand), - /// Test the smart contract off-chain - #[clap(name = "test")] - Test(TestCommand), /// Upload contract code #[clap(name = "upload")] Upload(UploadCommand), @@ -170,13 +166,6 @@ fn exec(cmd: Command) -> Result<()> { } Ok(()) } - Command::Test(test) => { - let res = test.exec().map_err(format_err)?; - if res.verbosity.is_verbose() { - println!("{}", res.display()?) - } - Ok(()) - } Command::Upload(upload) => { upload .run()