Skip to content

Commit

Permalink
improve test directory path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed Jan 20, 2025
1 parent 7cb7080 commit ddb5c0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
19 changes: 6 additions & 13 deletions compiler_tester/src/directories/matter_labs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,29 @@ impl Collection for MatterLabsDirectory {
let entry = entry?;
let path = entry.path();
let entry_type = entry.file_type().map_err(|error| {
anyhow::anyhow!(
"Failed to get the type of file `{}`: {}",
path.to_string_lossy(),
error
)
anyhow::anyhow!("Failed to get the type of file {path:?}: {error}")
})?;

if entry_type.is_dir() {
tests.extend(Self::read_all(
_target,
&path,
path.as_path(),
extension,
summary.clone(),
filters,
)?);
continue;
} else if !entry_type.is_file() {
anyhow::bail!("Invalid type of file `{}`", path.to_string_lossy());
anyhow::bail!("Invalid type of file {path:?}");
}

if entry.file_name().to_string_lossy().starts_with('.') {
continue;
}

let file_extension = path.extension().ok_or_else(|| {
anyhow::anyhow!(
"Failed to get the extension of file `{}`",
path.to_string_lossy()
)
})?;
let file_extension = path
.extension()
.ok_or_else(|| anyhow::anyhow!("Failed to get the extension of file {path:?}"))?;
if file_extension != extension {
continue;
}
Expand Down
28 changes: 14 additions & 14 deletions compiler_tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) mod utils;
pub(crate) mod vm;
pub(crate) mod workflow;

use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Mutex;

Expand Down Expand Up @@ -281,7 +281,7 @@ impl CompilerTester {

tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::SOLIDITY_SIMPLE,
PathBuf::from(Self::SOLIDITY_SIMPLE),
era_compiler_common::EXTENSION_SOLIDITY,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
Expand All @@ -291,14 +291,14 @@ impl CompilerTester {
if let era_compiler_common::Target::EraVM = target {
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::VYPER_SIMPLE,
PathBuf::from(Self::VYPER_SIMPLE),
era_compiler_common::EXTENSION_VYPER,
vyper_compiler.clone(),
)?);
}
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::YUL_SIMPLE,
PathBuf::from(Self::YUL_SIMPLE),
era_compiler_common::EXTENSION_YUL,
match toolchain {
Toolchain::IrLLVM => yul_compiler.clone(),
Expand All @@ -307,20 +307,20 @@ impl CompilerTester {
)?);
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::LLVM_SIMPLE,
PathBuf::from(Self::LLVM_SIMPLE),
era_compiler_common::EXTENSION_LLVM_SOURCE,
llvm_compiler,
)?);
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::ERAVM_SIMPLE,
PathBuf::from(Self::ERAVM_SIMPLE),
era_compiler_common::EXTENSION_ERAVM_ASSEMBLY,
eravm_compiler,
)?);

tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::SOLIDITY_COMPLEX,
PathBuf::from(Self::SOLIDITY_COMPLEX),
era_compiler_common::EXTENSION_JSON,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
Expand All @@ -330,18 +330,18 @@ impl CompilerTester {
if let era_compiler_common::Target::EraVM = target {
tests.extend(self.directory::<MatterLabsDirectory>(
target,
Self::VYPER_COMPLEX,
PathBuf::from(Self::VYPER_COMPLEX),
era_compiler_common::EXTENSION_JSON,
vyper_compiler.clone(),
)?);
}

tests.extend(self.directory::<EthereumDirectory>(
target,
match target {
PathBuf::from(match target {
era_compiler_common::Target::EraVM => Self::SOLIDITY_ETHEREUM,
era_compiler_common::Target::EVM => Self::SOLIDITY_ETHEREUM_UPSTREAM,
},
}),
era_compiler_common::EXTENSION_SOLIDITY,
match toolchain {
Toolchain::IrLLVM => solidity_compiler.clone(),
Expand All @@ -351,7 +351,7 @@ impl CompilerTester {
if let era_compiler_common::Target::EraVM = target {
tests.extend(self.directory::<EthereumDirectory>(
target,
Self::VYPER_ETHEREUM,
PathBuf::from(Self::VYPER_ETHEREUM),
era_compiler_common::EXTENSION_VYPER,
vyper_compiler,
)?);
Expand All @@ -366,7 +366,7 @@ impl CompilerTester {
fn directory<T>(
&self,
target: era_compiler_common::Target,
path: &str,
path: PathBuf,
extension: &'static str,
compiler: Arc<dyn Compiler>,
) -> anyhow::Result<Vec<Test>>
Expand All @@ -375,12 +375,12 @@ impl CompilerTester {
{
Ok(T::read_all(
target,
Path::new(path),
path.as_path(),
extension,
self.summary.clone(),
&self.filters,
)
.map_err(|error| anyhow::anyhow!("Failed to read the tests directory `{path}`: {error}"))?
.map_err(|error| anyhow::anyhow!("Failed to read the tests directory {path:?}: {error}"))?
.into_iter()
.map(|test| Arc::new(test) as Arc<dyn Buildable>)
.cartesian_product(compiler.all_modes())
Expand Down

0 comments on commit ddb5c0e

Please sign in to comment.