|
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | 5 |
|
| 6 | +// spell-checker:ignore crème brûlée |
| 7 | + |
6 | 8 | use uutests::at_and_ucmd; |
7 | 9 | use uutests::new_ucmd; |
8 | 10 | use uutests::unwrap_or_return; |
@@ -447,6 +449,52 @@ fn test_quoting_style_locale() { |
447 | 449 | .stdout_only("\'\"\'\n"); |
448 | 450 | } |
449 | 451 |
|
| 452 | +#[test] |
| 453 | +fn test_quoting_style_invalid_env() { |
| 454 | + let ts = TestScenario::new(util_name!()); |
| 455 | + let at = &ts.fixtures; |
| 456 | + at.touch("baguette"); |
| 457 | + at.touch("Croissant"); |
| 458 | + at.touch("Escargot"); |
| 459 | + |
| 460 | + let needle = "ignoring invalid value of environment variable QUOTING_STYLE"; |
| 461 | + |
| 462 | + // A bogus value triggers exactly one warning across multiple files and the |
| 463 | + // output falls back to the default (shell-escape) style. |
| 464 | + let res = ts |
| 465 | + .ucmd() |
| 466 | + .env("QUOTING_STYLE", "fromage") |
| 467 | + .args(&["-c", "nom=[%N]", "baguette", "Croissant", "Escargot"]) |
| 468 | + .succeeds(); |
| 469 | + res.stdout_is("nom=['baguette']\nnom=['Croissant']\nnom=['Escargot']\n"); |
| 470 | + assert_eq!(res.stderr_str().matches(needle).count(), 1); |
| 471 | + |
| 472 | + // An empty value is also invalid and must be reported with empty quotes. |
| 473 | + ts.ucmd() |
| 474 | + .env("QUOTING_STYLE", "") |
| 475 | + .args(&["-c", "%N", "baguette"]) |
| 476 | + .succeeds() |
| 477 | + .stdout_is("'baguette'\n") |
| 478 | + .stderr_is("stat: ignoring invalid value of environment variable QUOTING_STYLE: ''\n"); |
| 479 | + |
| 480 | + // %%%N: a literal '%' followed by the quoted name, fallback style applies. |
| 481 | + ts.ucmd() |
| 482 | + .env("QUOTING_STYLE", "soufflé") |
| 483 | + .args(&["-c", "%%%N", "baguette"]) |
| 484 | + .succeeds() |
| 485 | + .stdout_is("%'baguette'\n") |
| 486 | + .stderr_is( |
| 487 | + "stat: ignoring invalid value of environment variable QUOTING_STYLE: 'soufflé'\n", |
| 488 | + ); |
| 489 | + |
| 490 | + // When the format never consults %N, QUOTING_STYLE must not be parsed at all. |
| 491 | + ts.ucmd() |
| 492 | + .env("QUOTING_STYLE", "crème-brûlée") |
| 493 | + .args(&["-c", "taille=%s genre:%F brut=%n", "baguette"]) |
| 494 | + .succeeds() |
| 495 | + .no_stderr(); |
| 496 | +} |
| 497 | + |
450 | 498 | #[test] |
451 | 499 | fn test_printf_octal_1() { |
452 | 500 | let ts = TestScenario::new(util_name!()); |
|
0 commit comments