Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Qw, Qx and Qww. One more test for qx to check how two backslashes are interpreted #182

Merged
merged 4 commits into from Nov 15, 2016

Conversation

samcv
Copy link
Contributor

@samcv samcv commented Nov 14, 2016

No description provided.

@@ -524,6 +527,8 @@ Hello, World
my $var = 'world';
is qx/echo world/.chomp, "world", 'qx';
is qqx/echo $var/.chomp, "world", 'qqx';
is Qx[echo '\\'].chomp, "\\\\", "Qx treats backslash literally";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails. With different failure modes on Debian and on Windows, because Windows uses " as shell quoting character:

Debian:

not ok 1 - Qx treats backslash literally

# Failed test 'Qx treats backslash literally'
# at z.p6 line 4
# expected: '\\'
#      got: '\'

Windows:

not ok 1 - Qx treats backslash literally

# Failed test 'Qx treats backslash literally'
# at p.t line 4
# expected: '\\'
#      got: ''\\''

@@ -524,6 +527,8 @@ Hello, World
my $var = 'world';
is qx/echo world/.chomp, "world", 'qx';
is qqx/echo $var/.chomp, "world", 'qqx';
is Qx[echo '\\'].chomp, "\\\\", "Qx treats backslash literally";
is qx[echo '\\'].chomp, "\\", 'qx escaping a backslash returns one backslash';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails on Windows, as it uses " quotes for shell escapes:

# Failed test 'qx escaping a backslash returns one backslash'
# at p.t line 5
# expected: '\'
#      got: ''\''

@samcv
Copy link
Contributor Author

samcv commented Nov 14, 2016

It should pass now I think on Windows and POSIX environments. Since echo on Windows leaves quotation marks in, and on POSIX we need them to treat the contents literally, compare qx[echo '\\\\\\\\'] and Qx[echo '\\\\'] to have the same result. The reason for so many slashes is this:
bash, sh, dash (echo binary), csh builtin, busybox builtin:
echo '\' #> \
echo '\\' #> \\
zsh builtin and tcsh builtin:
echo '\' #> \
echo '\\' #> \
Windows:
echo '\' #> '\'
echo '\\' #> '\\'

zsh and tcsh's builtin echo does not properly follow POSIX. Although worst case would be that the test would pass when it shouldn't, we can do better than this. We fix this with the extra slashes. As you can see all the below are different, and the test is functional on POSIX compliant and noncompliant echo's
zsh builtin and tcsh builtin:
echo '\\\\\\\\' #> \\\\
echo '\\\\' #> \\
echo '\\' #> \

If something went wrong and Qx has sent half as many slashes as expected, this should detect it without assuming which shell the user has set as the system shell.

@zoffixznet zoffixznet merged commit f1581ac into Raku:master Nov 15, 2016
@zoffixznet
Copy link
Contributor

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants