Fix path type using PWD from the environment (#12975)

This PR fixes the `path type` command so that it resolves relative paths
using PWD from the engine state.

As a bonus, it also fixes the issue of `path type` returning an empty
string instead of an error when it fails.
This commit is contained in:
YizhePKU
2024-05-27 01:23:52 +08:00
committed by GitHub
parent f38f88d42c
commit a1fc41db22
2 changed files with 30 additions and 23 deletions

View File

@ -74,3 +74,14 @@ fn returns_type_of_existing_file_const() {
assert_eq!(actual.out, "dir");
})
}
#[test]
fn respects_cwd() {
Playground::setup("path_type_respects_cwd", |dirs, sandbox| {
sandbox.within("foo").with_files(&[EmptyFile("bar.txt")]);
let actual = nu!(cwd: dirs.test(), "cd foo; 'bar.txt' | path type");
assert_eq!(actual.out, "file");
})
}