From e1d49cc67fdc8d0b3de55d49147b879ebf0b2ca4 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 26 Jan 2023 11:12:10 -0800 Subject: [PATCH] tests: use dotted notation in TOML when it saves lines --- tests/common/mod.rs | 10 +------- tests/test_alias.rs | 42 +++++++--------------------------- tests/test_describe_command.rs | 5 +--- tests/test_global_opts.rs | 5 +--- tests/test_init_command.rs | 6 +---- tests/test_log_command.rs | 6 +---- tests/test_show_command.rs | 6 +---- tests/test_untrack_command.rs | 12 ++-------- 8 files changed, 16 insertions(+), 76 deletions(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 9fb710dc1..66f061602 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -169,15 +169,7 @@ impl TestEnvironment { // Simplified TOML escaping, hoping that there are no '"' or control characters // in it let escaped_diff_editor_path = diff_editor_path.to_str().unwrap().replace('\\', r"\\"); - self.add_config( - format!( - r###" - [ui] - diff-editor = "{escaped_diff_editor_path}" - "### - ) - .as_bytes(), - ); + self.add_config(format!(r#"ui.diff-editor = "{escaped_diff_editor_path}""#).as_bytes()); let edit_script = self.env_root().join("diff_edit_script"); std::fs::write(&edit_script, "").unwrap(); self.add_env_var("DIFF_EDIT_SCRIPT", edit_script.to_str().unwrap()); diff --git a/tests/test_alias.rs b/tests/test_alias.rs index 3b75a1cb3..dc2dbbd86 100644 --- a/tests/test_alias.rs +++ b/tests/test_alias.rs @@ -24,11 +24,7 @@ fn test_alias_basic() { test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - b = ["log", "-r", "@", "-T", "branches"] - "#, - ); + test_env.add_config(br#"alias.b = ["log", "-r", "@", "-T", "branches"]"#); test_env.jj_cmd_success(&repo_path, &["branch", "create", "my-branch"]); let stdout = test_env.jj_cmd_success(&repo_path, &["b"]); insta::assert_snapshot!(stdout, @r###" @@ -59,11 +55,7 @@ fn test_alias_calls_unknown_command() { test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - foo = ["nonexistent"] - "#, - ); + test_env.add_config(br#"alias.foo = ["nonexistent"]"#); let stderr = test_env.jj_cmd_cli_error(&repo_path, &["foo"]); insta::assert_snapshot!(stderr, @r###" error: The subcommand 'nonexistent' wasn't recognized @@ -80,11 +72,7 @@ fn test_alias_calls_command_with_invalid_option() { test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - foo = ["log", "--nonexistent"] - "#, - ); + test_env.add_config(br#"alias.foo = ["log", "--nonexistent"]"#); let stderr = test_env.jj_cmd_cli_error(&repo_path, &["foo"]); insta::assert_snapshot!(stderr, @r###" error: Found argument '--nonexistent' which wasn't expected, or isn't valid in this context @@ -102,11 +90,7 @@ fn test_alias_calls_help() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - h = ["--help"] - "#, - ); + test_env.add_config(br#"alias.h = ["--help"]"#); let stdout = test_env.jj_cmd_success(&repo_path, &["h"]); insta::assert_snapshot!(stdout.lines().take(5).join("\n"), @r###" Jujutsu (An experimental VCS) @@ -123,11 +107,7 @@ fn test_alias_cannot_override_builtin() { test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - log = ["rebase"] - "#, - ); + test_env.add_config(br#"alias.log = ["rebase"]"#); // Alias should be ignored let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "root"]); insta::assert_snapshot!(stdout, @r###" @@ -166,11 +146,7 @@ fn test_alias_global_args_before_and_after() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - l = ["log", "-T", "commit_id", "-r", "all()"] - "#, - ); + test_env.add_config(br#"alias.l = ["log", "-T", "commit_id", "-r", "all()"]"#); // Test the setup let stdout = test_env.jj_cmd_success(&repo_path, &["l"]); insta::assert_snapshot!(stdout, @r###" @@ -205,10 +181,8 @@ fn test_alias_global_args_in_definition() { let test_env = TestEnvironment::default(); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[alias] - l = ["log", "-T", "commit_id", "--at-op", "@-", "-r", "all()", "--color=always"] - "#, + test_env.add_config( + br#"alias.l = ["log", "-T", "commit_id", "--at-op", "@-", "-r", "all()", "--color=always"]"#, ); // The global argument in the alias is respected diff --git a/tests/test_describe_command.rs b/tests/test_describe_command.rs index d122e7aae..2691f3a30 100644 --- a/tests/test_describe_command.rs +++ b/tests/test_describe_command.rs @@ -125,10 +125,7 @@ fn test_describe() { assert!(get_stderr_string(&assert).contains("bad-editor-from-visual-env")); // `ui.editor` config overrides `$VISUAL` - test_env.add_config( - br#"[ui] - editor = "bad-editor-from-config""#, - ); + test_env.add_config(br#"ui.editor = "bad-editor-from-config""#); let assert = test_env .jj_cmd(&repo_path, &["describe"]) .env("VISUAL", "bad-editor-from-visual-env") diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index 3d2a75262..bdcb87f59 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -187,10 +187,7 @@ fn test_color_config() { "###); // Test that color is used if it's requested in the config file - test_env.add_config( - br#"[ui] -color="always""#, - ); + test_env.add_config(br#"ui.color="always""#); let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-T", "commit_id"]); insta::assert_snapshot!(stdout, @r###" @ 230dd059e1b059aefc0da06a2e5a7dbf22362f22 diff --git a/tests/test_init_command.rs b/tests/test_init_command.rs index 986ccc33c..cc2529444 100644 --- a/tests/test_init_command.rs +++ b/tests/test_init_command.rs @@ -196,11 +196,7 @@ fn test_init_local_disallowed() { #[test] fn test_init_local() { let test_env = TestEnvironment::default(); - test_env.add_config( - br#"[ui] - allow-init-native = true - "#, - ); + test_env.add_config(br#"ui.allow-init-native = true"#); let stdout = test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]); insta::assert_snapshot!(stdout, @r###" Initialized repo in "repo" diff --git a/tests/test_log_command.rs b/tests/test_log_command.rs index b8b11ab51..52eaa9351 100644 --- a/tests/test_log_command.rs +++ b/tests/test_log_command.rs @@ -603,11 +603,7 @@ fn test_default_revset() { test_env.jj_cmd_success(&repo_path, &["describe", "-m", "add a file"]); // Set configuration to only show the root commit. - test_env.add_config( - br#"[ui] - default-revset = "root" - "#, - ); + test_env.add_config(br#"ui.default-revset = "root""#); // Log should only contain one line (for the root commit), and not show the // commit created above. diff --git a/tests/test_show_command.rs b/tests/test_show_command.rs index e869457ad..87fc9413e 100644 --- a/tests/test_show_command.rs +++ b/tests/test_show_command.rs @@ -41,11 +41,7 @@ fn test_show_relative_timestamps() { test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); let repo_path = test_env.env_root().join("repo"); - test_env.add_config( - br#"[ui] - relative-timestamps = true - "#, - ); + test_env.add_config(br#"ui.relative-timestamps = true"#); let stdout = test_env.jj_cmd_success(&repo_path, &["show"]); let timestamp_re = Regex::new(r"\([0-9]+ years ago\)").unwrap(); diff --git a/tests/test_untrack_command.rs b/tests/test_untrack_command.rs index 5ab77761e..8ea184a68 100644 --- a/tests/test_untrack_command.rs +++ b/tests/test_untrack_command.rs @@ -21,11 +21,7 @@ pub mod common; #[test] fn test_untrack() { let test_env = TestEnvironment::default(); - test_env.add_config( - br#"[ui] - allow-init-native = true - "#, - ); + test_env.add_config(br#"ui.allow-init-native = true"#); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]); let repo_path = test_env.env_root().join("repo"); @@ -105,11 +101,7 @@ fn test_untrack() { #[test] fn test_untrack_sparse() { let test_env = TestEnvironment::default(); - test_env.add_config( - br#"[ui] - allow-init-native = true - "#, - ); + test_env.add_config(br#"ui.allow-init-native = true"#); test_env.jj_cmd_success(test_env.env_root(), &["init", "repo"]); let repo_path = test_env.env_root().join("repo");