forked from mirrors/jj
tests: use absolute timestamps in the operation log
The current use of `timestamp.ago()` in the default template makes the tests depend on the current time, which they shouldn't.
This commit is contained in:
parent
9e027c0aa2
commit
4b5b497283
4 changed files with 41 additions and 27 deletions
|
@ -41,7 +41,7 @@ impl Default for TestEnvironment {
|
||||||
let config_dir = env_root.join("config");
|
let config_dir = env_root.join("config");
|
||||||
std::fs::create_dir(&config_dir).unwrap();
|
std::fs::create_dir(&config_dir).unwrap();
|
||||||
let env_vars = HashMap::new();
|
let env_vars = HashMap::new();
|
||||||
Self {
|
let env = Self {
|
||||||
_temp_dir: tmp_dir,
|
_temp_dir: tmp_dir,
|
||||||
env_root,
|
env_root,
|
||||||
home_dir,
|
home_dir,
|
||||||
|
@ -49,7 +49,16 @@ impl Default for TestEnvironment {
|
||||||
env_vars,
|
env_vars,
|
||||||
config_file_number: RefCell::new(0),
|
config_file_number: RefCell::new(0),
|
||||||
command_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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,15 +51,15 @@ fn test_concurrent_operations_auto_rebase() {
|
||||||
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
|
test_env.jj_cmd_success(&repo_path, &["describe", "-m", "initial"]);
|
||||||
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
||||||
insta::assert_snapshot!(stdout, @r###"
|
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
|
│ describe commit 123ed18e4c4c0d77428df41112bc02ffc83fb935
|
||||||
│ args: jj describe -m initial
|
│ 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
|
│ snapshot working copy
|
||||||
│ args: jj describe -m initial
|
│ 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'
|
│ 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
|
initialize repo
|
||||||
"###);
|
"###);
|
||||||
let op_id_hex = stdout[3..15].to_string();
|
let op_id_hex = stdout[3..15].to_string();
|
||||||
|
|
|
@ -328,7 +328,7 @@ fn test_invalid_config() {
|
||||||
test_env.add_config("[section]key = value-missing-quotes");
|
test_env.add_config("[section]key = value-missing-quotes");
|
||||||
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "repo"]);
|
let stderr = test_env.jj_cmd_failure(test_env.env_root(), &["init", "repo"]);
|
||||||
insta::assert_snapshot!(stderr.replace('\\', "/"), @r###"
|
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.
|
For help, see https://github.com/martinvonz/jj/blob/main/docs/config.md.
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
◉ 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
|
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 add_workspace_id = "a99a3fd5c51e";
|
||||||
let initialize_repo_id = "56b94dfc38e7";
|
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
|
@ 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
|
◉ 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]
|
#[test]
|
||||||
|
@ -168,21 +173,21 @@ fn test_op_log_word_wrap() {
|
||||||
|
|
||||||
// ui.log-word-wrap option works
|
// ui.log-word-wrap option works
|
||||||
insta::assert_snapshot!(render(&["op", "log"], 40, false), @r###"
|
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'
|
│ 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
|
initialize repo
|
||||||
"###);
|
"###);
|
||||||
insta::assert_snapshot!(render(&["op", "log"], 40, true), @r###"
|
insta::assert_snapshot!(render(&["op", "log"], 40, true), @r###"
|
||||||
@ a99a3fd5c51e
|
@ a99a3fd5c51e
|
||||||
│ test-username@host.example.com 22
|
│ test-username@host.example.com
|
||||||
│ years ago, lasted less than a
|
│ 2001-02-03 04:05:07.000 +07:00 -
|
||||||
│ microsecond
|
│ 2001-02-03 04:05:07.000 +07:00
|
||||||
│ add workspace 'default'
|
│ add workspace 'default'
|
||||||
◉ 56b94dfc38e7
|
◉ 56b94dfc38e7
|
||||||
test-username@host.example.com 22
|
test-username@host.example.com
|
||||||
years ago, lasted less than a
|
2001-02-03 04:05:07.000 +07:00 -
|
||||||
microsecond
|
2001-02-03 04:05:07.000 +07:00
|
||||||
initialize repo
|
initialize repo
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue