uutils / uutils/coreutils

test: "unary bool-op" unfixable with current parser

Open
#6,203 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - test
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

We currently fail the GNU test test/test-diag, which simply asserts that test -a arg outputs the error message '-a': unary operator expected.

However, this is unfixable with our current parser. To demonstrate this claim, let's insert eprintln!("{:?}", p.stack); near the very end of parser.rs, right before Ok(p.stack). Then we get the following outputs:

$ ../gnu/src/test x -a '(' -o asd ')' -a y
../gnu/src/test: ‘-o’: unary operator expected
[$? = 2]
$ ../gnu/src/test -a "(" x -o asd ")" -a y
../gnu/src/test: ‘-a’: unary operator expected
[$? = 2]
$ cargo run test x -a '(' -o asd ')' -a y
[Literal("x"), Literal("asd"), BoolOp("-o"), BoolOp("-a"), Literal("y"), BoolOp("-a")]
$ cargo run test -a "(" x -o asd ")" -a y
[Literal("x"), Literal("asd"), BoolOp("-o"), BoolOp("-a"), Literal("y"), BoolOp("-a")]

This demonstrates that two different inputs shall result in two different outputs according to GNU. However, the parser creates identical parse stacks in both cases. Therefore, the parser must be fixed (otherwise eval has no chance).

However, the parser is a complicated beast. For example, the BNF grammar and the actual parsing method do not seem to be closely related. lparen and bang peek up to 3 and 4 tokens ahead, I don't feel confident that this handles all cases correctly. Therefore, I don't want to touch the parser, or at least not now, and simply document the test cases above.

@drocco007, it looks like you wrote most of the parser, do you feel like taking up this task? :)

Here's two more interesting cases, that currently fail ($? = 2) in the parser:

$ ../gnu/src/test -a "(" x ")"
../gnu/src/test: ‘-a’: unary operator expected
[$? = 2]
$ ../gnu/src/test "(" -a x ")"
../gnu/src/test: ‘-a’: unary operator expected
[$? = 2]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with parser.rs, especially the parsing path near the reported Ok(p.stack) point, and reproduce the cases from test/test-diag and the GNU command examples. Compare the parser stacks and resulting evaluations for the four failing inputs; done means the inputs no longer collapse to one parse and the GNU diagnostic behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.