Skip to content

Commit aa2ff11

Browse files
committed
Add tests for argument splitting
1 parent 81d8dc8 commit aa2ff11

File tree

6 files changed

+114
-0
lines changed

6 files changed

+114
-0
lines changed
632 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
description = "Echo command-line arguments"
2+
name = "echo_arguments"
3+
version = "1.0.0"
4+
maintainers = ["[email protected]"]
5+
maintainers-logins = ["mrlazy"]
6+
7+
[origin]
8+
url = "file:../../../crates/echo_arguments_1.0.tgz"
9+
hashes = ["sha512:bf19d20f74aa5766aed0fabd2f38983cdcaf5b130142fa476bc4bda0f31ad5b3c916fe0f9e8fe3d5f3efa74a5918799105ebed517ff993589c6e5923e3e587b0"]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Test `alr edit` argument splitting
3+
"""
4+
5+
from drivers.alr import run_alr, CalledProcessError
6+
from drivers.asserts import assert_match
7+
from subprocess import run
8+
9+
import os, re, shutil
10+
11+
alr_path = os.environ['ALR_PATH']
12+
13+
p = run_alr('settings', '--global', '--set', 'editor.cmd', 'sh -c "echo Argument splitting test"')
14+
15+
target = 'noop_1.0.0_filesystem'
16+
p = run_alr('get', 'noop=1.0-default', quiet=True)
17+
os.chdir(target)
18+
19+
p = run([alr_path, "edit"], capture_output=True)
20+
assert_match('Argument splitting test', p.stdout.decode(), flags=re.S)
21+
22+
os.chdir('..')
23+
shutil.rmtree(target)
24+
25+
print('SUCCESS')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
driver: python-script
2+
indexes:
3+
run_index:
4+
in_fixtures: true
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""
2+
Test `alr run -a` argument splitting
3+
"""
4+
5+
from drivers.alr import run_alr, CalledProcessError
6+
from drivers.asserts import assert_match
7+
from subprocess import run
8+
9+
import os, re, shutil
10+
11+
target = 'echo_arguments_1.0.0_filesystem'
12+
alr_path = os.environ['ALR_PATH']
13+
14+
def check_run(arguments, match="", should_fail=False):
15+
if not should_fail:
16+
p = run_alr('run', '-a', arguments, quiet=not match, complain_on_error=not should_fail)
17+
if match:
18+
assert_match(match, p.out, flags=re.S)
19+
else:
20+
# Need to check stderr on failure, so using subprocess.run
21+
p = run([alr_path, "run", "-a", arguments], capture_output=True)
22+
if 0 == p.returncode:
23+
raise CalledProcessError
24+
if match:
25+
assert_match(match, p.stderr.decode(), flags=re.S)
26+
27+
p = run_alr('get', 'echo_arguments', quiet=True)
28+
os.chdir(target)
29+
30+
# Split on spaces
31+
check_run('code example with spaces', match=".*'code'\n'example'\n'with'\n'spaces'")
32+
33+
# Escaped spaces
34+
check_run('code\ example\ with\ spaces', match=".*'code example with spaces'")
35+
36+
# Unnecessary escapes
37+
check_run('\c\o\d\e \example \with \s\p\\a\c\e\s', match=".*'code'\n'example'\n'with'\n'spaces'")
38+
39+
# Double quotes
40+
check_run('code "example with" spaces', match=".*'code'\n'example with'\n'spaces'")
41+
42+
# Single quotes
43+
check_run('code \'example with\' spaces', match=".*'code'\n'example with'\n'spaces'")
44+
45+
# Escaped double quotes
46+
check_run('code \\"example with\\" spaces', match=".*'code'\n'\"example'\n'with\"'\n'spaces'")
47+
48+
# Escaped single quotes
49+
check_run('code \\\'example with\\\' spaces', match=".*'code'\n'\\\\'example'\n'with\\\\''\n'spaces'")
50+
51+
# Nested escaped double quotes
52+
check_run('code \"example \\\" with\" spaces', match=".*'code'\n'example \" with'\n'spaces'")
53+
54+
# Escaped closing single quote (closing quote cannot be escaped)
55+
check_run('code \'example \\\' with spaces', match=".*'code'\n'example \\\\\\\\'\n'with'\n'spaces'")
56+
57+
# Nested double & single quotes
58+
check_run('code \"example \'with spaces\'\"', match=".*'code'\n'example \\\\'with spaces\\\\''")
59+
60+
# Unterminated escape should fail
61+
check_run('code example with spaces\\', match=".*Unterminated escape sequence in command:.*", should_fail=True)
62+
63+
# Unterminated single quote should fail
64+
check_run('code example with \'spaces', match=".*Unterminated single quote sequence in command:.*", should_fail=True)
65+
66+
# Unterminated double quote should fail
67+
check_run('code example with \"spaces', match=".*Unterminated double quote sequence in command:.*", should_fail=True)
68+
69+
os.chdir('..')
70+
shutil.rmtree(target)
71+
72+
print('SUCCESS')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
driver: python-script
2+
indexes:
3+
run_index:
4+
in_fixtures: true

0 commit comments

Comments
 (0)