Skip to content

Commit

Permalink
Merge pull request #36 from topos-protocol/parse_all_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashtare authored Aug 21, 2023
2 parents 91bf6ca + 6c4528f commit ae799c2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
2 changes: 2 additions & 0 deletions eth_test_parser/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub(crate) const ETH_TESTS_REPO_URL: &str = "https://github.com/ethereum/tests.git";
pub(crate) const ETH_TESTS_REPO_LOCAL_PATH: &str = "eth_tests";
pub(crate) const TEST_GROUPS: [&str; 1] = ["GeneralStateTests"];
// The following subgroups contain subfolders unlike the other test folders.
pub(crate) const SPECIAL_TEST_SUBGROUPS: [&str; 2] = ["Shanghai", "VMTests"];
51 changes: 49 additions & 2 deletions eth_test_parser/src/eth_tests_fetching.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Utils to clone and pull the eth test repo.

use std::{path::Path, process::Command};
use std::{fs, path::Path, process::Command};

use crate::{
config::{ETH_TESTS_REPO_LOCAL_PATH, ETH_TESTS_REPO_URL, TEST_GROUPS},
config::{ETH_TESTS_REPO_LOCAL_PATH, ETH_TESTS_REPO_URL, SPECIAL_TEST_SUBGROUPS, TEST_GROUPS},
fs_scaffolding::get_test_group_dirs,
utils::run_cmd,
};

Expand All @@ -13,6 +14,52 @@ pub(crate) fn clone_or_update_remote_tests() {
} else {
download_remote_tests();
}

// Flatten special folders before parsing test files
flatten_special_folders();
}

#[allow(clippy::permissions_set_readonly_false)]
fn flatten_special_folders() {
let dirs = get_test_group_dirs()
.unwrap()
.flat_map(|entry| fs::read_dir(entry.path()).unwrap())
.flatten()
.filter(|entry| match entry.file_name().to_str() {
Some(file_name) => SPECIAL_TEST_SUBGROUPS.contains(&file_name),
None => false,
});

dirs.for_each(|d| {
let subdirs = fs::read_dir(d.path())
.unwrap()
.flatten()
.filter(|entry| entry.file_type().unwrap().is_dir());

for sd in subdirs {
let new_folder_path = d.path();

fs::read_dir(sd.path())
.unwrap()
.flatten()
.filter(|entry| match entry.path().extension() {
None => false,
Some(ext) => ext == "json",
})
.for_each(|f| {
let mut new_path = new_folder_path.clone();

// Give write access
let mut permissions = new_path.metadata().unwrap().permissions();
permissions.set_readonly(false);
fs::set_permissions(new_path.clone(), permissions).unwrap();

new_path.push(f.file_name().into_string().unwrap().as_str());

fs::copy(f.path(), new_path).unwrap();
})
}
});
}

fn update_remote_tests() {
Expand Down

0 comments on commit ae799c2

Please sign in to comment.