Selaa lähdekoodia

test: add tests for non-recent/recent custom time style

SPQV MF 2 vuotta sitten
vanhempi
sitoutus
131ad8afc1

+ 23 - 0
devtools/generate-timestamp-test-dir.sh

@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+if [ -z "$1" ]; then
+    echo "Usage: $0 <output_dir>";
+    exit 1;
+fi
+
+rm "$1" -rf;
+mkdir -p "$1";
+cd "$1" || exit;
+
+# generate files of various age
+# TODO: some are commented out due to undeterministic behavior, see:
+# https://github.com/eza-community/eza/issues/574
+
+touch --date="13 month ago"  ./13_month
+#touch --date="11 month ago"  ./11_month
+#touch --date="7 month ago"   ./07_month
+#touch --date="5 month ago"   ./05_month
+touch --date="now"           ./now
+#touch --date="next hour"     ./next_hour
+#touch --date="next month"    ./next_month
+#touch --date="next year"     ./next_year

+ 9 - 2
flake.nix

@@ -152,7 +152,10 @@
             # buildPhase files differ between dep and main phase
             singleStep = true;
             # generate testing files
-            buildPhase = ''bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated"'';
+            buildPhase = ''
+              bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated"
+              bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
+            '';
             cargoTestOptions = opts: opts ++ ["--features nix"];
             inherit buildInputs;
             nativeBuildInputs = with pkgs; [git];
@@ -169,7 +172,10 @@
             # buildPhase files differ between dep and main phase
             singleStep = true;
             # set itests files creation date to unix epoch
-            buildPhase = ''touch --date=@0 tests/itest/* && bash devtools/dir-generator.sh tests/test_dir'';
+            buildPhase = ''
+              touch --date=@0 tests/itest/* && bash devtools/dir-generator.sh tests/test_dir
+              bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
+            '';
             cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local" "--features powertest"];
             inherit buildInputs;
             nativeBuildInputs = with pkgs; [git];
@@ -187,6 +193,7 @@
             # set itests files creation date to unix epoch
             buildPhase = ''
               bash devtools/dir-generator.sh tests/test_dir
+              bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
               touch --date=@0 tests/itest/*;
               rm tests/cmd/*.stdout || echo;
               rm tests/cmd/*.stderr || echo;

+ 8 - 7
src/options/view.rs

@@ -652,13 +652,14 @@ mod test {
         test!(empty:     TimeFormat <- [], None;                            Both => like Ok(TimeFormat::DefaultFormat));
 
         // Individual settings
-        test!(default:          TimeFormat <- ["--time-style=default"], None;      Both => like Ok(TimeFormat::DefaultFormat));
-        test!(iso:              TimeFormat <- ["--time-style", "iso"], None;       Both => like Ok(TimeFormat::ISOFormat));
-        test!(relative:         TimeFormat <- ["--time-style", "relative"], None;  Both => like Ok(TimeFormat::Relative));
-        test!(long_iso:         TimeFormat <- ["--time-style=long-iso"], None;     Both => like Ok(TimeFormat::LongISO));
-        test!(full_iso:         TimeFormat <- ["--time-style", "full-iso"], None;  Both => like Ok(TimeFormat::FullISO));
-        test!(custom_style:     TimeFormat <- ["--time-style", "+%Y/%m/%d"], None; Both => like Ok(TimeFormat::Custom { .. }));
-        test!(bad_custom_style: TimeFormat <- ["--time-style", "%Y/%m/%d"], None;  Both => err OptionsError::BadArgument(&flags::TIME_STYLE, OsString::from("%Y/%m/%d")));
+        test!(default:                TimeFormat <- ["--time-style=default"], None;               Both => like Ok(TimeFormat::DefaultFormat));
+        test!(iso:                    TimeFormat <- ["--time-style", "iso"], None;                Both => like Ok(TimeFormat::ISOFormat));
+        test!(relative:               TimeFormat <- ["--time-style", "relative"], None;           Both => like Ok(TimeFormat::Relative));
+        test!(long_iso:               TimeFormat <- ["--time-style=long-iso"], None;              Both => like Ok(TimeFormat::LongISO));
+        test!(full_iso:               TimeFormat <- ["--time-style", "full-iso"], None;           Both => like Ok(TimeFormat::FullISO));
+        test!(custom_style:           TimeFormat <- ["--time-style", "+%Y/%m/%d"], None;          Both => like Ok(TimeFormat::Custom { recent: None, .. }));
+        test!(custom_style_multiline: TimeFormat <- ["--time-style", "+%Y/%m/%d\n--%m-%d"], None; Both => like Ok(TimeFormat::Custom { recent: Some(_), .. }));
+        test!(bad_custom_style:       TimeFormat <- ["--time-style", "%Y/%m/%d"], None;           Both => err OptionsError::BadArgument(&flags::TIME_STYLE, OsString::from("%Y/%m/%d")));
 
         // Overriding
         test!(actually:  TimeFormat <- ["--time-style=default", "--time-style", "iso"], None;  Last => like Ok(TimeFormat::ISOFormat));

+ 0 - 0
tests/gen/long_time_style_custom_non_recent_and_recent_nix.stderr


+ 2 - 0
tests/gen/long_time_style_custom_non_recent_and_recent_nix.stdout

@@ -0,0 +1,2 @@
+NON_RECENT 13_month
+    RECENT now

+ 2 - 0
tests/gen/long_time_style_custom_non_recent_and_recent_nix.toml

@@ -0,0 +1,2 @@
+bin.name = "eza"
+args = "tests/timestamp_test_dir --long --no-permissions --no-filesize --no-user --sort=modified --time-style='+NON_RECENT\n    RECENT'"

+ 2 - 0
tests/gen/long_time_style_custom_non_recent_empty_nix.stderr

@@ -0,0 +1,2 @@
+[..]Custom timestamp format is empty, please supply a chrono format string after the plus sign.[..]
+...

+ 0 - 0
tests/gen/long_time_style_custom_non_recent_empty_nix.stdout


+ 3 - 0
tests/gen/long_time_style_custom_non_recent_empty_nix.toml

@@ -0,0 +1,3 @@
+bin.name = "eza"
+args = "tests/timestamp_test_dir --long --no-permissions --no-filesize --no-user --sort=modified --time-style='+\n'"
+status.code = 101

+ 2 - 0
tests/gen/long_time_style_custom_non_recent_none_nix.stderr

@@ -0,0 +1,2 @@
+[..]Custom timestamp format is empty, please supply a chrono format string after the plus sign.[..]
+...

+ 0 - 0
tests/gen/long_time_style_custom_non_recent_none_nix.stdout


+ 3 - 0
tests/gen/long_time_style_custom_non_recent_none_nix.toml

@@ -0,0 +1,3 @@
+bin.name = "eza"
+args = "tests/timestamp_test_dir --long --no-permissions --no-filesize --no-user --sort=modified --time-style='+'"
+status.code = 101

+ 0 - 0
tests/gen/long_time_style_custom_non_recent_only_nix.stderr


+ 2 - 0
tests/gen/long_time_style_custom_non_recent_only_nix.stdout

@@ -0,0 +1,2 @@
+NON_RECENT 13_month
+NON_RECENT now

+ 2 - 0
tests/gen/long_time_style_custom_non_recent_only_nix.toml

@@ -0,0 +1,2 @@
+bin.name = "eza"
+args = "tests/timestamp_test_dir --long --no-permissions --no-filesize --no-user --sort=modified --time-style='+NON_RECENT'"

+ 2 - 0
tests/gen/long_time_style_custom_recent_empty_nix.stderr

@@ -0,0 +1,2 @@
+[..]Custom timestamp format for recent files is empty, please supply a chrono format string at the second line.[..]
+...

+ 0 - 0
tests/gen/long_time_style_custom_recent_empty_nix.stdout


+ 3 - 0
tests/gen/long_time_style_custom_recent_empty_nix.toml

@@ -0,0 +1,3 @@
+bin.name = "eza"
+args = "tests/timestamp_test_dir --long --no-permissions --no-filesize --no-user --sort=modified --time-style='+NON_RECENT\n\n'"
+status.code = 101