inject workdir

Signed-off-by: xermicus <bigcyrill@hotmail.com>
This commit is contained in:
xermicus
2025-03-23 15:36:49 +01:00
parent 487eefe908
commit bfb96bf67d
7 changed files with 42 additions and 15 deletions
Generated
+8
View File
@@ -2886,6 +2886,7 @@ dependencies = [
"semver 1.0.26",
"serde",
"serde_json",
"temp-dir",
]
[[package]]
@@ -2909,6 +2910,7 @@ dependencies = [
"revive-dt-config",
"revive-dt-node-interaction",
"serde_json",
"temp-dir",
]
[[package]]
@@ -3527,6 +3529,12 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "temp-dir"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc1ee6eef34f12f765cb94725905c6312b6610ab2b0940889cfe58dae7bc3c72"
[[package]]
name = "tempfile"
version = "3.19.1"
+1
View File
@@ -33,6 +33,7 @@ semver = { version = "1.0", features = ["serde"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1.0", default-features = false, features = ["arbitrary_precision", "std"] }
sha2 = { version = "0.10.8" }
temp-dir = { version = "0.1.14" }
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
# revive compiler
+5 -10
View File
@@ -1,6 +1,6 @@
//! The global configuration used accross all revive differential testing crates.
use std::{env, path::PathBuf};
use std::path::PathBuf;
use clap::Parser;
@@ -18,8 +18,10 @@ pub struct Arguments {
pub corpus: Vec<PathBuf>,
/// A place to store temporary artifacts during test execution.
#[arg(long = "workdir", short, default_value_t = cwd())]
pub working_directory: String,
///
/// Creates a temporary dir if not specified.
#[arg(long = "workdir", short)]
pub working_directory: Option<PathBuf>,
/// The path to the `geth` executable.
///
@@ -40,13 +42,6 @@ pub struct Arguments {
pub genesis_file: Option<PathBuf>,
}
fn cwd() -> String {
env::current_dir()
.expect("should be able to access current woring directory")
.to_string_lossy()
.to_string()
}
impl Default for Arguments {
fn default() -> Self {
Arguments::parse_from(["retester"])
+1
View File
@@ -27,3 +27,4 @@ rayon = { workspace = true }
semver = { workspace = true }
serde = { workspace = true, features = [ "derive" ] }
serde_json = { workspace = true }
temp-dir = { workspace = true }
+8 -1
View File
@@ -6,15 +6,22 @@ use rayon::prelude::*;
use revive_dt_config::*;
use revive_dt_core::driver::compiler::build_evm;
use revive_dt_format::corpus::Corpus;
use temp_dir::TempDir;
fn main() -> anyhow::Result<()> {
env_logger::init();
let config = Arguments::parse();
let mut config = Arguments::parse();
if config.corpus.is_empty() {
anyhow::bail!("no test corpus specified");
}
let temporary_directory = TempDir::new()?;
config
.working_directory
.get_or_insert_with(|| temporary_directory.path().into());
for path in config.corpus.iter().collect::<BTreeSet<_>>() {
log::trace!("attempting corpus {path:?}");
let corpus = Corpus::try_from_path(path)?;
+3
View File
@@ -15,3 +15,6 @@ serde_json = { workspace = true }
revive-dt-node-interaction = { workspace = true }
revive-dt-config = { workspace = true }
[dev-dependencies]
temp-dir = { workspace = true }
+16 -4
View File
@@ -54,7 +54,11 @@ impl Instance {
/// Create a new uninitialized instance.
pub fn new(config: &Arguments) -> anyhow::Result<Self> {
let geth_directory = PathBuf::from(&config.working_directory).join(Self::BASE_DIRECTORY);
let geth_directory = config
.working_directory
.as_ref()
.ok_or_else(|| anyhow::anyhow!("config did not provide working directory"))?
.join(Self::BASE_DIRECTORY);
let id = NODE_COUNT.fetch_add(1, Ordering::SeqCst);
let base_directory = geth_directory.join(id.to_string());
@@ -218,16 +222,24 @@ impl Drop for Instance {
#[cfg(test)]
mod tests {
use revive_dt_config::Arguments;
use temp_dir::TempDir;
use crate::{GENESIS_JSON, Node};
use super::Instance;
fn test_config() -> (Arguments, TempDir) {
let mut config = Arguments::default();
let temp_dir = TempDir::new().unwrap();
config.working_directory = temp_dir.path().to_path_buf().into();
(config, temp_dir)
}
#[test]
fn init_works() {
Instance::new(&Arguments::default())
Instance::new(&test_config().0)
.unwrap()
.init(GENESIS_JSON.to_string())
.unwrap();
@@ -235,7 +247,7 @@ mod tests {
#[test]
fn spawn_works() {
Instance::new(&Arguments::default())
Instance::new(&test_config().0)
.unwrap()
.spawn(GENESIS_JSON.to_string())
.unwrap();