1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

pr: rustfmt test_pr.rs and utils.rs

This commit is contained in:
Terts Diepraam 2021-05-29 19:34:17 +02:00
parent bc1870c0a7
commit b0bf3e7e0f
2 changed files with 13 additions and 5 deletions

View file

@ -1,7 +1,7 @@
use crate::common::util::*; use crate::common::util::*;
use std::fs::metadata;
use chrono::offset::Local; use chrono::offset::Local;
use chrono::DateTime; use chrono::DateTime;
use std::fs::metadata;
fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String { fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String {
let tmp_dir_path = ucmd.get_full_fixture_path(path); let tmp_dir_path = ucmd.get_full_fixture_path(path);
@ -245,7 +245,10 @@ fn test_with_no_header_trailer_option() {
scenario scenario
.args(&["-t", test_file_path]) .args(&["-t", test_file_path])
.succeeds() .succeeds()
.stdout_is_templated_fixture(expected_test_file_path, vec![(&"{last_modified_time}".to_string(), &value)]); .stdout_is_templated_fixture(
expected_test_file_path,
vec![(&"{last_modified_time}".to_string(), &value)],
);
} }
#[test] #[test]

View file

@ -226,8 +226,13 @@ impl CmdResult {
} }
/// like stdout_is_fixture(...), but replaces the data in fixture file based on values provided in template_vars /// like stdout_is_fixture(...), but replaces the data in fixture file based on values provided in template_vars
/// command output /// command output
pub fn stdout_is_templated_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T, template_vars: Vec<(&String, &String)>) -> &CmdResult { pub fn stdout_is_templated_fixture<T: AsRef<OsStr>>(
let mut contents = String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap(); &self,
file_rel_path: T,
template_vars: Vec<(&String, &String)>,
) -> &CmdResult {
let mut contents =
String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap();
for kv in template_vars { for kv in template_vars {
contents = contents.replace(kv.0, kv.1); contents = contents.replace(kv.0, kv.1);
} }
@ -923,7 +928,7 @@ impl UCommand {
cmd_result cmd_result
} }
pub fn get_full_fixture_path(&self, file_rel_path: &str) -> String{ pub fn get_full_fixture_path(&self, file_rel_path: &str) -> String {
let tmpdir_path = self.tmpd.as_ref().unwrap().path(); let tmpdir_path = self.tmpd.as_ref().unwrap().path();
format!("{}/{}", tmpdir_path.to_str().unwrap(), file_rel_path) format!("{}/{}", tmpdir_path.to_str().unwrap(), file_rel_path)
} }