coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

test: Show error when using a binary operator without two operands

Open sargas opened this issue 10 months ago • 6 comments

When preforming a binary operation with the test command, GNU coreutils gives an error if only one operands exist:

$ /bin/test -o blah
/bin/test: ‘-o’: unary operator expected
$ /bin/test -a blah
/bin/test: ‘-a’: unary operator expected

$ /bin/test blah -a
/bin/test: missing argument after ‘-a’
$ /bin/test blah -o
/bin/test: missing argument after ‘-o’

This PR adds the error messages for the first set, where the first operand is missing. The second operand missing does not appear as trivial, since Symbol::new causes the operator to be treated as a literal as part of the parsing.

With this PR, tests/test/test-diag.pl should pass.

This PR also fixes an integration test that says that -a ! should return an exit code of 1. GNU test gives an error with a status code of 2.

sargas avatar Apr 05 '24 05:04 sargas

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/test/test-diag is no longer failing!

github-actions[bot] avatar Apr 05 '24 06:04 github-actions[bot]

@sargas

The second operand missing does not appear as trivial, since Symbol::new causes the operator to be treated as a literal as part of the parsing.

This should still be done right? Should we open an issue for it in meantime?

tertsdiepraam avatar Apr 05 '24 07:04 tertsdiepraam

@sargas

The second operand missing does not appear as trivial, since Symbol::new causes the operator to be treated as a literal as part of the parsing.

This should still be done right? Should we open an issue for it in meantime?

Agreed, especially since the GNU tests didn't check for this. I can have a go at this tonight

sargas avatar Apr 05 '24 13:04 sargas

@sargas ping ? :)

sylvestre avatar Apr 08 '24 07:04 sylvestre

@sargas ping ? :)

Sorry, busier than expected, still interested in this PR. Whether <blah> -a shows an error is different for an arbitrary string and for !, so I wanted to create some more test cases

sargas avatar Apr 08 '24 14:04 sargas

GNU testsuite comparison:

Congrats! The gnu test tests/test/test-diag is no longer failing!

github-actions[bot] avatar Apr 27 '24 10:04 github-actions[bot]