|
1 | 1 | use assert_fs::fixture::{FileWriteStr, PathChild, PathCopy};
|
2 | 2 | use assert_fs::TempDir;
|
3 | 3 | use camino::Utf8PathBuf;
|
4 |
| -use fs_extra::dir::{copy, CopyOptions}; |
5 | 4 | use indoc::formatdoc;
|
6 | 5 | use shared::command::CommandExt;
|
7 | 6 | use shared::test_utils::node_url::node_rpc_url;
|
8 | 7 | use snapbox::cmd::{cargo_bin, Command as SnapboxCommand};
|
9 |
| -use std::fs::{create_dir_all, remove_dir_all}; |
10 | 8 | use std::path::{Path, PathBuf};
|
11 | 9 | use std::process::Command;
|
12 | 10 | use std::str::FromStr;
|
13 |
| -use std::sync::LazyLock; |
14 | 11 | use std::{env, fs};
|
15 | 12 | use test_utils::tempdir_with_tool_versions;
|
16 | 13 | use toml_edit::{value, DocumentMut};
|
17 | 14 | use walkdir::WalkDir;
|
18 | 15 |
|
19 |
| -/// To avoid rebuilding `snforge_std` and associated plugin for each test, we cache it in a directory and copy it to the e2e test temp directory. |
20 |
| -static BASE_CACHE_DIR: LazyLock<PathBuf> = |
21 |
| - LazyLock::new(|| init_base_cache_dir().expect("Failed to initialize base cache directory")); |
22 |
| - |
23 |
| -fn init_base_cache_dir() -> anyhow::Result<PathBuf> { |
24 |
| - let cache_dir_path = env::current_dir()?.join(".forge_e2e_cache"); |
25 |
| - if cache_dir_path.exists() { |
26 |
| - remove_dir_all(&cache_dir_path)?; |
27 |
| - } |
28 |
| - create_dir_all(&cache_dir_path)?; |
29 |
| - let cache_dir_path = cache_dir_path.canonicalize()?; |
30 |
| - |
31 |
| - let snforge_std = PathBuf::from("../../snforge_std").canonicalize()?; |
32 |
| - |
33 |
| - SnapboxCommand::new("scarb") |
34 |
| - .arg("build") |
35 |
| - .current_dir(snforge_std.as_path()) |
36 |
| - .env("SCARB_CACHE", &cache_dir_path) |
37 |
| - .assert() |
38 |
| - .success(); |
39 |
| - |
40 |
| - Ok(cache_dir_path) |
41 |
| -} |
42 |
| - |
43 | 16 | pub(crate) fn runner(temp_dir: &TempDir) -> SnapboxCommand {
|
44 |
| - copy( |
45 |
| - BASE_CACHE_DIR.as_path(), |
46 |
| - temp_dir.path(), |
47 |
| - &CopyOptions::new().overwrite(true).content_only(true), |
48 |
| - ) |
49 |
| - .unwrap(); |
| 17 | + SnapboxCommand::new(snforge_test_bin_path()).current_dir(temp_dir) |
| 18 | +} |
50 | 19 |
|
51 |
| - SnapboxCommand::new(cargo_bin!("snforge")) |
52 |
| - .env("SCARB_CACHE", temp_dir.path()) |
53 |
| - .current_dir(temp_dir) |
| 20 | +// If ran on CI, we want to get the nextest's built binary |
| 21 | +pub fn snforge_test_bin_path() -> PathBuf { |
| 22 | + if env::var("NEXTEST").unwrap_or("0".to_string()) == "1" { |
| 23 | + let snforge_nextest_env = |
| 24 | + env::var("NEXTEST_BIN_EXE_snforge").expect("No snforge binary for nextest found"); |
| 25 | + return PathBuf::from(snforge_nextest_env); |
| 26 | + } |
| 27 | + cargo_bin!("snforge").to_path_buf() |
54 | 28 | }
|
55 | 29 |
|
56 | 30 | pub(crate) fn test_runner(temp_dir: &TempDir) -> SnapboxCommand {
|
|
0 commit comments