nushell/crates/nu-command/tests/commands/mktemp.rs
Ian Manske f4c0d9d45b
Path migration part 4: various tests (#13373)
# Description
Part 4 of replacing std::path types with nu_path types added in
https://github.com/nushell/nushell/pull/13115. This PR migrates various
tests throughout the code base.
2024-08-03 10:09:13 +02:00

45 lines
1.2 KiB
Rust

use nu_path::AbsolutePath;
use nu_test_support::nu;
use nu_test_support::playground::Playground;
#[test]
fn creates_temp_file() {
Playground::setup("mktemp_test_1", |dirs, _| {
let output = nu!(
cwd: dirs.test(),
"mktemp"
);
let loc = AbsolutePath::try_new(&output.out).unwrap();
println!("{:?}", loc);
assert!(loc.exists());
})
}
#[test]
fn creates_temp_file_with_suffix() {
Playground::setup("mktemp_test_2", |dirs, _| {
let output = nu!(
cwd: dirs.test(),
"mktemp --suffix .txt tempfileXXX"
);
let loc = AbsolutePath::try_new(&output.out).unwrap();
assert!(loc.exists());
assert!(loc.is_file());
assert!(output.out.ends_with(".txt"));
assert!(output.out.starts_with(dirs.test().to_str().unwrap()));
})
}
#[test]
fn creates_temp_directory() {
Playground::setup("mktemp_test_3", |dirs, _| {
let output = nu!(
cwd: dirs.test(),
"mktemp -d"
);
let loc = AbsolutePath::try_new(&output.out).unwrap();
assert!(loc.exists());
assert!(loc.is_dir());
})
}