Skip to content

Commit

Permalink
Bring test-ci-only back (#180)
Browse files Browse the repository at this point in the history
* Revert "Revert me: Remove `--all-features` (#114)"

This reverts commit 4a0d352.

* Pass verbosity flag

* Format use

* Run tests without `binaryen-as-dependency`

* Update to `scale-info` 0.6

* Fix `value used after move`

* Do not continue processing wasm on `check`

Results in `No such file` otherwise, since
no *.wasm is generated on `check`.

* Make casing consistent for `log` messages

* Clarify behavior of `check`

* Revert me: add debug output

* Upgrade `cargo_metadata` to 0.13.1

* Fix assert for target path `target/ink`

* Revert "Revert me: add debug output"

This reverts commit d2bf1dd.

* Revert "Upgrade `cargo_metadata` to 0.13.1"

This reverts commit 723c9b2.

* Run tests only with `binaryen-as-dependency`

* Upgrade cargo-metadata and fix usages (#210)

* Only allow new contract names beginning with an alphabetic character (#219)

* Only allow contract names beginning with an alphabetic character

* Add test for contract name beginning with a number

* Add test for contract name beginning with a number

* Run tests only with `binaryen-as-dependency`

* Refactor

* Revert "Refactor"

This reverts commit defe20d.

Co-authored-by: Andrew Jones <[email protected]>
  • Loading branch information
Michael Müller and ascjones authored Mar 10, 2021
1 parent d4891aa commit 4111385
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
4 changes: 1 addition & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ test:
stage: test
<<: *docker-env
script:
# We are temporarily removing `--all-features` here for the build to succeed
# until our substrate dependencies are released in newer versions.
- cargo test --verbose --workspace
- cargo test --verbose --workspace --all-features

#### stage: build (default features)

Expand Down
40 changes: 26 additions & 14 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ pub(crate) fn execute_with_crate_metadata(
"Building cargo project".bright_green().bold()
);
build_cargo_project(&crate_metadata, build_artifact, verbosity, unstable_flags)?;
if build_artifact == BuildArtifacts::CheckOnly {
return Ok((None, None));
}
maybe_println!(
verbosity,
" {} {}",
Expand All @@ -456,7 +459,9 @@ pub(crate) fn execute_with_crate_metadata(
#[cfg(feature = "test-ci-only")]
#[cfg(test)]
mod tests_ci_only {
use crate::{cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags};
use crate::{
cmd, util::tests::with_tmp_dir, BuildArtifacts, ManifestPath, UnstableFlags, Verbosity,
};

#[test]
fn build_template() {
Expand All @@ -466,30 +471,33 @@ mod tests_ci_only {
ManifestPath::new(&path.join("new_project").join("Cargo.toml")).unwrap();
let res = super::execute(
&manifest_path,
None,
Verbosity::Default,
true,
BuildArtifacts::All,
UnstableFlags::default(),
)
.expect("build failed");

// we can't use `/target/ink` here, since this would match
// for `/target` being the root path. but since `ends_with`
// always matches whole path components we can be sure
// the path can never be e.g. `foo_target/ink` -- the assert
// would fail for that.
assert!(res.target_directory.ends_with("target/ink"));
assert!(res.optimization_result.unwrap().optimized_size > 0.0);
// our ci has set `CARGO_TARGET_DIR` to cache artifacts.
// this dir does not include `/target/` as a path, hence
// we can't match for e.g. `foo_project/target/ink`.
//
// we also can't match for `/ink` here, since this would match
// for `/ink` being the root path.
assert!(res.target_directory.ends_with("ink"));

let optimized_size = res.optimization_result.unwrap().optimized_size;
assert!(optimized_size > 0.0);

// our optimized contract template should always be below 3k.
assert!(res.optimization_result.unwrap().optimized_size < 3.0);
assert!(optimized_size < 3.0);

Ok(())
})
}

#[test]
fn check_must_not_create_target_in_project_dir() {
fn check_must_not_output_contract_artifacts_in_project_dir() {
with_tmp_dir(|path| {
// given
cmd::new::execute("new_project", Some(path)).expect("new project creation failed");
Expand All @@ -499,7 +507,7 @@ mod tests_ci_only {
// when
super::execute(
&manifest_path,
None,
Verbosity::Default,
true,
BuildArtifacts::CheckOnly,
UnstableFlags::default(),
Expand All @@ -508,8 +516,12 @@ mod tests_ci_only {

// then
assert!(
!project_dir.join("target").exists(),
"found target folder in project directory!"
!project_dir.join("target/ink/new_project.contract").exists(),
"found contract artifact in project directory!"
);
assert!(
!project_dir.join("target/ink/new_project.wasm").exists(),
"found wasm artifact in project directory!"
);
Ok(())
})
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ mod tests {
use crate::cmd::metadata::blake2_hash;
use crate::{
cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, BuildArtifacts,
ManifestPath, UnstableFlags,
ManifestPath, UnstableFlags, Verbosity,
};
use contract_metadata::*;
use serde_json::{Map, Value};
Expand Down Expand Up @@ -379,7 +379,7 @@ mod tests {
let crate_metadata = CrateMetadata::collect(&test_manifest.manifest_path)?;
let dest_bundle = cmd::metadata::execute(
&test_manifest.manifest_path,
None,
Verbosity::Default,
BuildArtifacts::All,
UnstableFlags::default(),
)?
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ enum Command {
/// Command has been deprecated, use `cargo contract build` instead
#[structopt(name = "generate-metadata")]
GenerateMetadata {},
/// Check that the code builds as Wasm; does not output any build artifact to the top level `target/` directory
/// Check that the code builds as Wasm; does not output any `<name>.contract` artifact to the `target/` directory
#[structopt(name = "check")]
Check(CheckCommand),
/// Test the smart contract off-chain
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ where
Verbosity::Default => &mut cmd,
};

log::info!("invoking cargo: {:?}", cmd);
log::info!("Invoking cargo: {:?}", cmd);

let child = cmd
// capture the stdout to return from this function as bytes
Expand Down

0 comments on commit 4111385

Please sign in to comment.