Skip to content

Commit

Permalink
Use project root as default path for fe test (ethereum#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf authored Aug 16, 2023
1 parent 79cc5c2 commit 6ba3f04
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
25 changes: 24 additions & 1 deletion crates/common/src/utils/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use path_clean::PathClean;
use smol_str::SmolStr;
use walkdir::WalkDir;

const FE_TOML: &str = "fe.toml";

enum FileLoader {
Static(Vec<(&'static str, &'static str)>),
Fs,
Expand Down Expand Up @@ -141,7 +143,7 @@ pub struct ProjectFiles {
impl ProjectFiles {
fn load(loader: &FileLoader, path: &str) -> Result<Self, String> {
let manifest_path = Path::new(path)
.join("fe.toml")
.join(FE_TOML)
.to_str()
.expect("unable to convert path to &str")
.to_owned();
Expand Down Expand Up @@ -292,3 +294,24 @@ impl Manifest {
Ok(manifest)
}
}

/// Returns the root path of the current Fe project
pub fn get_project_root() -> Option<String> {
let current_dir = std::env::current_dir().expect("Unable to get current directory");

let mut current_path = current_dir.clone();
loop {
let fe_toml_path = current_path.join(FE_TOML);
if fe_toml_path.is_file() {
return fe_toml_path
.parent()
.map(|val| val.to_string_lossy().to_string());
}

if !current_path.pop() {
break;
}
}

None
}
3 changes: 2 additions & 1 deletion crates/fe/src/task/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use std::path::Path;
use clap::Args;
use colored::Colorize;
use fe_common::diagnostics::print_diagnostics;
use fe_common::utils::files::BuildFiles;
use fe_common::utils::files::{get_project_root, BuildFiles};
use fe_driver::CompiledTest;
use fe_test_runner::TestSink;

#[derive(Args)]
#[clap(about = "Execute tests in the current project")]
pub struct TestArgs {
#[clap(default_value_t = get_project_root().unwrap_or(".".to_string()))]
input_path: String,
#[clap(long, takes_value(true))]
optimize: Option<bool>,
Expand Down
3 changes: 3 additions & 0 deletions newsfragments/913.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Use the project root as default path for `fe test`

Just run `fe test` from any directory of the project.

0 comments on commit 6ba3f04

Please sign in to comment.