|
2 | 2 | // |
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | | -// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD winsize xpixel ypixel |
| 5 | +// spell-checker:ignore (words) bamf chdir rlimit prlimit COMSPEC cout cerr FFFD winsize xpixel ypixel Secho |
6 | 6 | #![allow(clippy::missing_errors_doc)] |
7 | 7 |
|
8 | 8 | #[cfg(unix)] |
@@ -1801,3 +1801,64 @@ fn test_shebang_error() { |
1801 | 1801 | .fails() |
1802 | 1802 | .stderr_contains("use -[v]S to pass options in shebang lines"); |
1803 | 1803 | } |
| 1804 | + |
| 1805 | +#[test] |
| 1806 | +#[cfg(not(target_os = "windows"))] |
| 1807 | +fn test_braced_variable_with_default_value() { |
| 1808 | + new_ucmd!() |
| 1809 | + .arg("-Secho ${UNSET_VAR_UNLIKELY_12345:fallback}") |
| 1810 | + .succeeds() |
| 1811 | + .stdout_is("fallback\n"); |
| 1812 | +} |
| 1813 | + |
| 1814 | +#[test] |
| 1815 | +#[cfg(not(target_os = "windows"))] |
| 1816 | +fn test_braced_variable_with_default_when_set() { |
| 1817 | + new_ucmd!() |
| 1818 | + .env("TEST_VAR_12345", "actual") |
| 1819 | + .arg("-Secho ${TEST_VAR_12345:fallback}") |
| 1820 | + .succeeds() |
| 1821 | + .stdout_is("actual\n"); |
| 1822 | +} |
| 1823 | + |
| 1824 | +#[test] |
| 1825 | +#[cfg(not(target_os = "windows"))] |
| 1826 | +fn test_simple_braced_variable() { |
| 1827 | + new_ucmd!() |
| 1828 | + .env("TEST_VAR_12345", "value") |
| 1829 | + .arg("-Secho ${TEST_VAR_12345}") |
| 1830 | + .succeeds() |
| 1831 | + .stdout_is("value\n"); |
| 1832 | +} |
| 1833 | + |
| 1834 | +#[test] |
| 1835 | +fn test_braced_variable_error_missing_closing_brace() { |
| 1836 | + new_ucmd!() |
| 1837 | + .arg("-Secho ${FOO") |
| 1838 | + .fails_with_code(125) |
| 1839 | + .stderr_contains("Missing closing brace"); |
| 1840 | +} |
| 1841 | + |
| 1842 | +#[test] |
| 1843 | +fn test_braced_variable_error_missing_closing_brace_after_default() { |
| 1844 | + new_ucmd!() |
| 1845 | + .arg("-Secho ${FOO:-value") |
| 1846 | + .fails_with_code(125) |
| 1847 | + .stderr_contains("Missing closing brace after default value"); |
| 1848 | +} |
| 1849 | + |
| 1850 | +#[test] |
| 1851 | +fn test_braced_variable_error_starts_with_digit() { |
| 1852 | + new_ucmd!() |
| 1853 | + .arg("-Secho ${1FOO}") |
| 1854 | + .fails_with_code(125) |
| 1855 | + .stderr_contains("Unexpected character: '1'"); |
| 1856 | +} |
| 1857 | + |
| 1858 | +#[test] |
| 1859 | +fn test_braced_variable_error_unexpected_character() { |
| 1860 | + new_ucmd!() |
| 1861 | + .arg("-Secho ${FOO?}") |
| 1862 | + .fails_with_code(125) |
| 1863 | + .stderr_contains("Unexpected character: '?'"); |
| 1864 | +} |
0 commit comments