just playing with tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: port test_file_annotate_command.rs to TestWorkDir API

+89 -100
+89 -100
cli/tests/test_file_annotate_command.rs
··· 29 29 fn test_annotate_linear() { 30 30 let test_env = TestEnvironment::default(); 31 31 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 32 - let repo_path = test_env.env_root().join("repo"); 32 + let work_dir = test_env.work_dir("repo"); 33 33 34 - std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap(); 35 - test_env 36 - .run_jj_in( 37 - &repo_path, 38 - ["describe", "-m=initial", "--author=Foo <foo@example.org>"], 39 - ) 34 + work_dir.write_file("file.txt", "line1\n"); 35 + work_dir 36 + .run_jj(["describe", "-m=initial", "--author=Foo <foo@example.org>"]) 40 37 .success(); 41 38 42 - test_env.run_jj_in(&repo_path, ["new", "-m=next"]).success(); 43 - append_to_file(&repo_path.join("file.txt"), "new text from new commit"); 39 + work_dir.run_jj(["new", "-m=next"]).success(); 40 + append_to_file( 41 + &work_dir.root().join("file.txt"), 42 + "new text from new commit", 43 + ); 44 44 45 - let output = test_env.run_jj_in(&repo_path, ["file", "annotate", "file.txt"]); 45 + let output = work_dir.run_jj(["file", "annotate", "file.txt"]); 46 46 insta::assert_snapshot!(output, @r" 47 47 qpvuntsm foo 2001-02-03 08:05:08 1: line1 48 48 kkmpptxz test.use 2001-02-03 08:05:10 2: new text from new commit ··· 54 54 fn test_annotate_merge() { 55 55 let test_env = TestEnvironment::default(); 56 56 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 57 - let repo_path = test_env.env_root().join("repo"); 57 + let work_dir = test_env.work_dir("repo"); 58 58 59 - std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap(); 60 - test_env 61 - .run_jj_in(&repo_path, ["describe", "-m=initial"]) 62 - .success(); 63 - test_env 64 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "initial"]) 59 + work_dir.write_file("file.txt", "line1\n"); 60 + work_dir.run_jj(["describe", "-m=initial"]).success(); 61 + work_dir 62 + .run_jj(["branch", "create", "-r@", "initial"]) 65 63 .success(); 66 64 67 - test_env 68 - .run_jj_in(&repo_path, ["new", "-m=commit1"]) 69 - .success(); 70 - append_to_file(&repo_path.join("file.txt"), "new text from new commit 1"); 71 - test_env 72 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "commit1"]) 65 + work_dir.run_jj(["new", "-m=commit1"]).success(); 66 + append_to_file( 67 + &work_dir.root().join("file.txt"), 68 + "new text from new commit 1", 69 + ); 70 + work_dir 71 + .run_jj(["branch", "create", "-r@", "commit1"]) 73 72 .success(); 74 73 75 - test_env 76 - .run_jj_in(&repo_path, ["new", "-m=commit2", "initial"]) 77 - .success(); 78 - append_to_file(&repo_path.join("file.txt"), "new text from new commit 2"); 79 - test_env 80 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "commit2"]) 74 + work_dir.run_jj(["new", "-m=commit2", "initial"]).success(); 75 + append_to_file( 76 + &work_dir.root().join("file.txt"), 77 + "new text from new commit 2", 78 + ); 79 + work_dir 80 + .run_jj(["branch", "create", "-r@", "commit2"]) 81 81 .success(); 82 82 83 83 // create a (conflicted) merge 84 - test_env 85 - .run_jj_in(&repo_path, ["new", "-m=merged", "commit1", "commit2"]) 84 + work_dir 85 + .run_jj(["new", "-m=merged", "commit1", "commit2"]) 86 86 .success(); 87 87 // resolve conflicts 88 - std::fs::write( 89 - repo_path.join("file.txt"), 88 + work_dir.write_file( 89 + "file.txt", 90 90 "line1\nnew text from new commit 1\nnew text from new commit 2\n", 91 - ) 92 - .unwrap(); 91 + ); 93 92 94 - let output = test_env.run_jj_in(&repo_path, ["file", "annotate", "file.txt"]); 93 + let output = work_dir.run_jj(["file", "annotate", "file.txt"]); 95 94 insta::assert_snapshot!(output, @r" 96 95 qpvuntsm test.use 2001-02-03 08:05:08 1: line1 97 96 zsuskuln test.use 2001-02-03 08:05:11 2: new text from new commit 1 ··· 104 103 fn test_annotate_conflicted() { 105 104 let test_env = TestEnvironment::default(); 106 105 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 107 - let repo_path = test_env.env_root().join("repo"); 106 + let work_dir = test_env.work_dir("repo"); 108 107 109 - std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap(); 110 - test_env 111 - .run_jj_in(&repo_path, ["describe", "-m=initial"]) 112 - .success(); 113 - test_env 114 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "initial"]) 108 + work_dir.write_file("file.txt", "line1\n"); 109 + work_dir.run_jj(["describe", "-m=initial"]).success(); 110 + work_dir 111 + .run_jj(["branch", "create", "-r@", "initial"]) 115 112 .success(); 116 113 117 - test_env 118 - .run_jj_in(&repo_path, ["new", "-m=commit1"]) 119 - .success(); 120 - append_to_file(&repo_path.join("file.txt"), "new text from new commit 1"); 121 - test_env 122 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "commit1"]) 114 + work_dir.run_jj(["new", "-m=commit1"]).success(); 115 + append_to_file( 116 + &work_dir.root().join("file.txt"), 117 + "new text from new commit 1", 118 + ); 119 + work_dir 120 + .run_jj(["branch", "create", "-r@", "commit1"]) 123 121 .success(); 124 122 125 - test_env 126 - .run_jj_in(&repo_path, ["new", "-m=commit2", "initial"]) 127 - .success(); 128 - append_to_file(&repo_path.join("file.txt"), "new text from new commit 2"); 129 - test_env 130 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "commit2"]) 123 + work_dir.run_jj(["new", "-m=commit2", "initial"]).success(); 124 + append_to_file( 125 + &work_dir.root().join("file.txt"), 126 + "new text from new commit 2", 127 + ); 128 + work_dir 129 + .run_jj(["branch", "create", "-r@", "commit2"]) 131 130 .success(); 132 131 133 132 // create a (conflicted) merge 134 - test_env 135 - .run_jj_in(&repo_path, ["new", "-m=merged", "commit1", "commit2"]) 133 + work_dir 134 + .run_jj(["new", "-m=merged", "commit1", "commit2"]) 136 135 .success(); 137 - test_env.run_jj_in(&repo_path, ["new"]).success(); 136 + work_dir.run_jj(["new"]).success(); 138 137 139 - let output = test_env.run_jj_in(&repo_path, ["file", "annotate", "file.txt"]); 138 + let output = work_dir.run_jj(["file", "annotate", "file.txt"]); 140 139 insta::assert_snapshot!(output, @r" 141 140 qpvuntsm test.use 2001-02-03 08:05:08 1: line1 142 141 yostqsxw test.use 2001-02-03 08:05:15 2: <<<<<<< Conflict 1 of 1 ··· 153 152 fn test_annotate_merge_one_sided_conflict_resolution() { 154 153 let test_env = TestEnvironment::default(); 155 154 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 156 - let repo_path = test_env.env_root().join("repo"); 155 + let work_dir = test_env.work_dir("repo"); 157 156 158 - std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap(); 159 - test_env 160 - .run_jj_in(&repo_path, ["describe", "-m=initial"]) 161 - .success(); 162 - test_env 163 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "initial"]) 157 + work_dir.write_file("file.txt", "line1\n"); 158 + work_dir.run_jj(["describe", "-m=initial"]).success(); 159 + work_dir 160 + .run_jj(["branch", "create", "-r@", "initial"]) 164 161 .success(); 165 162 166 - test_env 167 - .run_jj_in(&repo_path, ["new", "-m=commit1"]) 168 - .success(); 169 - append_to_file(&repo_path.join("file.txt"), "new text from new commit 1"); 170 - test_env 171 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "commit1"]) 163 + work_dir.run_jj(["new", "-m=commit1"]).success(); 164 + append_to_file( 165 + &work_dir.root().join("file.txt"), 166 + "new text from new commit 1", 167 + ); 168 + work_dir 169 + .run_jj(["branch", "create", "-r@", "commit1"]) 172 170 .success(); 173 171 174 - test_env 175 - .run_jj_in(&repo_path, ["new", "-m=commit2", "initial"]) 176 - .success(); 177 - append_to_file(&repo_path.join("file.txt"), "new text from new commit 2"); 178 - test_env 179 - .run_jj_in(&repo_path, ["branch", "create", "-r@", "commit2"]) 172 + work_dir.run_jj(["new", "-m=commit2", "initial"]).success(); 173 + append_to_file( 174 + &work_dir.root().join("file.txt"), 175 + "new text from new commit 2", 176 + ); 177 + work_dir 178 + .run_jj(["branch", "create", "-r@", "commit2"]) 180 179 .success(); 181 180 182 181 // create a (conflicted) merge 183 - test_env 184 - .run_jj_in(&repo_path, ["new", "-m=merged", "commit1", "commit2"]) 182 + work_dir 183 + .run_jj(["new", "-m=merged", "commit1", "commit2"]) 185 184 .success(); 186 185 // resolve conflicts 187 - std::fs::write( 188 - repo_path.join("file.txt"), 189 - "line1\nnew text from new commit 1\n", 190 - ) 191 - .unwrap(); 186 + work_dir.write_file("file.txt", "line1\nnew text from new commit 1\n"); 192 187 193 - let output = test_env.run_jj_in(&repo_path, ["file", "annotate", "file.txt"]); 188 + let output = work_dir.run_jj(["file", "annotate", "file.txt"]); 194 189 insta::assert_snapshot!(output, @r" 195 190 qpvuntsm test.use 2001-02-03 08:05:08 1: line1 196 191 zsuskuln test.use 2001-02-03 08:05:11 2: new text from new commit 1 ··· 202 197 fn test_annotate_with_template() { 203 198 let test_env = TestEnvironment::default(); 204 199 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 205 - let repo_path = test_env.env_root().join("repo"); 200 + let work_dir = test_env.work_dir("repo"); 206 201 207 - std::fs::write(repo_path.join("file.txt"), "line1\n").unwrap(); 208 - test_env 209 - .run_jj_in(&repo_path, ["commit", "-m=initial"]) 210 - .success(); 202 + work_dir.write_file("file.txt", "line1\n"); 203 + work_dir.run_jj(["commit", "-m=initial"]).success(); 211 204 212 205 append_to_file( 213 - &repo_path.join("file.txt"), 206 + &work_dir.root().join("file.txt"), 214 207 "new text from new commit 1\nthat splits into multiple lines", 215 208 ); 216 - test_env 217 - .run_jj_in(&repo_path, ["commit", "-m=commit1"]) 218 - .success(); 209 + work_dir.run_jj(["commit", "-m=commit1"]).success(); 219 210 220 211 append_to_file( 221 - &repo_path.join("file.txt"), 212 + &work_dir.root().join("file.txt"), 222 213 "new text from new commit 2\nalso continuing on a second line\nand a third!", 223 214 ); 224 - test_env 225 - .run_jj_in(&repo_path, ["describe", "-m=commit2"]) 226 - .success(); 215 + work_dir.run_jj(["describe", "-m=commit2"]).success(); 227 216 228 217 let template = indoc::indoc! {r#" 229 218 if(first_line_in_hunk, "\n" ++ separate("\n", ··· 236 225 ) ++ "\n") ++ pad_start(4, line_number) ++ ": " ++ content 237 226 "#}; 238 227 239 - let output = test_env.run_jj_in(&repo_path, ["file", "annotate", "file.txt", "-T", template]); 228 + let output = work_dir.run_jj(["file", "annotate", "file.txt", "-T", template]); 240 229 insta::assert_snapshot!(output, @r" 241 230 qpvuntsm initial 242 231 2001-02-03 08:05:08 Test User <test.user@example.com>