diff --git a/tests/commands_test.rs b/tests/commands_test.rs index 3ed2eb7037..9b131256be 100644 --- a/tests/commands_test.rs +++ b/tests/commands_test.rs @@ -13,49 +13,48 @@ fn lines() { assert_eq!(output, "rustyline"); } -// #[test] -// fn save_figures_out_intelligently_where_to_write_out_with_metadata() { -// let sandbox = Playground::setup_for("save_smart_test") -// .with_files(vec![FileWithContent( -// "cargo_sample.toml", -// r#" -// [package] -// name = "nu" -// version = "0.1.1" -// authors = ["Yehuda Katz "] -// description = "A shell for the GitHub era" -// license = "ISC" -// edition = "2018" -// "#, -// )]) -// .test_dir_name(); +#[test] +fn save_figures_out_intelligently_where_to_write_out_with_metadata() { + Playground::setup("save_smart_test", |dirs, playground| { + playground + .with_files(vec![FileWithContent( + "cargo_sample.toml", + r#" + [package] + name = "nu" + version = "0.1.1" + authors = ["Yehuda Katz "] + description = "A shell for the GitHub era" + license = "ISC" + edition = "2018" + "#, + )]) + .test_dir_name(); -// let full_path = format!("{}/{}", Playground::root(), sandbox); -// let subject_file = format!("{}/{}", full_path, "cargo_sample.toml"); + let subject_file = dirs.test().join("cargo_sample.toml"); -// nu!( -// _output, -// cwd(&Playground::root()), -// "open save_smart_test/cargo_sample.toml | inc package.version --minor | save" -// ); + nu!( + dirs.root(), + "open save_smart_test/cargo_sample.toml | inc package.version --minor | save" + ); -// let actual = h::file_contents(&subject_file); -// assert!(actual.contains("0.2.0")); -// } + let actual = h::file_contents(&subject_file); + assert!(actual.contains("0.2.0")); + }) +} -// #[test] -// fn save_can_write_out_csv() { -// let sandbox = Playground::setup_for("save_writes_out_csv_test").test_dir_name(); +#[test] +fn save_can_write_out_csv() { + Playground::setup("save_writes_out_csv_test", |dirs, playground| { + let expected_file = dirs.test().join("cargo_sample.csv"); -// let full_path = format!("{}/{}", Playground::root(), sandbox); -// let expected_file = format!("{}/{}", full_path, "cargo_sample.csv"); + nu!( + dirs.root(), + "open {}/cargo_sample.toml | inc package.version --minor | get package | save save_writes_out_csv_test/cargo_sample.csv", + dirs.formats() + ); -// nu!( -// _output, -// cwd(&Playground::root()), -// "open ../formats/cargo_sample.toml | inc package.version --minor | get package | save save_writes_out_csv_test/cargo_sample.csv" -// ); - -// let actual = h::file_contents(&expected_file); -// assert!(actual.contains("[list list],A shell for the GitHub era,2018,ISC,nu,0.2.0")); -// } + let actual = h::file_contents(expected_file); + assert!(actual.contains("[list list],A shell for the GitHub era,2018,ISC,nu,0.2.0")); + }) +} diff --git a/tests/helpers/mod.rs b/tests/helpers/mod.rs index f744da6775..5009284c0e 100644 --- a/tests/helpers/mod.rs +++ b/tests/helpers/mod.rs @@ -299,8 +299,8 @@ impl Playground { } } -pub fn file_contents(full_path: &str) -> String { - let mut file = std::fs::File::open(full_path).expect("can not open file"); +pub fn file_contents(full_path: impl AsRef) -> String { + let mut file = std::fs::File::open(full_path.as_ref()).expect("can not open file"); let mut contents = String::new(); file.read_to_string(&mut contents) .expect("can not read file");