Skip to content

Commit

Permalink
test: make tests independent from fixed commit sha
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbaliasnikov committed May 8, 2024
1 parent 796e292 commit b50980a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 50 deletions.
24 changes: 12 additions & 12 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rstest::rstest;
/// Returns `Ok(())` if the test passes.
#[rstest]
fn build_without_clone() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let file = assert_fs::NamedTempFile::new(common::LLVM_LOCK_FILE)?;
let path = file.parent().expect("Lockfile parent dir does not exist");
cmd.current_dir(path);
Expand All @@ -48,8 +48,8 @@ fn build_without_clone() -> anyhow::Result<()> {
#[rstest]
#[timeout(std::time::Duration::from_secs(5000))]
fn clone_build_and_clean() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -58,14 +58,14 @@ fn clone_build_and_clean() -> anyhow::Result<()> {
cmd.assert()
.success()
.stderr(predicate::str::is_match(".*Updating files:.*100%.*done").unwrap());
let mut build_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut build_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
build_cmd.current_dir(test_dir);
build_cmd
.arg("build")
.assert()
.success()
.stdout(predicate::str::is_match("Installing:.*").unwrap());
let mut clean_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut clean_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
clean_cmd.current_dir(test_dir);
clean_cmd.arg("clean");
clean_cmd.assert().success();
Expand All @@ -88,8 +88,8 @@ fn clone_build_and_clean() -> anyhow::Result<()> {
#[rstest]
#[timeout(std::time::Duration::from_secs(5000))]
fn clone_build_and_clean_musl() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -98,7 +98,7 @@ fn clone_build_and_clean_musl() -> anyhow::Result<()> {
cmd.assert()
.success()
.stderr(predicate::str::is_match(".*Updating files:.*100%.*done").unwrap());
let mut build_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut build_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
build_cmd.current_dir(test_dir);
build_cmd
.arg("build")
Expand All @@ -107,7 +107,7 @@ fn clone_build_and_clean_musl() -> anyhow::Result<()> {
.assert()
.success()
.stdout(predicate::str::is_match("Installing:.*").unwrap());
let mut clean_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut clean_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
clean_cmd.current_dir(test_dir);
clean_cmd.arg("clean");
clean_cmd.assert().success();
Expand All @@ -130,8 +130,8 @@ fn clone_build_and_clean_musl() -> anyhow::Result<()> {
#[rstest]
#[timeout(std::time::Duration::from_secs(5000))]
fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -140,7 +140,7 @@ fn debug_build_with_tests_coverage() -> anyhow::Result<()> {
cmd.assert()
.success()
.stderr(predicate::str::is_match(".*Updating files:.*100%.*done").unwrap());
let mut build_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut build_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
build_cmd.current_dir(test_dir);
build_cmd
.arg("build")
Expand Down
24 changes: 9 additions & 15 deletions tests/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use rstest::rstest;
/// Returns `Ok(())` if the test passes.
#[rstest]
fn checkout_after_clone() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -31,16 +31,13 @@ fn checkout_after_clone() -> anyhow::Result<()> {
cmd.assert()
.success()
.stderr(predicate::str::is_match(".*Updating files:.*100%.*done").unwrap());
let mut checkout_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut checkout_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
checkout_cmd.current_dir(test_dir);
checkout_cmd.arg("checkout");
checkout_cmd
.assert()
.success()
.stderr(predicate::str::contains(format!(
"HEAD is now at {}",
&common::ERA_LLVM_REPO_TEST_REF[..8]
)));
.stderr(predicate::str::contains("HEAD is now at"));
Ok(())
}

Expand All @@ -59,8 +56,8 @@ fn checkout_after_clone() -> anyhow::Result<()> {
/// Returns `Ok(())` if the test passes.
#[rstest]
fn force_checkout() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -69,16 +66,13 @@ fn force_checkout() -> anyhow::Result<()> {
cmd.assert()
.success()
.stderr(predicate::str::is_match(".*Updating files:.*100%.*done").unwrap());
let mut checkout_cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut checkout_cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
checkout_cmd.current_dir(test_dir);
checkout_cmd.arg("checkout").arg("--force");
checkout_cmd
.assert()
.success()
.stderr(predicate::str::contains(format!(
"HEAD is now at {}",
&common::ERA_LLVM_REPO_TEST_REF[..8]
)));
.stderr(predicate::str::contains("HEAD is now at"));
Ok(())
}

Expand All @@ -97,7 +91,7 @@ fn force_checkout() -> anyhow::Result<()> {
/// Returns `Ok(())` if the test passes.
#[rstest]
fn checkout_without_lockfile() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let file = assert_fs::NamedTempFile::new(common::LLVM_LOCK_FILE)?;
let path = file.parent().expect("Lockfile parent dir does not exist");
cmd.current_dir(path);
Expand Down
2 changes: 1 addition & 1 deletion tests/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use rstest::rstest;
/// Returns `Ok(())` if the test passes.
#[rstest]
fn clean_without_clone() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let file = assert_fs::NamedTempFile::new(common::LLVM_LOCK_FILE)?;
let path = file.parent().expect("Lockfile parent dir does not exist");
cmd.current_dir(path);
Expand Down
25 changes: 10 additions & 15 deletions tests/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@ use rstest::rstest;
/// Returns `Ok(())` if the test passes.
#[rstest]
fn clone() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
cmd.current_dir(test_dir);
cmd.arg("clone");
cmd.assert()
.success()
.stderr(predicate::str::contains(format!(
"HEAD is now at {}",
&common::ERA_LLVM_REPO_TEST_REF[..8]
)));
.stderr(predicate::str::contains("HEAD is now at"));
Ok(())
}

Expand All @@ -52,8 +49,8 @@ fn clone() -> anyhow::Result<()> {
/// Returns `Ok(())` if the test passes.
#[rstest]
fn clone_deep() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_REF)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(None)?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -62,10 +59,7 @@ fn clone_deep() -> anyhow::Result<()> {
cmd.arg("--deep");
cmd.assert()
.success()
.stderr(predicate::str::contains(format!(
"HEAD is now at {}",
&common::ERA_LLVM_REPO_TEST_REF[..8]
)));
.stderr(predicate::str::contains("HEAD is now at"));
Ok(())
}

Expand All @@ -84,8 +78,9 @@ fn clone_deep() -> anyhow::Result<()> {
/// Returns `Ok(())` if the test passes.
#[rstest]
fn clone_wrong_reference() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let lockfile = common::create_test_tmp_lockfile(common::ERA_LLVM_REPO_TEST_SHA_INVALID)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let lockfile =
common::create_test_tmp_lockfile(Some(common::ERA_LLVM_REPO_TEST_SHA_INVALID.to_string()))?;
let test_dir = lockfile
.parent()
.expect("Lockfile parent dir does not exist");
Expand All @@ -112,7 +107,7 @@ fn clone_wrong_reference() -> anyhow::Result<()> {
/// Returns `Ok(())` if the test passes.
#[rstest]
fn clone_without_lockfile() -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
let file = assert_fs::NamedTempFile::new(common::LLVM_LOCK_FILE)?;
let path = file.parent().expect("Lockfile parent dir does not exist");
cmd.current_dir(path);
Expand Down
9 changes: 5 additions & 4 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use assert_fs::fixture::FileWriteStr;

pub const ZKEVM_LLVM: &str = "zkevm-llvm";
pub const ZKSYNC_LLVM: &str = "zksync-llvm";
pub const PACKAGE_VERSION: &str = env!("CARGO_PKG_VERSION");
pub const ERA_LLVM_REPO_URL: &str = "https://github.com/matter-labs/era-compiler-llvm";
pub const ERA_LLVM_REPO_TEST_BRANCH: &str = "v1.4.2";
pub const ERA_LLVM_REPO_TEST_REF: &str = "b5ccf6d5774e9bc3cee47ab4a334404718d3adfd";
pub const ERA_LLVM_REPO_TEST_SHA_INVALID: &str = "12345abcd";
pub const LLVM_LOCK_FILE: &str = "LLVM.lock";

/// Creates a temporary lock file for testing.
pub fn create_test_tmp_lockfile(reference: &str) -> anyhow::Result<assert_fs::NamedTempFile> {
pub fn create_test_tmp_lockfile(
reference: Option<String>,
) -> anyhow::Result<assert_fs::NamedTempFile> {
let file = assert_fs::NamedTempFile::new(LLVM_LOCK_FILE)?;
let lock = compiler_llvm_builder::Lock {
url: ERA_LLVM_REPO_URL.to_string(),
branch: ERA_LLVM_REPO_TEST_BRANCH.to_string(),
r#ref: Some(reference.to_string()),
r#ref: reference,
};
file.write_str(toml::to_string(&lock)?.as_str())?;
Ok(file)
Expand Down
4 changes: 2 additions & 2 deletions tests/invalid_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rstest::rstest;
#[case("clone", "--invalid-clone-option")]
#[case("checkout", "--invalid-checkout-option")]
fn invalid_option(#[case] subcommand: &str, #[case] option: &str) -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
if subcommand != "" {
cmd.arg(subcommand);
}
Expand Down Expand Up @@ -65,7 +65,7 @@ fn invalid_option(#[case] subcommand: &str, #[case] option: &str) -> anyhow::Res
#[case("123")]
#[case("$$.@!;-a3")]
fn invalid_subcommand(#[case] subcommand: &str) -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
cmd.arg(subcommand);
cmd.assert()
.failure()
Expand Down
2 changes: 1 addition & 1 deletion tests/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rstest::rstest;
#[case("clone")]
#[case("checkout")]
fn version(#[case] subcommand: String) -> anyhow::Result<()> {
let mut cmd = Command::cargo_bin(common::ZKEVM_LLVM)?;
let mut cmd = Command::cargo_bin(common::ZKSYNC_LLVM)?;
if subcommand != "" {
cmd.arg(subcommand);
}
Expand Down

0 comments on commit b50980a

Please sign in to comment.