Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl: test sub cmd with support for --manifest-path (#280) #283

Merged
merged 1 commit into from
Jul 3, 2021

Conversation

chiefbiiko
Copy link
Contributor

drafts cargo contract test [FLAGS] [--manifest-path]

in this first impl stdout is uncolored

let me know if you care much for the colors

@cla-bot-2021
Copy link

cla-bot-2021 bot commented May 27, 2021

User @chiefbiiko, please sign the CLA here.

Copy link
Contributor

@Robbepop Robbepop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What precisely is the win of having cargo contract test over just using cargo test as it can be done right now?

@cmichi
Copy link
Collaborator

cmichi commented Jun 17, 2021

@Robbepop At the moment cargo contract --help shows the sub-command as:

test     Test the smart contract off-chain

If one invokes cargo contract test currently this results in an unimplemented! panic though, which is why people were irritated and started creating issues about it in this repository.

So we could either remove the sub-command or just hand over to cargo test. After talking to @ascjones we concluded that it's probably best to just spawn a sub-process with cargo test until we have further ideas what to do with the sub-command (#280).

What's your opinion?

@Robbepop
Copy link
Contributor

@Robbepop At the moment cargo contract --help shows the sub-command as:

test     Test the smart contract off-chain

If one invokes cargo contract test currently this results in an unimplemented! panic though, which is why people were irritated and started creating issues about it in this repository.

So we could either remove the sub-command or just hand over to cargo test. After talking to @ascjones we concluded that it's probably best to just spawn a sub-process with cargo test until we have further ideas what to do with the sub-command (#280).

What's your opinion?

I currently do not see a major reason but it might help against confusion. So yeah let's do it the proposed way.

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, it looks good!

I've got just some minor things. We use the writing off-chain everywhere, hence the suggestion of keeping it consistent.

Cargo.toml Outdated
@@ -3,7 +3,7 @@ members = [".", "metadata"]

[package]
name = "cargo-contract"
version = "0.12.1"
version = "0.13.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = "0.13.0"
version = "0.12.1"

Good that you thought of this, but we plan on having another change in the next release as well, so let's wait for that :-).

CHANGELOG.md Outdated
Comment on lines 9 to 10
## [0.13.0] - 2021-05-27

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## [0.13.0] - 2021-05-27

README.md Outdated
@@ -87,6 +87,9 @@ toolchain of a directory by executing `rustup override set nightly` in it.
Checks that the code builds as WebAssembly. This command does not output any `<name>.contract`
artifact to the `target/` directory.

##### `cargo contract test`

Runs test suites defined for a smart contract - offchain.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Runs test suites defined for a smart contract - offchain.
Runs test suites defined for a smart contract off-chain.

@@ -99,6 +99,7 @@ test-new-project-template:

- cargo run --all-features -- contract build --manifest-path new_project/Cargo.toml
- cargo run --all-features -- contract check --manifest-path new_project/Cargo.toml
- cargo run --all-features -- contract test --manifest-path new_project/Cargo.toml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you thought of adding it here!

Cargo.lock Outdated
@@ -487,7 +487,7 @@ dependencies = [

[[package]]
name = "cargo-contract"
version = "0.12.1"
version = "0.13.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = "0.13.0"
version = "0.12.1"

src/cmd/test.rs Outdated
#[derive(Debug, StructOpt)]
#[structopt(name = "test")]
pub struct TestCommand {
/// Path to the Cargo.toml of the contract to test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Path to the Cargo.toml of the contract to test
/// Path to the `Cargo.toml` of the contract to test

src/cmd/test.rs Outdated
use std::{convert::TryFrom, path::PathBuf};
use structopt::StructOpt;

/// Executes smart-contract tests offchain by delegating to `cargo test`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Executes smart-contract tests offchain by delegating to `cargo test`.
/// Executes smart-contract tests off-chain by delegating to `cargo test`.

src/cmd/test.rs Outdated
}
}

/// Executes cargo +nightly test.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Executes cargo +nightly test.
/// Executes `cargo +nightly test`.

src/cmd/test.rs Outdated
with_new_contract_project(|manifest_path| {
let res = super::execute(&manifest_path, Verbosity::Default).expect("test failed");

assert!(res.stdout.len() > 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add another assertions which checks for something like test result: ok. 2 passed; 0 failed; 0 ignored?

This way we can then be sure that there was no other unrelated failure the cause of stdout.len() > 0.

CHANGELOG.md Outdated
## [0.13.0] - 2021-05-27

### Added
- Convenient offchain testing through `cargo contract test`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Convenient offchain testing through `cargo contract test`
- Convenient off-chain testing through `cargo contract test`

@chiefbiiko
Copy link
Contributor Author

thanks for the review
i have included your suggestions now

Copy link
Collaborator

@cmichi cmichi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@cmichi cmichi merged commit 78d4d4e into use-ink:master Jul 3, 2021
@cmichi cmichi mentioned this pull request Jul 3, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants