mirror of
https://github.com/nushell/nushell
synced 2024-11-16 09:47:57 +00:00
9850fbd77d
chrono version update # Description upgrade chrono to 0.4.23 # Major Changes If you're considering making any major change to nushell, before starting work on it, seek feedback from regular contributors and get approval for the idea from the core team either on [Discord](https://discordapp.com/invite/NtAbbGn) or [GitHub issue](https://github.com/nushell/nushell/issues/new/choose). Making sure we're all on board with the change saves everybody's time. Thanks! # Tests + Formatting Make sure you've done the following, if applicable: - Add tests that cover your changes (either in the command examples, the crate/tests folder, or in the /tests folder) - Try to think about corner cases and various ways how your changes could break. Cover those in the tests Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace --features=extra` to check that all tests pass # After Submitting * Help us keep the docs up to date: If your PR affects the user experience of Nushell (adding/removing a command, changing an input/output type, etc.), make sure the changes are reflected in the documentation (https://github.com/nushell/nushell.github.io) after the PR is merged. Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
124 lines
3.3 KiB
Rust
124 lines
3.3 KiB
Rust
use chrono::{DateTime, Local};
|
|
use nu_test_support::fs::Stub;
|
|
use nu_test_support::nu;
|
|
use nu_test_support::playground::Playground;
|
|
|
|
#[test]
|
|
fn creates_a_file_when_it_doesnt_exist() {
|
|
Playground::setup("create_test_1", |dirs, _sandbox| {
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
"touch i_will_be_created.txt"
|
|
);
|
|
|
|
let path = dirs.test().join("i_will_be_created.txt");
|
|
assert!(path.exists());
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn creates_two_files() {
|
|
Playground::setup("create_test_2", |dirs, _sandbox| {
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
"touch a b"
|
|
);
|
|
|
|
let path = dirs.test().join("a");
|
|
assert!(path.exists());
|
|
|
|
let path2 = dirs.test().join("b");
|
|
assert!(path2.exists());
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn change_modified_time_of_file_to_today() {
|
|
Playground::setup("change_time_test_9", |dirs, sandbox| {
|
|
sandbox.with_files(vec![Stub::EmptyFile("file.txt")]);
|
|
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
"touch -m file.txt"
|
|
);
|
|
|
|
let path = dirs.test().join("file.txt");
|
|
|
|
// Check only the date since the time may not match exactly
|
|
let date = Local::now().date_naive();
|
|
let actual_date_time: DateTime<Local> =
|
|
DateTime::from(path.metadata().unwrap().modified().unwrap());
|
|
let actual_date = actual_date_time.date_naive();
|
|
|
|
assert_eq!(date, actual_date);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn change_access_time_of_file_to_today() {
|
|
Playground::setup("change_time_test_18", |dirs, sandbox| {
|
|
sandbox.with_files(vec![Stub::EmptyFile("file.txt")]);
|
|
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
"touch -a file.txt"
|
|
);
|
|
|
|
let path = dirs.test().join("file.txt");
|
|
|
|
// Check only the date since the time may not match exactly
|
|
let date = Local::now().date_naive();
|
|
let actual_date_time: DateTime<Local> =
|
|
DateTime::from(path.metadata().unwrap().accessed().unwrap());
|
|
let actual_date = actual_date_time.date_naive();
|
|
|
|
assert_eq!(date, actual_date);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn change_modified_and_access_time_of_file_to_today() {
|
|
Playground::setup("change_time_test_27", |dirs, sandbox| {
|
|
sandbox.with_files(vec![Stub::EmptyFile("file.txt")]);
|
|
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
"touch -a -m file.txt"
|
|
);
|
|
|
|
let metadata = dirs.test().join("file.txt").metadata().unwrap();
|
|
|
|
// Check only the date since the time may not match exactly
|
|
let date = Local::now().date_naive();
|
|
let adate_time: DateTime<Local> = DateTime::from(metadata.accessed().unwrap());
|
|
let adate = adate_time.date_naive();
|
|
let mdate_time: DateTime<Local> = DateTime::from(metadata.modified().unwrap());
|
|
let mdate = mdate_time.date_naive();
|
|
|
|
assert_eq!(date, adate);
|
|
assert_eq!(date, mdate);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn not_create_file_if_it_not_exists() {
|
|
Playground::setup("change_time_test_28", |dirs, _sandbox| {
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
r#"touch -c file.txt"#
|
|
);
|
|
|
|
let path = dirs.test().join("file.txt");
|
|
|
|
assert!(!path.exists());
|
|
|
|
nu!(
|
|
cwd: dirs.test(),
|
|
r#"touch -c file.txt"#
|
|
);
|
|
|
|
let path = dirs.test().join("file.txt");
|
|
|
|
assert!(!path.exists());
|
|
})
|
|
}
|