diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 715c7f035..e6fa12b32 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -41,7 +41,7 @@ impl Default for TestEnvironment { let config_dir = env_root.join("config"); std::fs::create_dir(&config_dir).unwrap(); let env_vars = HashMap::new(); - Self { + let env = Self { _temp_dir: tmp_dir, env_root, home_dir, @@ -49,7 +49,16 @@ impl Default for TestEnvironment { env_vars, config_file_number: RefCell::new(0), command_number: RefCell::new(0), - } + }; + // Use absolute timestamps in the operation log to make tests independent of the + // current time. + env.add_config( + r#" +[template-aliases] +'format_time_range(time_range)' = 'time_range.start() ++ " - " ++ time_range.end()' + "#, + ); + env } } diff --git a/tests/test_concurrent_operations.rs b/tests/test_concurrent_operations.rs index ce3fdf49c..e0f08b066 100644 --- a/tests/test_concurrent_operations.rs +++ b/tests/test_concurrent_operations.rs @@ -51,15 +51,15 @@ fn test_concurrent_operations_auto_rebase() { test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]); let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]); insta::assert_snapshot!(stdout, @r###" - @ cde29280d4a9 test-username@host.example.com 22 years ago, lasted less than a microsecond + @ cde29280d4a9 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00 │ describe commit 123ed18e4c4c0d77428df41112bc02ffc83fb935 │ args: jj describe -m initial - ◉ 7c212e0863fd test-username@host.example.com 22 years ago, lasted less than a microsecond + ◉ 7c212e0863fd test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00 │ snapshot working copy │ args: jj describe -m initial - ◉ a99a3fd5c51e test-username@host.example.com 22 years ago, lasted less than a microsecond + ◉ a99a3fd5c51e test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 │ add workspace 'default' - ◉ 56b94dfc38e7 test-username@host.example.com 22 years ago, lasted less than a microsecond + ◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 initialize repo "###); let op_id_hex = stdout[3..15].to_string(); diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index 16e508a64..fca801269 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -328,7 +328,7 @@ fn test_invalid_config() { test_env.add_config("[section]key = value-missing-quotes"); let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "repo"]); insta::assert_snapshot!(stderr.replace('\\', "/"), @r###" - Config error: expected newline, found an identifier at line 1 column 10 in config/config0001.toml + Config error: expected newline, found an identifier at line 1 column 10 in config/config0002.toml For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md. "###); } diff --git a/tests/test_operations.rs b/tests/test_operations.rs index 05f9e5a25..5c0abb50f 100644 --- a/tests/test_operations.rs +++ b/tests/test_operations.rs @@ -45,18 +45,6 @@ fn test_op_log() { ◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 initialize repo "###); - // Test op log with relative dates - let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]); - let regex = Regex::new(r"\d\d years").unwrap(); - insta::assert_snapshot!(regex.replace_all(&stdout, "NN years"), @r###" - @ 45108169c0f8 test-username@host.example.com NN years ago, lasted less than a microsecond - │ describe commit 230dd059e1b059aefc0da06a2e5a7dbf22362f22 - │ args: jj describe -m 'description 0' - ◉ a99a3fd5c51e test-username@host.example.com NN years ago, lasted less than a microsecond - │ add workspace 'default' - ◉ 56b94dfc38e7 test-username@host.example.com NN years ago, lasted less than a microsecond - initialize repo - "###); let add_workspace_id = "a99a3fd5c51e"; let initialize_repo_id = "56b94dfc38e7"; @@ -145,6 +133,23 @@ fn test_op_log_template() { @ a99a3 true test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 2001-02-03 04:05:07.000 +07:00 less than a microsecond ◉ 56b94 false test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 2001-02-03 04:05:07.000 +07:00 less than a microsecond "###); + // Test the default template, i.e. with relative start time and duration. We + // don't generally use that template because it depends on the current time, + // so we need to reset the time range format here. + test_env.add_config( + r#" +[template-aliases] +'format_time_range(time_range)' = 'time_range.start().ago() ++ ", lasted " ++ time_range.duration()' + "#, + ); + let regex = Regex::new(r"\d\d years").unwrap(); + let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]); + insta::assert_snapshot!(regex.replace_all(&stdout, "NN years"), @r###" + @ a99a3fd5c51e test-username@host.example.com NN years ago, lasted less than a microsecond + │ add workspace 'default' + ◉ 56b94dfc38e7 test-username@host.example.com NN years ago, lasted less than a microsecond + initialize repo + "###); } #[test] @@ -168,21 +173,21 @@ fn test_op_log_word_wrap() { // ui.log-word-wrap option works insta::assert_snapshot!(render(&["op", "log"], 40, false), @r###" - @ a99a3fd5c51e test-username@host.example.com 22 years ago, lasted less than a microsecond + @ a99a3fd5c51e test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 │ add workspace 'default' - ◉ 56b94dfc38e7 test-username@host.example.com 22 years ago, lasted less than a microsecond + ◉ 56b94dfc38e7 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00 initialize repo "###); insta::assert_snapshot!(render(&["op", "log"], 40, true), @r###" @ a99a3fd5c51e - │ test-username@host.example.com 22 - │ years ago, lasted less than a - │ microsecond + │ test-username@host.example.com + │ 2001-02-03 04:05:07.000 +07:00 - + │ 2001-02-03 04:05:07.000 +07:00 │ add workspace 'default' ◉ 56b94dfc38e7 - test-username@host.example.com 22 - years ago, lasted less than a - microsecond + test-username@host.example.com + 2001-02-03 04:05:07.000 +07:00 - + 2001-02-03 04:05:07.000 +07:00 initialize repo "###); }