Skip to content

Commit b4423b9

Browse files
authored
Adding integration tests for the braced variable parsing in env (#9459)
* Adding integration tests for the braced variable parsing in env * Adding missing spell checker words
1 parent 69008b6 commit b4423b9

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

tests/by-util/test_env.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// For the full copyright and license information, please view the LICENSE
44
// 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
66
#![allow(clippy::missing_errors_doc)]
77

88
#[cfg(unix)]
@@ -1801,3 +1801,64 @@ fn test_shebang_error() {
18011801
.fails()
18021802
.stderr_contains("use -[v]S to pass options in shebang lines");
18031803
}
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

Comments
 (0)