Fix import name for path utilities.

This commit is contained in:
jcamiel 2023-02-15 13:50:49 +01:00
parent ec39c59d05
commit ba3c95c02d
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
6 changed files with 17 additions and 18 deletions

View File

@ -16,7 +16,7 @@
* *
*/ */
use crate::util; use crate::util::path;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
/// Represents the directories used to run a Hurl file. /// Represents the directories used to run a Hurl file.
@ -60,7 +60,7 @@ impl ContextDir {
let file = self.get_path(filename); let file = self.get_path(filename);
let absolute_file = self.current_dir.join(file); let absolute_file = self.current_dir.join(file);
let absolute_file_root = self.current_dir.join(&self.file_root); 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())
} }
} }

View File

@ -27,11 +27,12 @@ use colored::*;
use hurl::cli::{CliError, CliOptions, Logger, OutputType}; use hurl::cli::{CliError, CliOptions, Logger, OutputType};
use hurl::http; use hurl::http;
use hurl::report; use hurl::report;
use hurl::report::{canonicalize_filename, html}; use hurl::report::html;
use hurl::runner; use hurl::runner;
use hurl::runner::HurlResult; use hurl::runner::HurlResult;
use hurl::runner::RunnerOptions; use hurl::runner::RunnerOptions;
use hurl::util::logger::{BaseLogger, LoggerBuilder}; use hurl::util::logger::{BaseLogger, LoggerBuilder};
use hurl::util::path;
use hurl::{cli, output}; use hurl::{cli, output};
use hurl_core::ast::HurlFile; use hurl_core::ast::HurlFile;
use hurl_core::parser; 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> { fn create_html_report(runs: &[Run], dir_path: &Path) -> Result<(), CliError> {
let hurl_results = runs.iter().map(|it| &it.result).collect::<Vec<_>>(); let hurl_results = runs.iter().map(|it| &it.result).collect::<Vec<_>>();
html::write_report(dir_path, &hurl_results)?; html::write_report(dir_path, &hurl_results)?;
for run in runs.iter() { for run in runs.iter() {
let filename = &run.result.filename; let filename = &run.result.filename;
format_html(filename, dir_path)?; format_html(filename, dir_path)?;
@ -355,7 +357,7 @@ fn get_input_files(
} }
fn format_html(input_file: &str, dir_path: &Path) -> Result<(), CliError> { 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 absolute_input_file = dir_path.join(format!("{relative_input_file}.html"));
let parent = absolute_input_file.parent().expect("a parent"); let parent = absolute_input_file.parent().expect("a parent");

View File

@ -19,8 +19,8 @@
//! HTML report //! HTML report
use crate::cli::CliError; use crate::cli::CliError;
use crate::report::canonicalize_filename;
use crate::runner::HurlResult; use crate::runner::HurlResult;
use crate::util::path;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use std::io::Write; use std::io::Write;
use std::path::Path; 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)?; let mut results = parse_html(&index_path)?;
for result in hurl_results.iter() { for result in hurl_results.iter() {
let html_result = HTMLResult { let html_result = HTMLResult {
filename: canonicalize_filename(&result.filename), filename: path::canonicalize_filename(&result.filename),
time_in_ms: result.time_in_ms, time_in_ms: result.time_in_ms,
success: result.success, success: result.success,
}; };

View File

@ -20,12 +20,3 @@
pub mod html; pub mod html;
pub mod junit; 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()
}

View File

@ -15,7 +15,5 @@
* limitations under the License. * limitations under the License.
* *
*/ */
pub use self::path::is_descendant;
pub mod logger; pub mod logger;
mod path; pub mod path;

View File

@ -17,6 +17,14 @@
*/ */
use std::path::{Component, Path, PathBuf}; 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. /// Return true if `path` is a descendant path of `ancestor`, false otherwise.
pub fn is_descendant(path: &Path, ancestor: &Path) -> bool { pub fn is_descendant(path: &Path, ancestor: &Path) -> bool {
let path = normalize_path(path); let path = normalize_path(path);