Skip to content

Commit

Permalink
#1682: fix build tests (#1736)
Browse files Browse the repository at this point in the history
* Fix build tests

* revert implementation
  • Loading branch information
Ifropc authored Dec 20, 2024
1 parent b63a40b commit 2c215cd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/crates/soroban-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ assert_fs = "1.0.7"
predicates = { workspace = true }
fs_extra = "1.3.0"
toml = { workspace = true }
home = "0.5.9"


[dev-dependencies]
Expand Down
59 changes: 37 additions & 22 deletions cmd/crates/soroban-test/tests/it/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use predicates::prelude::predicate;
use soroban_cli::xdr::{Limited, Limits, ReadXdr, ScMetaEntry, ScMetaV0};
use soroban_spec_tools::contract::Spec;
use soroban_test::TestEnv;
use std::env;
use std::io::Cursor;

#[test]
Expand All @@ -16,11 +17,9 @@ fn build_all() {
.arg("--print-commands-only")
.assert()
.success()
.stdout(predicate::eq("\
cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
.stdout(predicate::eq(with_flags("cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
cargo rustc --manifest-path=contracts/call/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
cargo rustc --manifest-path=contracts/add/add2/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
"));
cargo rustc --manifest-path=contracts/add/add2/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release")));
}

#[test]
Expand All @@ -36,9 +35,7 @@ fn build_package_by_name() {
.arg("--package=add")
.assert()
.success()
.stdout(predicate::eq("\
cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
"));
.stdout(predicate::eq(with_flags("cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release")));
}

#[test]
Expand All @@ -54,9 +51,7 @@ fn build_package_by_current_dir() {
.assert()
.success()
.stdout(predicate::eq(
"\
cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
",
with_flags("cargo rustc --manifest-path=Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release"),
));
}

Expand Down Expand Up @@ -85,20 +80,17 @@ fn build_all_when_in_non_package_directory() {
let sandbox = TestEnv::default();
let cargo_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let fixture_path = cargo_dir.join("tests/fixtures/workspace/contracts/add/src/");

sandbox
.new_assert_cmd("contract")
.current_dir(fixture_path)
.arg("build")
.arg("--print-commands-only")
.assert()
.success()
.stdout(predicate::eq(
"\
cargo rustc --manifest-path=../Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
cargo rustc --manifest-path=../../call/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
cargo rustc --manifest-path=../add2/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
",
));
.stdout(predicate::eq(with_flags(
"cargo rustc --manifest-path=../Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release"
)));
}

#[test]
Expand All @@ -113,11 +105,7 @@ fn build_default_members() {
.arg("--print-commands-only")
.assert()
.success()
.stdout(predicate::eq(
"\
cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release
",
));
.stdout(predicate::eq(with_flags("cargo rustc --manifest-path=contracts/add/Cargo.toml --crate-type=cdylib --target=wasm32-unknown-unknown --release")));
}

#[test]
Expand Down Expand Up @@ -185,3 +173,30 @@ fn build_with_metadata() {

assert_eq!(entries, expected_entries);
}

fn with_flags(expected: &str) -> String {
let cargo_home = home::cargo_home().unwrap();
let cargo_home = format!("{}", cargo_home.display());
let registry_prefix = format!("{cargo_home}/registry/src/");

let vec: Vec<_> = if env::var("RUSTFLAGS").is_ok() {
expected.split("\n").map(|x| x.to_string()).collect()
} else {
expected
.split("\n")
.map(|x| {
format!(
"CARGO_BUILD_RUSTFLAGS=--remap-path-prefix={}= {}",
registry_prefix, x
)
})
.collect()
};

return format!(
"\
{}
",
vec.join("\n")
);
}

0 comments on commit 2c215cd

Please sign in to comment.