mirror of
https://github.com/nushell/nushell.git
synced 2024-11-15 04:54:46 +01:00
21ad06b1e1
The original intent of this patch was to remove more unwraps to reduce panics. I then lost a ton of time to the fact that the playground isn't in a temp directory (because of permissions issues on Windows). This commit improves the test facilities to: - use a tempdir for the playground - change the playground API so you instantiate it with a block that encloses the lifetime of the tempdir - the block is called with a `dirs` argument that has `dirs.test()` and other important directories that we were computing by hand all the time - the block is also called with a `playground` argument that you can use to construct files (it's the same `Playground` as before) - change the nu! and nu_error! macros to produce output instead of taking a variable binding - change the nu! and nu_error! macros to do the cwd() transformation internally - change the nu! and nu_error! macros to take varargs at the end that get interpolated into the running command I didn't manage to finish porting all of the tests, so a bunch of tests are currently commented out. That will need to change before we land this patch.
76 lines
2.1 KiB
Rust
76 lines
2.1 KiB
Rust
mod helpers;
|
|
|
|
use h::{Playground, Stub::*};
|
|
use helpers as h;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
#[test]
|
|
fn knows_the_filesystems_entered() {
|
|
Playground::setup("enter_filesystem_sessions_test", |dirs, playground| {
|
|
playground
|
|
.within("red_pill")
|
|
.with_files(vec![
|
|
EmptyFile("andres.nu"),
|
|
EmptyFile("jonathan.nu"),
|
|
EmptyFile("yehuda.nu"),
|
|
])
|
|
.within("blue_pill")
|
|
.with_files(vec![
|
|
EmptyFile("bash.nxt"),
|
|
EmptyFile("korn.nxt"),
|
|
EmptyFile("powedsh.nxt"),
|
|
])
|
|
.mkdir("expected")
|
|
.test_dir_name();
|
|
|
|
let red_pill_dir = dirs.test().join("red_pill");
|
|
let blue_pill_dir = dirs.test().join("blue_pill");
|
|
let expected = dirs.test().join("expected");
|
|
let expected_recycled = expected.join("recycled");
|
|
|
|
nu!(
|
|
dirs.test(),
|
|
r#"
|
|
enter expected
|
|
mkdir recycled
|
|
enter ../red_pill
|
|
mv jonathan.nu ../expected
|
|
enter ../blue_pill
|
|
cp *.nxt ../expected/recycled
|
|
p
|
|
p
|
|
mv ../red_pill/yehuda.nu .
|
|
n
|
|
mv andres.nu ../expected/andres.nu
|
|
exit
|
|
cd ..
|
|
rm red_pill --recursive
|
|
exit
|
|
n
|
|
rm blue_pill --recursive
|
|
exit
|
|
"#
|
|
);
|
|
|
|
assert!(!h::dir_exists_at(PathBuf::from(red_pill_dir)));
|
|
assert!(h::files_exist_at(
|
|
vec![
|
|
Path::new("andres.nu"),
|
|
Path::new("jonathan.nu"),
|
|
Path::new("yehuda.nu"),
|
|
],
|
|
PathBuf::from(&expected)
|
|
));
|
|
|
|
assert!(!h::dir_exists_at(PathBuf::from(blue_pill_dir)));
|
|
assert!(h::files_exist_at(
|
|
vec![
|
|
Path::new("bash.nxt"),
|
|
Path::new("korn.nxt"),
|
|
Path::new("powedsh.nxt"),
|
|
],
|
|
PathBuf::from(&expected_recycled)
|
|
));
|
|
})
|
|
}
|