| 1 |
// Copyright 2022 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use crate::common::TestEnvironment; |
| 16 |
|
| 17 |
#[test] |
| 18 |
fn test_syntax_error() { |
| 19 |
let test_env = TestEnvironment::default(); |
| 20 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 21 |
let work_dir = test_env.work_dir("repo"); |
| 22 |
|
| 23 |
let output = work_dir.run_jj(["log", "-r", ":x"]); |
| 24 |
insta::assert_snapshot!(output, @" |
| 25 |
------- stderr ------- |
| 26 |
Error: Failed to parse revset: `:` is not a prefix operator |
| 27 |
Caused by: --> 1:1 |
| 28 |
| |
| 29 |
1 | :x |
| 30 |
| ^ |
| 31 |
| |
| 32 |
= `:` is not a prefix operator |
| 33 |
Hint: Did you mean `::` for ancestors? |
| 34 |
[EOF] |
| 35 |
[exit status: 1] |
| 36 |
"); |
| 37 |
|
| 38 |
let output = work_dir.run_jj(["log", "-r", "x &"]); |
| 39 |
insta::assert_snapshot!(output, @" |
| 40 |
------- stderr ------- |
| 41 |
Error: Failed to parse revset: Syntax error |
| 42 |
Caused by: --> 1:4 |
| 43 |
| |
| 44 |
1 | x & |
| 45 |
| ^--- |
| 46 |
| |
| 47 |
= expected `::`, `..`, `~`, or <primary> |
| 48 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols. |
| 49 |
[EOF] |
| 50 |
[exit status: 1] |
| 51 |
"); |
| 52 |
|
| 53 |
let output = work_dir.run_jj(["log", "-r", "x - y"]); |
| 54 |
insta::assert_snapshot!(output, @" |
| 55 |
------- stderr ------- |
| 56 |
Error: Failed to parse revset: `-` is not an infix operator |
| 57 |
Caused by: --> 1:3 |
| 58 |
| |
| 59 |
1 | x - y |
| 60 |
| ^ |
| 61 |
| |
| 62 |
= `-` is not an infix operator |
| 63 |
Hint: Did you mean `~` for difference? |
| 64 |
[EOF] |
| 65 |
[exit status: 1] |
| 66 |
"); |
| 67 |
|
| 68 |
let output = work_dir.run_jj(["log", "-r", "HEAD^"]); |
| 69 |
insta::assert_snapshot!(output, @" |
| 70 |
------- stderr ------- |
| 71 |
Error: Failed to parse revset: `^` is not a postfix operator |
| 72 |
Caused by: --> 1:5 |
| 73 |
| |
| 74 |
1 | HEAD^ |
| 75 |
| ^ |
| 76 |
| |
| 77 |
= `^` is not a postfix operator |
| 78 |
Hint: Did you mean `-` for parents? |
| 79 |
[EOF] |
| 80 |
[exit status: 1] |
| 81 |
"); |
| 82 |
} |
| 83 |
|
| 84 |
#[test] |
| 85 |
fn test_bad_function_call() { |
| 86 |
let test_env = TestEnvironment::default(); |
| 87 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 88 |
let work_dir = test_env.work_dir("repo"); |
| 89 |
|
| 90 |
let output = work_dir.run_jj(["log", "-r", "all(or::nothing)"]); |
| 91 |
insta::assert_snapshot!(output, @" |
| 92 |
------- stderr ------- |
| 93 |
Error: Failed to parse revset: Function `all`: Expected 0 arguments |
| 94 |
Caused by: --> 1:5 |
| 95 |
| |
| 96 |
1 | all(or::nothing) |
| 97 |
| ^---------^ |
| 98 |
| |
| 99 |
= Function `all`: Expected 0 arguments |
| 100 |
[EOF] |
| 101 |
[exit status: 1] |
| 102 |
"); |
| 103 |
|
| 104 |
let output = work_dir.run_jj(["log", "-r", "parents()"]); |
| 105 |
insta::assert_snapshot!(output, @" |
| 106 |
------- stderr ------- |
| 107 |
Error: Failed to parse revset: Function `parents`: Expected 1 to 2 arguments |
| 108 |
Caused by: --> 1:9 |
| 109 |
| |
| 110 |
1 | parents() |
| 111 |
| ^ |
| 112 |
| |
| 113 |
= Function `parents`: Expected 1 to 2 arguments |
| 114 |
[EOF] |
| 115 |
[exit status: 1] |
| 116 |
"); |
| 117 |
|
| 118 |
let output = work_dir.run_jj(["log", "-r", "parents(foo, bar, baz)"]); |
| 119 |
insta::assert_snapshot!(output, @" |
| 120 |
------- stderr ------- |
| 121 |
Error: Failed to parse revset: Function `parents`: Expected 1 to 2 arguments |
| 122 |
Caused by: --> 1:9 |
| 123 |
| |
| 124 |
1 | parents(foo, bar, baz) |
| 125 |
| ^-----------^ |
| 126 |
| |
| 127 |
= Function `parents`: Expected 1 to 2 arguments |
| 128 |
[EOF] |
| 129 |
[exit status: 1] |
| 130 |
"); |
| 131 |
|
| 132 |
let output = work_dir.run_jj(["log", "-r", "heads(foo, bar)"]); |
| 133 |
insta::assert_snapshot!(output, @" |
| 134 |
------- stderr ------- |
| 135 |
Error: Failed to parse revset: Function `heads`: Expected 1 arguments |
| 136 |
Caused by: --> 1:7 |
| 137 |
| |
| 138 |
1 | heads(foo, bar) |
| 139 |
| ^------^ |
| 140 |
| |
| 141 |
= Function `heads`: Expected 1 arguments |
| 142 |
[EOF] |
| 143 |
[exit status: 1] |
| 144 |
"); |
| 145 |
|
| 146 |
let output = work_dir.run_jj(["log", "-r", "latest(a, not_an_integer)"]); |
| 147 |
insta::assert_snapshot!(output, @" |
| 148 |
------- stderr ------- |
| 149 |
Error: Failed to parse revset: Expected integer |
| 150 |
Caused by: --> 1:11 |
| 151 |
| |
| 152 |
1 | latest(a, not_an_integer) |
| 153 |
| ^------------^ |
| 154 |
| |
| 155 |
= Expected integer |
| 156 |
[EOF] |
| 157 |
[exit status: 1] |
| 158 |
"); |
| 159 |
|
| 160 |
// "N to M arguments" |
| 161 |
let output = work_dir.run_jj(["log", "-r", "ancestors()"]); |
| 162 |
insta::assert_snapshot!(output, @" |
| 163 |
------- stderr ------- |
| 164 |
Error: Failed to parse revset: Function `ancestors`: Expected 1 to 2 arguments |
| 165 |
Caused by: --> 1:11 |
| 166 |
| |
| 167 |
1 | ancestors() |
| 168 |
| ^ |
| 169 |
| |
| 170 |
= Function `ancestors`: Expected 1 to 2 arguments |
| 171 |
[EOF] |
| 172 |
[exit status: 1] |
| 173 |
"); |
| 174 |
|
| 175 |
let output = work_dir.run_jj(["log", "-r", "change_id(glob:a)"]); |
| 176 |
insta::assert_snapshot!(output, @" |
| 177 |
------- stderr ------- |
| 178 |
Error: Failed to parse revset: Expected change ID prefix |
| 179 |
Caused by: --> 1:11 |
| 180 |
| |
| 181 |
1 | change_id(glob:a) |
| 182 |
| ^----^ |
| 183 |
| |
| 184 |
= Expected change ID prefix |
| 185 |
[EOF] |
| 186 |
[exit status: 1] |
| 187 |
"); |
| 188 |
|
| 189 |
let output = work_dir.run_jj(["log", "-r", "commit_id(xyzzy)"]); |
| 190 |
insta::assert_snapshot!(output, @" |
| 191 |
------- stderr ------- |
| 192 |
Error: Failed to parse revset: Invalid commit ID prefix |
| 193 |
Caused by: --> 1:11 |
| 194 |
| |
| 195 |
1 | commit_id(xyzzy) |
| 196 |
| ^---^ |
| 197 |
| |
| 198 |
= Invalid commit ID prefix |
| 199 |
[EOF] |
| 200 |
[exit status: 1] |
| 201 |
"); |
| 202 |
|
| 203 |
let output = work_dir.run_jj(["log", "-r", "files(not::a-fileset)"]); |
| 204 |
insta::assert_snapshot!(output, @" |
| 205 |
------- stderr ------- |
| 206 |
Error: Failed to parse revset: In fileset expression |
| 207 |
Caused by: |
| 208 |
1: --> 1:7 |
| 209 |
| |
| 210 |
1 | files(not::a-fileset) |
| 211 |
| ^------------^ |
| 212 |
| |
| 213 |
= In fileset expression |
| 214 |
2: --> 1:5 |
| 215 |
| |
| 216 |
1 | not::a-fileset |
| 217 |
| ^--- |
| 218 |
| |
| 219 |
= expected <primary> |
| 220 |
Hint: See https://docs.jj-vcs.dev/latest/filesets/ or use `jj help -k filesets` for filesets syntax and how to match file paths. |
| 221 |
[EOF] |
| 222 |
[exit status: 1] |
| 223 |
"); |
| 224 |
|
| 225 |
let output = work_dir.run_jj(["log", "-r", r#"files(foo:"bar")"#]); |
| 226 |
insta::assert_snapshot!(output, @r#" |
| 227 |
------- stderr ------- |
| 228 |
Error: Failed to parse revset: In fileset expression |
| 229 |
Caused by: |
| 230 |
1: --> 1:7 |
| 231 |
| |
| 232 |
1 | files(foo:"bar") |
| 233 |
| ^-------^ |
| 234 |
| |
| 235 |
= In fileset expression |
| 236 |
2: --> 1:1 |
| 237 |
| |
| 238 |
1 | foo:"bar" |
| 239 |
| ^-------^ |
| 240 |
| |
| 241 |
= Invalid file pattern |
| 242 |
3: Invalid file pattern kind `foo:` |
| 243 |
Hint: See https://docs.jj-vcs.dev/latest/filesets/#file-patterns or `jj help -k filesets` for valid prefixes. |
| 244 |
[EOF] |
| 245 |
[exit status: 1] |
| 246 |
"#); |
| 247 |
|
| 248 |
let output = work_dir.run_jj(["log", "-r", r#"files("../out")"#]); |
| 249 |
insta::assert_snapshot!(output.normalize_backslash(), @r#" |
| 250 |
------- stderr ------- |
| 251 |
Error: Failed to parse revset: In fileset expression |
| 252 |
Caused by: |
| 253 |
1: --> 1:7 |
| 254 |
| |
| 255 |
1 | files("../out") |
| 256 |
| ^------^ |
| 257 |
| |
| 258 |
= In fileset expression |
| 259 |
2: --> 1:1 |
| 260 |
| |
| 261 |
1 | "../out" |
| 262 |
| ^------^ |
| 263 |
| |
| 264 |
= Invalid file pattern |
| 265 |
3: Path "../out" is not in the repo "." |
| 266 |
4: Invalid component ".." in repo-relative path "../out" |
| 267 |
[EOF] |
| 268 |
[exit status: 1] |
| 269 |
"#); |
| 270 |
|
| 271 |
let output = work_dir.run_jj(["log", "-r", "bookmarks(bad:pattern)"]); |
| 272 |
insta::assert_snapshot!(output, @" |
| 273 |
------- stderr ------- |
| 274 |
Error: Failed to parse revset: Invalid string pattern |
| 275 |
Caused by: |
| 276 |
1: --> 1:11 |
| 277 |
| |
| 278 |
1 | bookmarks(bad:pattern) |
| 279 |
| ^---------^ |
| 280 |
| |
| 281 |
= Invalid string pattern |
| 282 |
2: Invalid string pattern kind `bad:` |
| 283 |
Hint: Try prefixing with one of `exact:`, `glob:`, `regex:`, `substring:`, or one of these with `-i` suffix added (e.g. `glob-i:`) for case-insensitive matching |
| 284 |
[EOF] |
| 285 |
[exit status: 1] |
| 286 |
"); |
| 287 |
|
| 288 |
let output = work_dir.run_jj(["log", "-r", "bookmarks(regex:'(')"]); |
| 289 |
insta::assert_snapshot!(output, @" |
| 290 |
------- stderr ------- |
| 291 |
Error: Failed to parse revset: Invalid string pattern |
| 292 |
Caused by: |
| 293 |
1: --> 1:11 |
| 294 |
| |
| 295 |
1 | bookmarks(regex:'(') |
| 296 |
| ^-------^ |
| 297 |
| |
| 298 |
= Invalid string pattern |
| 299 |
2: regex parse error: |
| 300 |
( |
| 301 |
^ |
| 302 |
error: unclosed group |
| 303 |
[EOF] |
| 304 |
[exit status: 1] |
| 305 |
"); |
| 306 |
|
| 307 |
let output = work_dir.run_jj(["log", "-r", "root()::whatever()"]); |
| 308 |
insta::assert_snapshot!(output, @" |
| 309 |
------- stderr ------- |
| 310 |
Error: Failed to parse revset: Function `whatever` doesn't exist |
| 311 |
Caused by: --> 1:9 |
| 312 |
| |
| 313 |
1 | root()::whatever() |
| 314 |
| ^------^ |
| 315 |
| |
| 316 |
= Function `whatever` doesn't exist |
| 317 |
[EOF] |
| 318 |
[exit status: 1] |
| 319 |
"); |
| 320 |
|
| 321 |
let output = work_dir.run_jj(["log", "-r", "remote_bookmarks(a, b, remote=c)"]); |
| 322 |
insta::assert_snapshot!(output, @r#" |
| 323 |
------- stderr ------- |
| 324 |
Error: Failed to parse revset: Function `remote_bookmarks`: Got multiple values for keyword "remote" |
| 325 |
Caused by: --> 1:24 |
| 326 |
| |
| 327 |
1 | remote_bookmarks(a, b, remote=c) |
| 328 |
| ^------^ |
| 329 |
| |
| 330 |
= Function `remote_bookmarks`: Got multiple values for keyword "remote" |
| 331 |
[EOF] |
| 332 |
[exit status: 1] |
| 333 |
"#); |
| 334 |
|
| 335 |
let output = work_dir.run_jj(["log", "-r", "remote_bookmarks(remote=a, b)"]); |
| 336 |
insta::assert_snapshot!(output, @" |
| 337 |
------- stderr ------- |
| 338 |
Error: Failed to parse revset: Function `remote_bookmarks`: Positional argument follows keyword argument |
| 339 |
Caused by: --> 1:28 |
| 340 |
| |
| 341 |
1 | remote_bookmarks(remote=a, b) |
| 342 |
| ^ |
| 343 |
| |
| 344 |
= Function `remote_bookmarks`: Positional argument follows keyword argument |
| 345 |
[EOF] |
| 346 |
[exit status: 1] |
| 347 |
"); |
| 348 |
|
| 349 |
let output = work_dir.run_jj(["log", "-r", "remote_bookmarks(=foo)"]); |
| 350 |
insta::assert_snapshot!(output, @" |
| 351 |
------- stderr ------- |
| 352 |
Error: Failed to parse revset: Syntax error |
| 353 |
Caused by: --> 1:18 |
| 354 |
| |
| 355 |
1 | remote_bookmarks(=foo) |
| 356 |
| ^--- |
| 357 |
| |
| 358 |
= expected <strict_identifier> or <expression> |
| 359 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols. |
| 360 |
[EOF] |
| 361 |
[exit status: 1] |
| 362 |
"); |
| 363 |
|
| 364 |
let output = work_dir.run_jj(["log", "-r", "remote_bookmarks(remote=)"]); |
| 365 |
insta::assert_snapshot!(output, @" |
| 366 |
------- stderr ------- |
| 367 |
Error: Failed to parse revset: Syntax error |
| 368 |
Caused by: --> 1:25 |
| 369 |
| |
| 370 |
1 | remote_bookmarks(remote=) |
| 371 |
| ^--- |
| 372 |
| |
| 373 |
= expected <expression> |
| 374 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols. |
| 375 |
[EOF] |
| 376 |
[exit status: 1] |
| 377 |
"); |
| 378 |
} |
| 379 |
|
| 380 |
#[test] |
| 381 |
fn test_function_name_hint() { |
| 382 |
let test_env = TestEnvironment::default(); |
| 383 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 384 |
let work_dir = test_env.work_dir("repo"); |
| 385 |
let evaluate = |expr| work_dir.run_jj(["log", "-r", expr]); |
| 386 |
|
| 387 |
test_env.add_config( |
| 388 |
r###" |
| 389 |
[revset-aliases] |
| 390 |
'bookmarks(x)' = 'x' # override builtin function |
| 391 |
'my_author(x)' = 'author(x)' # similar name to builtin function |
| 392 |
'author_sym' = 'x' # not a function alias |
| 393 |
'my_bookmarks' = 'bookmark()' # typo in alias |
| 394 |
"###, |
| 395 |
); |
| 396 |
|
| 397 |
// The suggestion "bookmarks" shouldn't be duplicated |
| 398 |
insta::assert_snapshot!(evaluate("bookmark()"), @" |
| 399 |
------- stderr ------- |
| 400 |
Error: Failed to parse revset: Function `bookmark` doesn't exist |
| 401 |
Caused by: --> 1:1 |
| 402 |
| |
| 403 |
1 | bookmark() |
| 404 |
| ^------^ |
| 405 |
| |
| 406 |
= Function `bookmark` doesn't exist |
| 407 |
Hint: Did you mean `bookmarks`, `remote_bookmarks`? |
| 408 |
[EOF] |
| 409 |
[exit status: 1] |
| 410 |
"); |
| 411 |
|
| 412 |
// Both builtin function and function alias should be suggested |
| 413 |
insta::assert_snapshot!(evaluate("author_()"), @" |
| 414 |
------- stderr ------- |
| 415 |
Error: Failed to parse revset: Function `author_` doesn't exist |
| 416 |
Caused by: --> 1:1 |
| 417 |
| |
| 418 |
1 | author_() |
| 419 |
| ^-----^ |
| 420 |
| |
| 421 |
= Function `author_` doesn't exist |
| 422 |
Hint: Did you mean `author`, `author_date`, `author_email`, `author_name`, `my_author`? |
| 423 |
[EOF] |
| 424 |
[exit status: 1] |
| 425 |
"); |
| 426 |
|
| 427 |
insta::assert_snapshot!(evaluate("my_bookmarks"), @" |
| 428 |
------- stderr ------- |
| 429 |
Error: Failed to parse revset: In alias `my_bookmarks` |
| 430 |
Caused by: |
| 431 |
1: --> 1:1 |
| 432 |
| |
| 433 |
1 | my_bookmarks |
| 434 |
| ^----------^ |
| 435 |
| |
| 436 |
= In alias `my_bookmarks` |
| 437 |
2: --> 1:1 |
| 438 |
| |
| 439 |
1 | bookmark() |
| 440 |
| ^------^ |
| 441 |
| |
| 442 |
= Function `bookmark` doesn't exist |
| 443 |
Hint: Did you mean `bookmarks`, `remote_bookmarks`? |
| 444 |
[EOF] |
| 445 |
[exit status: 1] |
| 446 |
"); |
| 447 |
} |
| 448 |
|
| 449 |
#[test] |
| 450 |
fn test_bad_symbol_or_argument_should_not_be_optimized_out() { |
| 451 |
let test_env = TestEnvironment::default(); |
| 452 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 453 |
let work_dir = test_env.work_dir("repo"); |
| 454 |
|
| 455 |
let output = work_dir.run_jj(["log", "-r", "unknown & none()"]); |
| 456 |
insta::assert_snapshot!(output, @" |
| 457 |
------- stderr ------- |
| 458 |
Error: Revision `unknown` doesn't exist |
| 459 |
[EOF] |
| 460 |
[exit status: 1] |
| 461 |
"); |
| 462 |
|
| 463 |
let output = work_dir.run_jj(["log", "-r", "all() | unknown"]); |
| 464 |
insta::assert_snapshot!(output, @" |
| 465 |
------- stderr ------- |
| 466 |
Error: Revision `unknown` doesn't exist |
| 467 |
[EOF] |
| 468 |
[exit status: 1] |
| 469 |
"); |
| 470 |
|
| 471 |
let output = work_dir.run_jj(["log", "-r", "description(regex:'(') & none()"]); |
| 472 |
insta::assert_snapshot!(output, @" |
| 473 |
------- stderr ------- |
| 474 |
Error: Failed to parse revset: Invalid string pattern |
| 475 |
Caused by: |
| 476 |
1: --> 1:13 |
| 477 |
| |
| 478 |
1 | description(regex:'(') & none() |
| 479 |
| ^-------^ |
| 480 |
| |
| 481 |
= Invalid string pattern |
| 482 |
2: regex parse error: |
| 483 |
( |
| 484 |
^ |
| 485 |
error: unclosed group |
| 486 |
[EOF] |
| 487 |
[exit status: 1] |
| 488 |
"); |
| 489 |
|
| 490 |
let output = work_dir.run_jj(["log", "-r", "files('..') & none()"]); |
| 491 |
insta::assert_snapshot!(output.normalize_backslash(), @r#" |
| 492 |
------- stderr ------- |
| 493 |
Error: Failed to parse revset: In fileset expression |
| 494 |
Caused by: |
| 495 |
1: --> 1:7 |
| 496 |
| |
| 497 |
1 | files('..') & none() |
| 498 |
| ^--^ |
| 499 |
| |
| 500 |
= In fileset expression |
| 501 |
2: --> 1:1 |
| 502 |
| |
| 503 |
1 | '..' |
| 504 |
| ^--^ |
| 505 |
| |
| 506 |
= Invalid file pattern |
| 507 |
3: Path ".." is not in the repo "." |
| 508 |
4: Invalid component ".." in repo-relative path ".." |
| 509 |
[EOF] |
| 510 |
[exit status: 1] |
| 511 |
"#); |
| 512 |
} |
| 513 |
|
| 514 |
#[test] |
| 515 |
fn test_default_string_pattern() { |
| 516 |
let test_env = TestEnvironment::default(); |
| 517 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 518 |
let work_dir = test_env.work_dir("repo"); |
| 519 |
|
| 520 |
// glob match by default |
| 521 |
let output = work_dir.run_jj(["log", "-rauthor('*test.user*')"]); |
| 522 |
insta::assert_snapshot!(output.normalize_backslash(), @" |
| 523 |
@ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 524 |
│ (empty) (no description set) |
| 525 |
~ |
| 526 |
[EOF] |
| 527 |
"); |
| 528 |
} |
| 529 |
|
| 530 |
// TODO: Remove in jj 0.44+ |
| 531 |
#[test] |
| 532 |
fn test_deprecated_diff_contains() { |
| 533 |
let test_env = TestEnvironment::default(); |
| 534 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 535 |
let work_dir = test_env.work_dir("repo"); |
| 536 |
|
| 537 |
let output = work_dir.run_jj(["log", "-rdiff_contains('') | diff_lines('')"]); |
| 538 |
insta::assert_snapshot!(output, @" |
| 539 |
------- stderr ------- |
| 540 |
Warning: In revset expression |
| 541 |
--> 1:1 |
| 542 |
| |
| 543 |
1 | diff_contains('') | diff_lines('') |
| 544 |
| ^-----------^ |
| 545 |
| |
| 546 |
= diff_contains() is deprecated; use diff_lines() instead |
| 547 |
[EOF] |
| 548 |
"); |
| 549 |
} |
| 550 |
|
| 551 |
#[test] |
| 552 |
fn test_alias() { |
| 553 |
let test_env = TestEnvironment::default(); |
| 554 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 555 |
let work_dir = test_env.work_dir("repo"); |
| 556 |
|
| 557 |
test_env.add_config( |
| 558 |
r###" |
| 559 |
[revset-aliases] |
| 560 |
'my-root' = 'root()' |
| 561 |
'syntax-error' = 'whatever &' |
| 562 |
'recurse' = 'recurse1' |
| 563 |
'recurse1' = 'recurse2()' |
| 564 |
'recurse2()' = 'recurse' |
| 565 |
'identity(x)' = 'x' |
| 566 |
'my_author(x)' = 'author(x)' |
| 567 |
'grep:x' = 'description(regex:x)' |
| 568 |
"###, |
| 569 |
); |
| 570 |
|
| 571 |
let output = work_dir.run_jj(["log", "-r", "my-root"]); |
| 572 |
insta::assert_snapshot!(output, @" |
| 573 |
◆ zzzzzzzz root() 00000000 |
| 574 |
[EOF] |
| 575 |
"); |
| 576 |
|
| 577 |
let output = work_dir.run_jj(["log", "-r", "identity(my-root)"]); |
| 578 |
insta::assert_snapshot!(output, @" |
| 579 |
◆ zzzzzzzz root() 00000000 |
| 580 |
[EOF] |
| 581 |
"); |
| 582 |
|
| 583 |
let output = work_dir.run_jj(["log", "-r", "root() & syntax-error"]); |
| 584 |
insta::assert_snapshot!(output, @" |
| 585 |
------- stderr ------- |
| 586 |
Error: Failed to parse revset: In alias `syntax-error` |
| 587 |
Caused by: |
| 588 |
1: --> 1:10 |
| 589 |
| |
| 590 |
1 | root() & syntax-error |
| 591 |
| ^----------^ |
| 592 |
| |
| 593 |
= In alias `syntax-error` |
| 594 |
2: --> 1:11 |
| 595 |
| |
| 596 |
1 | whatever & |
| 597 |
| ^--- |
| 598 |
| |
| 599 |
= expected `::`, `..`, `~`, or <primary> |
| 600 |
Hint: See https://docs.jj-vcs.dev/latest/revsets/ or use `jj help -k revsets` for revsets syntax and how to quote symbols. |
| 601 |
[EOF] |
| 602 |
[exit status: 1] |
| 603 |
"); |
| 604 |
|
| 605 |
let output = work_dir.run_jj(["log", "-r", "identity()"]); |
| 606 |
insta::assert_snapshot!(output, @" |
| 607 |
------- stderr ------- |
| 608 |
Error: Failed to parse revset: Function `identity`: Expected 1 arguments |
| 609 |
Caused by: --> 1:10 |
| 610 |
| |
| 611 |
1 | identity() |
| 612 |
| ^ |
| 613 |
| |
| 614 |
= Function `identity`: Expected 1 arguments |
| 615 |
[EOF] |
| 616 |
[exit status: 1] |
| 617 |
"); |
| 618 |
|
| 619 |
let output = work_dir.run_jj(["log", "-r", "my_author(none())"]); |
| 620 |
insta::assert_snapshot!(output, @" |
| 621 |
------- stderr ------- |
| 622 |
Error: Failed to parse revset: In alias `my_author(x)` |
| 623 |
Caused by: |
| 624 |
1: --> 1:1 |
| 625 |
| |
| 626 |
1 | my_author(none()) |
| 627 |
| ^---------------^ |
| 628 |
| |
| 629 |
= In alias `my_author(x)` |
| 630 |
2: --> 1:8 |
| 631 |
| |
| 632 |
1 | author(x) |
| 633 |
| ^ |
| 634 |
| |
| 635 |
= In function parameter `x` |
| 636 |
3: --> 1:11 |
| 637 |
| |
| 638 |
1 | my_author(none()) |
| 639 |
| ^----^ |
| 640 |
| |
| 641 |
= Invalid string expression |
| 642 |
[EOF] |
| 643 |
[exit status: 1] |
| 644 |
"); |
| 645 |
|
| 646 |
let output = work_dir.run_jj(["log", "-r", "my_author(unknown:pat)"]); |
| 647 |
insta::assert_snapshot!(output, @" |
| 648 |
------- stderr ------- |
| 649 |
Error: Failed to parse revset: In alias `my_author(x)` |
| 650 |
Caused by: |
| 651 |
1: --> 1:1 |
| 652 |
| |
| 653 |
1 | my_author(unknown:pat) |
| 654 |
| ^--------------------^ |
| 655 |
| |
| 656 |
= In alias `my_author(x)` |
| 657 |
2: --> 1:8 |
| 658 |
| |
| 659 |
1 | author(x) |
| 660 |
| ^ |
| 661 |
| |
| 662 |
= In function parameter `x` |
| 663 |
3: --> 1:11 |
| 664 |
| |
| 665 |
1 | my_author(unknown:pat) |
| 666 |
| ^---------^ |
| 667 |
| |
| 668 |
= Invalid string pattern |
| 669 |
4: Invalid string pattern kind `unknown:` |
| 670 |
Hint: Try prefixing with one of `exact:`, `glob:`, `regex:`, `substring:`, or one of these with `-i` suffix added (e.g. `glob-i:`) for case-insensitive matching |
| 671 |
[EOF] |
| 672 |
[exit status: 1] |
| 673 |
"); |
| 674 |
|
| 675 |
let output = work_dir.run_jj(["log", "-r", "author(exact:my-root)"]); |
| 676 |
insta::assert_snapshot!(output, @" |
| 677 |
------- stderr ------- |
| 678 |
Error: Failed to parse revset: In alias `my-root` |
| 679 |
Caused by: |
| 680 |
1: --> 1:14 |
| 681 |
| |
| 682 |
1 | author(exact:my-root) |
| 683 |
| ^-----^ |
| 684 |
| |
| 685 |
= In alias `my-root` |
| 686 |
2: --> 1:1 |
| 687 |
| |
| 688 |
1 | root() |
| 689 |
| ^----^ |
| 690 |
| |
| 691 |
= Expected string |
| 692 |
[EOF] |
| 693 |
[exit status: 1] |
| 694 |
"); |
| 695 |
|
| 696 |
let output = work_dir.run_jj(["log", "-r", "grep:my-root"]); |
| 697 |
insta::assert_snapshot!(output, @" |
| 698 |
------- stderr ------- |
| 699 |
Error: Failed to parse revset: In alias `grep:x` |
| 700 |
Caused by: |
| 701 |
1: --> 1:1 |
| 702 |
| |
| 703 |
1 | grep:my-root |
| 704 |
| ^----------^ |
| 705 |
| |
| 706 |
= In alias `grep:x` |
| 707 |
2: --> 1:19 |
| 708 |
| |
| 709 |
1 | description(regex:x) |
| 710 |
| ^ |
| 711 |
| |
| 712 |
= In function parameter `x` |
| 713 |
3: --> 1:6 |
| 714 |
| |
| 715 |
1 | grep:my-root |
| 716 |
| ^-----^ |
| 717 |
| |
| 718 |
= In alias `my-root` |
| 719 |
4: --> 1:1 |
| 720 |
| |
| 721 |
1 | root() |
| 722 |
| ^----^ |
| 723 |
| |
| 724 |
= Expected string |
| 725 |
[EOF] |
| 726 |
[exit status: 1] |
| 727 |
"); |
| 728 |
|
| 729 |
let output = work_dir.run_jj(["log", "-r", "root() & recurse"]); |
| 730 |
insta::assert_snapshot!(output, @" |
| 731 |
------- stderr ------- |
| 732 |
Error: Failed to parse revset: In alias `recurse` |
| 733 |
Caused by: |
| 734 |
1: --> 1:10 |
| 735 |
| |
| 736 |
1 | root() & recurse |
| 737 |
| ^-----^ |
| 738 |
| |
| 739 |
= In alias `recurse` |
| 740 |
2: --> 1:1 |
| 741 |
| |
| 742 |
1 | recurse1 |
| 743 |
| ^------^ |
| 744 |
| |
| 745 |
= In alias `recurse1` |
| 746 |
3: --> 1:1 |
| 747 |
| |
| 748 |
1 | recurse2() |
| 749 |
| ^--------^ |
| 750 |
| |
| 751 |
= In alias `recurse2()` |
| 752 |
4: --> 1:1 |
| 753 |
| |
| 754 |
1 | recurse |
| 755 |
| ^-----^ |
| 756 |
| |
| 757 |
= Alias `recurse` expanded recursively |
| 758 |
[EOF] |
| 759 |
[exit status: 1] |
| 760 |
"); |
| 761 |
} |
| 762 |
|
| 763 |
#[test] |
| 764 |
fn test_alias_override() { |
| 765 |
let test_env = TestEnvironment::default(); |
| 766 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 767 |
let work_dir = test_env.work_dir("repo"); |
| 768 |
|
| 769 |
test_env.add_config( |
| 770 |
r###" |
| 771 |
[revset-aliases] |
| 772 |
'f(x)' = 'user' |
| 773 |
"###, |
| 774 |
); |
| 775 |
|
| 776 |
// 'f(x)' should be overridden by --config 'f(a)'. If aliases were sorted |
| 777 |
// purely by name, 'f(a)' would come first. |
| 778 |
let output = work_dir.run_jj(["log", "-r", "f(_)", "--config=revset-aliases.'f(a)'=arg"]); |
| 779 |
insta::assert_snapshot!(output, @" |
| 780 |
------- stderr ------- |
| 781 |
Error: Revision `arg` doesn't exist |
| 782 |
[EOF] |
| 783 |
[exit status: 1] |
| 784 |
"); |
| 785 |
} |
| 786 |
|
| 787 |
#[test] |
| 788 |
fn test_bad_alias_decl() { |
| 789 |
let test_env = TestEnvironment::default(); |
| 790 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 791 |
let work_dir = test_env.work_dir("repo"); |
| 792 |
|
| 793 |
test_env.add_config( |
| 794 |
r#" |
| 795 |
[revset-aliases] |
| 796 |
'my-root' = 'root()' |
| 797 |
'"bad"' = 'root()' |
| 798 |
'badfn(a, a)' = 'root()' |
| 799 |
"#, |
| 800 |
); |
| 801 |
|
| 802 |
// Invalid declaration should be warned and ignored. |
| 803 |
let output = work_dir.run_jj(["log", "-r", "my-root"]); |
| 804 |
insta::assert_snapshot!(output, @r#" |
| 805 |
◆ zzzzzzzz root() 00000000 |
| 806 |
[EOF] |
| 807 |
------- stderr ------- |
| 808 |
Warning: Failed to load `revset-aliases."bad"`: --> 1:1 |
| 809 |
| |
| 810 |
1 | "bad" |
| 811 |
| ^--- |
| 812 |
| |
| 813 |
= expected <strict_identifier> or <function_name> |
| 814 |
Warning: Failed to load `revset-aliases.badfn(a, a)`: --> 1:7 |
| 815 |
| |
| 816 |
1 | badfn(a, a) |
| 817 |
| ^--^ |
| 818 |
| |
| 819 |
= Redefinition of function parameter |
| 820 |
[EOF] |
| 821 |
"#); |
| 822 |
} |
| 823 |
|
| 824 |
/// Verifies that the committer_date revset honors the local time zone. |
| 825 |
/// This test cannot run on Windows because The TZ env var does not control |
| 826 |
/// chrono::Local on that platform. |
| 827 |
#[test] |
| 828 |
#[cfg(not(target_os = "windows"))] |
| 829 |
fn test_revset_committer_date_with_time_zone() { |
| 830 |
// Use these for the test instead of tzdb identifiers like America/New_York |
| 831 |
// because the tz database may not be installed on some build servers |
| 832 |
const NEW_YORK: &str = "EST+5EDT+4,M3.1.0,M11.1.0"; |
| 833 |
const CHICAGO: &str = "CST+6CDT+5,M3.1.0,M11.1.0"; |
| 834 |
const AUSTRALIA: &str = "AEST-10"; |
| 835 |
let mut test_env = TestEnvironment::default(); |
| 836 |
test_env.add_env_var("TZ", NEW_YORK); |
| 837 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 838 |
let work_dir = test_env.work_dir("repo"); |
| 839 |
|
| 840 |
work_dir |
| 841 |
.run_jj([ |
| 842 |
"--config=debug.commit-timestamp=2023-01-25T11:30:00-05:00", |
| 843 |
"describe", |
| 844 |
"-m", |
| 845 |
"first", |
| 846 |
]) |
| 847 |
.success(); |
| 848 |
work_dir |
| 849 |
.run_jj([ |
| 850 |
"--config=debug.commit-timestamp=2023-01-25T12:30:00-05:00", |
| 851 |
"new", |
| 852 |
"-m", |
| 853 |
"second", |
| 854 |
]) |
| 855 |
.success(); |
| 856 |
work_dir |
| 857 |
.run_jj([ |
| 858 |
"--config=debug.commit-timestamp=2023-01-25T13:30:00-05:00", |
| 859 |
"new", |
| 860 |
"-m", |
| 861 |
"third", |
| 862 |
]) |
| 863 |
.success(); |
| 864 |
|
| 865 |
let mut log_commits_before_and_after = |committer_date: &str, now: &str, tz: &str| { |
| 866 |
test_env.add_env_var("TZ", tz); |
| 867 |
let config = format!("debug.commit-timestamp={now}"); |
| 868 |
let work_dir = test_env.work_dir("repo"); |
| 869 |
let before_log = work_dir.run_jj([ |
| 870 |
"--config", |
| 871 |
config.as_str(), |
| 872 |
"log", |
| 873 |
"--no-graph", |
| 874 |
"-T", |
| 875 |
"description.first_line() ++ ' ' ++ committer.timestamp() ++ '\n'", |
| 876 |
"-r", |
| 877 |
format!("committer_date(before:'{committer_date}') ~ root()").as_str(), |
| 878 |
]); |
| 879 |
let after_log = work_dir.run_jj([ |
| 880 |
"--config", |
| 881 |
config.as_str(), |
| 882 |
"log", |
| 883 |
"--no-graph", |
| 884 |
"-T", |
| 885 |
"description.first_line() ++ ' ' ++ committer.timestamp() ++ '\n'", |
| 886 |
"-r", |
| 887 |
format!("committer_date(after:'{committer_date}')").as_str(), |
| 888 |
]); |
| 889 |
(before_log, after_log) |
| 890 |
}; |
| 891 |
|
| 892 |
let (before_log, after_log) = |
| 893 |
log_commits_before_and_after("2023-01-25 12:00", "2023-02-01T00:00:00-05:00", NEW_YORK); |
| 894 |
insta::assert_snapshot!(before_log, @" |
| 895 |
first 2023-01-25 11:30:00.000 -05:00 |
| 896 |
[EOF] |
| 897 |
"); |
| 898 |
insta::assert_snapshot!(after_log, @" |
| 899 |
third 2023-01-25 13:30:00.000 -05:00 |
| 900 |
second 2023-01-25 12:30:00.000 -05:00 |
| 901 |
[EOF] |
| 902 |
"); |
| 903 |
|
| 904 |
// Switch to DST and ensure we get the same results, because it should |
| 905 |
// evaluate 12:00 on commit date, not the current date |
| 906 |
let (before_log, after_log) = |
| 907 |
log_commits_before_and_after("2023-01-25 12:00", "2023-06-01T00:00:00-04:00", NEW_YORK); |
| 908 |
insta::assert_snapshot!(before_log, @" |
| 909 |
first 2023-01-25 11:30:00.000 -05:00 |
| 910 |
[EOF] |
| 911 |
"); |
| 912 |
insta::assert_snapshot!(after_log, @" |
| 913 |
third 2023-01-25 13:30:00.000 -05:00 |
| 914 |
second 2023-01-25 12:30:00.000 -05:00 |
| 915 |
[EOF] |
| 916 |
"); |
| 917 |
|
| 918 |
// Change the local time zone and ensure the result changes |
| 919 |
let (before_log, after_log) = |
| 920 |
log_commits_before_and_after("2023-01-25 12:00", "2023-06-01T00:00:00-06:00", CHICAGO); |
| 921 |
insta::assert_snapshot!(before_log, @" |
| 922 |
second 2023-01-25 12:30:00.000 -05:00 |
| 923 |
first 2023-01-25 11:30:00.000 -05:00 |
| 924 |
[EOF] |
| 925 |
"); |
| 926 |
insta::assert_snapshot!(after_log, @" |
| 927 |
third 2023-01-25 13:30:00.000 -05:00 |
| 928 |
[EOF] |
| 929 |
"); |
| 930 |
|
| 931 |
// Time zone far outside USA with no DST |
| 932 |
let (before_log, after_log) = |
| 933 |
log_commits_before_and_after("2023-01-26 03:00", "2023-06-01T00:00:00+10:00", AUSTRALIA); |
| 934 |
insta::assert_snapshot!(before_log, @" |
| 935 |
first 2023-01-25 11:30:00.000 -05:00 |
| 936 |
[EOF] |
| 937 |
"); |
| 938 |
insta::assert_snapshot!(after_log, @" |
| 939 |
third 2023-01-25 13:30:00.000 -05:00 |
| 940 |
second 2023-01-25 12:30:00.000 -05:00 |
| 941 |
[EOF] |
| 942 |
"); |
| 943 |
} |
| 944 |
|
| 945 |
#[test] |
| 946 |
fn test_user_trunk_absent_or_conflicted() { |
| 947 |
let test_env = TestEnvironment::default(); |
| 948 |
// If trunk() is set to a local bookmark, resolution may fail due to |
| 949 |
// conflicted or divergent symbols. This wouldn't happen with the default or |
| 950 |
// auto-configured trunk(), which refers to remote bookmarks. |
| 951 |
test_env.add_config("revset-aliases.'trunk()' = 'main'"); |
| 952 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 953 |
let work_dir = test_env.work_dir("repo"); |
| 954 |
|
| 955 |
work_dir |
| 956 |
.run_jj(["new", "-mA", "--no-edit", "root()"]) |
| 957 |
.success(); |
| 958 |
work_dir |
| 959 |
.run_jj(["new", "-mB", "--no-edit", "root()"]) |
| 960 |
.success(); |
| 961 |
// "main" is still absent |
| 962 |
let output = work_dir.run_jj(["bookmark", "set", "-rsubject(A)", "main"]); |
| 963 |
insta::assert_snapshot!(output, @" |
| 964 |
------- stderr ------- |
| 965 |
Warning: Failed to resolve `revset-aliases.trunk()`: Revision `main` doesn't exist |
| 966 |
The `trunk()` alias is temporarily set to `root()`. |
| 967 |
Hint: Use `jj config edit --repo` to adjust the `trunk()` alias. |
| 968 |
Created 1 bookmarks pointing to rlvkpnrz 095dbd02 main | (empty) A |
| 969 |
[EOF] |
| 970 |
"); |
| 971 |
|
| 972 |
// "main" is now present |
| 973 |
let output = work_dir.run_jj(["log"]); |
| 974 |
insta::assert_snapshot!(output, @" |
| 975 |
@ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 976 |
│ (empty) (no description set) |
| 977 |
│ ○ kkmpptxz [email protected] 2001-02-03 08:05:09 e3ebbfd5 |
| 978 |
├─╯ (empty) B |
| 979 |
│ ◆ rlvkpnrz [email protected] 2001-02-03 08:05:08 main 095dbd02 |
| 980 |
├─╯ (empty) A |
| 981 |
◆ zzzzzzzz root() 00000000 |
| 982 |
[EOF] |
| 983 |
"); |
| 984 |
|
| 985 |
// make "main" conflicted ("main" doesn't exist at op @-) |
| 986 |
let output = work_dir.run_jj(["bookmark", "--at-op=@-", "set", "-rsubject(B)", "main"]); |
| 987 |
insta::assert_snapshot!(output, @" |
| 988 |
------- stderr ------- |
| 989 |
Warning: Failed to resolve `revset-aliases.trunk()`: Revision `main` doesn't exist |
| 990 |
The `trunk()` alias is temporarily set to `root()`. |
| 991 |
Hint: Use `jj config edit --repo` to adjust the `trunk()` alias. |
| 992 |
Created 1 bookmarks pointing to kkmpptxz e3ebbfd5 main | (empty) B |
| 993 |
[EOF] |
| 994 |
"); |
| 995 |
|
| 996 |
// "main" is conflicted |
| 997 |
let output = work_dir.run_jj(["log"]); |
| 998 |
insta::assert_snapshot!(output, @" |
| 999 |
@ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 1000 |
│ (empty) (no description set) |
| 1001 |
│ ○ kkmpptxz [email protected] 2001-02-03 08:05:09 main?? e3ebbfd5 |
| 1002 |
├─╯ (empty) B |
| 1003 |
│ ○ rlvkpnrz [email protected] 2001-02-03 08:05:08 main?? 095dbd02 |
| 1004 |
├─╯ (empty) A |
| 1005 |
◆ zzzzzzzz root() 00000000 |
| 1006 |
[EOF] |
| 1007 |
------- stderr ------- |
| 1008 |
Concurrent modification detected, resolving automatically. |
| 1009 |
Warning: Failed to resolve `revset-aliases.trunk()`: Name `main` is conflicted |
| 1010 |
The `trunk()` alias is temporarily set to `root()`. |
| 1011 |
Hint: Use `jj config edit --repo` to adjust the `trunk()` alias. |
| 1012 |
[EOF] |
| 1013 |
"); |
| 1014 |
} |