diff --git a/packages/hurl/src/http/context_dir.rs b/packages/hurl/src/http/context_dir.rs index abf976900..dd1be1316 100644 --- a/packages/hurl/src/http/context_dir.rs +++ b/packages/hurl/src/http/context_dir.rs @@ -16,7 +16,7 @@ * */ -use crate::util; +use crate::util::path; use std::path::{Path, PathBuf}; /// Represents the directories used to run a Hurl file. @@ -60,7 +60,7 @@ impl ContextDir { let file = self.get_path(filename); let absolute_file = self.current_dir.join(file); let absolute_file_root = self.current_dir.join(&self.file_root); - util::is_descendant(absolute_file.as_path(), absolute_file_root.as_path()) + path::is_descendant(absolute_file.as_path(), absolute_file_root.as_path()) } } diff --git a/packages/hurl/src/main.rs b/packages/hurl/src/main.rs index e69d64af7..4cea3d87d 100644 --- a/packages/hurl/src/main.rs +++ b/packages/hurl/src/main.rs @@ -27,11 +27,12 @@ use colored::*; use hurl::cli::{CliError, CliOptions, Logger, OutputType}; use hurl::http; use hurl::report; -use hurl::report::{canonicalize_filename, html}; +use hurl::report::html; use hurl::runner; use hurl::runner::HurlResult; use hurl::runner::RunnerOptions; use hurl::util::logger::{BaseLogger, LoggerBuilder}; +use hurl::util::path; use hurl::{cli, output}; use hurl_core::ast::HurlFile; use hurl_core::parser; @@ -294,6 +295,7 @@ fn create_junit_report(runs: &[Run], filename: &str) -> Result<(), CliError> { fn create_html_report(runs: &[Run], dir_path: &Path) -> Result<(), CliError> { let hurl_results = runs.iter().map(|it| &it.result).collect::>(); html::write_report(dir_path, &hurl_results)?; + for run in runs.iter() { let filename = &run.result.filename; format_html(filename, dir_path)?; @@ -355,7 +357,7 @@ fn get_input_files( } fn format_html(input_file: &str, dir_path: &Path) -> Result<(), CliError> { - let relative_input_file = canonicalize_filename(input_file); + let relative_input_file = path::canonicalize_filename(input_file); let absolute_input_file = dir_path.join(format!("{relative_input_file}.html")); let parent = absolute_input_file.parent().expect("a parent"); diff --git a/packages/hurl/src/report/html/mod.rs b/packages/hurl/src/report/html/mod.rs index b16486594..7c5cc8d06 100644 --- a/packages/hurl/src/report/html/mod.rs +++ b/packages/hurl/src/report/html/mod.rs @@ -19,8 +19,8 @@ //! HTML report use crate::cli::CliError; -use crate::report::canonicalize_filename; use crate::runner::HurlResult; +use crate::util::path; use chrono::{DateTime, Local}; use std::io::Write; use std::path::Path; @@ -44,7 +44,7 @@ pub fn write_report(dir_path: &Path, hurl_results: &[&HurlResult]) -> Result<(), let mut results = parse_html(&index_path)?; for result in hurl_results.iter() { let html_result = HTMLResult { - filename: canonicalize_filename(&result.filename), + filename: path::canonicalize_filename(&result.filename), time_in_ms: result.time_in_ms, success: result.success, }; diff --git a/packages/hurl/src/report/mod.rs b/packages/hurl/src/report/mod.rs index c9e7c676c..a38144839 100644 --- a/packages/hurl/src/report/mod.rs +++ b/packages/hurl/src/report/mod.rs @@ -20,12 +20,3 @@ pub mod html; pub mod junit; -use std::path::Path; - -/// Returns the canonical fullname relative to / (technically a relative path) -/// The function will panic if the input file does not exist -pub fn canonicalize_filename(input_file: &str) -> String { - let relative_input_file = Path::new(input_file).canonicalize().expect("existing file"); - let relative_input_file = relative_input_file.to_string_lossy(); - relative_input_file.trim_start_matches('/').to_string() -} diff --git a/packages/hurl/src/util/mod.rs b/packages/hurl/src/util/mod.rs index 7f8c6acd1..8c46dbb01 100644 --- a/packages/hurl/src/util/mod.rs +++ b/packages/hurl/src/util/mod.rs @@ -15,7 +15,5 @@ * limitations under the License. * */ -pub use self::path::is_descendant; - pub mod logger; -mod path; +pub mod path; diff --git a/packages/hurl/src/util/path.rs b/packages/hurl/src/util/path.rs index b3ba17bb1..567b7d6ac 100644 --- a/packages/hurl/src/util/path.rs +++ b/packages/hurl/src/util/path.rs @@ -17,6 +17,14 @@ */ use std::path::{Component, Path, PathBuf}; +/// Returns the canonical fullname relative to / (technically a relative path) +/// The function will panic if the input file does not exist +pub fn canonicalize_filename(input_file: &str) -> String { + let relative_input_file = Path::new(input_file).canonicalize().expect("existing file"); + let relative_input_file = relative_input_file.to_string_lossy(); + relative_input_file.trim_start_matches('/').to_string() +} + /// Return true if `path` is a descendant path of `ancestor`, false otherwise. pub fn is_descendant(path: &Path, ancestor: &Path) -> bool { let path = normalize_path(path);