2023-10-30 13:59:48 +01:00
|
|
|
use nu_test_support::fs::files_exist_at;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
2024-10-11 14:13:42 +02:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
use uucore::mode;
|
|
|
|
|
2023-10-30 13:59:48 +01:00
|
|
|
#[test]
|
|
|
|
fn creates_directory() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_1", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir my_new_directory"
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("my_new_directory");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn accepts_and_creates_directories() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_2", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir dir_1 dir_2 dir_3"
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
2024-08-03 10:09:13 +02:00
|
|
|
assert!(files_exist_at(&["dir_1", "dir_2", "dir_3"], dirs.test()));
|
2023-10-30 13:59:48 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn creates_intermediary_directories() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_3", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir some_folder/another/deeper_one"
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("some_folder/another/deeper_one");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn create_directory_two_parents_up_using_multiple_dots() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_4", |dirs, sandbox| {
|
2023-10-30 13:59:48 +01:00
|
|
|
sandbox.within("foo").mkdir("bar");
|
|
|
|
|
|
|
|
nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir .../boo"
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("boo");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn print_created_paths() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_2", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
pipeline("mkdir -v dir_1 dir_2 dir_3")
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
2024-08-03 10:09:13 +02:00
|
|
|
assert!(files_exist_at(&["dir_1", "dir_2", "dir_3"], dirs.test()));
|
2023-10-30 13:59:48 +01:00
|
|
|
|
|
|
|
assert!(actual.out.contains("dir_1"));
|
|
|
|
assert!(actual.out.contains("dir_2"));
|
|
|
|
assert!(actual.out.contains("dir_3"));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn creates_directory_three_dots() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_1", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir test..."
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("test...");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn creates_directory_four_dots() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_1", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir test...."
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("test....");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn creates_directory_three_dots_quotation_marks() {
|
2024-02-28 13:27:10 +01:00
|
|
|
Playground::setup("mkdir_test_1", |dirs, _| {
|
2023-10-30 13:59:48 +01:00
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
2024-02-28 13:27:10 +01:00
|
|
|
"mkdir 'test...'"
|
2023-10-30 13:59:48 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("test...");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
2024-03-14 22:43:42 +01:00
|
|
|
|
2024-04-04 14:23:10 +02:00
|
|
|
#[test]
|
|
|
|
fn respects_cwd() {
|
|
|
|
Playground::setup("mkdir_respects_cwd", |dirs, _| {
|
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
"mkdir 'some_folder'; cd 'some_folder'; mkdir 'another/deeper_one'"
|
|
|
|
);
|
|
|
|
|
|
|
|
let expected = dirs.test().join("some_folder/another/deeper_one");
|
|
|
|
|
|
|
|
assert!(expected.exists());
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-14 22:43:42 +01:00
|
|
|
#[cfg(not(windows))]
|
|
|
|
#[test]
|
|
|
|
fn mkdir_umask_permission() {
|
|
|
|
use std::{fs, os::unix::fs::PermissionsExt};
|
|
|
|
|
|
|
|
Playground::setup("mkdir_umask_permission", |dirs, _| {
|
|
|
|
nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
"mkdir test_umask_permission"
|
|
|
|
);
|
|
|
|
let actual = fs::metadata(dirs.test().join("test_umask_permission"))
|
|
|
|
.unwrap()
|
|
|
|
.permissions()
|
|
|
|
.mode();
|
|
|
|
|
2024-10-11 14:13:42 +02:00
|
|
|
let umask = mode::get_umask();
|
|
|
|
let default_mode = 0o40777;
|
|
|
|
let expected: u32 = default_mode & !umask;
|
|
|
|
|
2024-03-14 22:43:42 +01:00
|
|
|
assert_eq!(
|
2024-10-11 14:13:42 +02:00
|
|
|
actual, expected,
|
|
|
|
"Umask should have been applied to created folder"
|
2024-03-14 22:43:42 +01:00
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 03:08:38 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mkdir_with_tilde() {
|
|
|
|
Playground::setup("mkdir with tilde", |dirs, _| {
|
|
|
|
let actual = nu!(cwd: dirs.test(), "mkdir '~tilde'");
|
|
|
|
assert!(actual.err.is_empty());
|
2024-08-03 10:09:13 +02:00
|
|
|
assert!(files_exist_at(&["~tilde"], dirs.test()));
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 03:08:38 +01:00
|
|
|
|
|
|
|
// pass variable
|
|
|
|
let actual = nu!(cwd: dirs.test(), "let f = '~tilde2'; mkdir $f");
|
|
|
|
assert!(actual.err.is_empty());
|
2024-08-03 10:09:13 +02:00
|
|
|
assert!(files_exist_at(&["~tilde2"], dirs.test()));
|
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# Description
Fixes: #11887
Fixes: #11626
This pr unify the tilde expand behavior over several filesystem relative
commands. It follows the same rule with glob expansion:
| command | result |
| ----------- | ------ |
| ls ~/aaa | expand tilde
| ls "~/aaa" | don't expand tilde
| let f = "~/aaa"; ls $f | don't expand tilde, if you want to: use `ls
($f \| path expand)`
| let f: glob = "~/aaa"; ls $f | expand tilde, they don't expand on
`mkdir`, `touch` comamnd.
Actually I'm not sure for 4th item, currently it's expanding is just
because it followes the same rule with glob expansion.
### About the change
It changes `expand_path_with` to accept a new argument called
`expand_tilde`, if it's true, expand it, if not, just keep it as `~`
itself.
# User-Facing Changes
After this change, `ls "~/aaa"` won't expand tilde.
# Tests + Formatting
Done
2024-03-25 03:08:38 +01:00
|
|
|
})
|
|
|
|
}
|