Skip to content
New issue

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

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

Already on GitHub? # to your account

Input file: support reading from stdin, symlinks, others #35

Merged
merged 3 commits into from
Jun 25, 2020

Conversation

aureliojargas
Copy link
Owner

Previously, clitest only accepted the input file if it was a "normal"
(as in test -f) file. But that's too restrictive, for no reason. At
the end, it doesn't matter if it is a normal or a special file, what
matters is that it is readable and we can find the tests on it.

With those changes, now the input file can be:

  • A normal file
  • A symlink that points to a file
  • /dev/stdin in systems that support it
  • - as a shortcut to stdin

Reading from directories continues to be forbidden (we can't properly
identify clitest input files), but at least now the error message is
more clear that it is a directory.

Issue #32

We do not support reading a directory as an input file, since there's
no exclusive file extension or an easy way to detect test files among
other files.

Alternatively, users can inform a glob, for example `dir/*.sh`.
At the end, it doesn't matter if it is a normal file or not, what
matters is that we can read the tests from "somewhere".

Relaxing this check now allows for reading tests from different kinds
of files, such as symlinks and special devices such as `/dev/stdin`.
Using `-` to mean that the file comes from from STDIN is a Unix classic.
Let's support it.

The implementation is not that clean, in the sense that the "fake"
temporary path will appear when using two or more input files, and one
of them is `-`. But in the summary table at the end it correctly shows
`-`. Example:

    $ cat x
    $ echo 1
    2
    $

    $ cat x | ./clitest - x
    Testing file /var/folders/zj/1vb37fxj2rd2glwn48nrsjl80000gq/T//clitest.zfwux7/stdin.txt
    #1      echo 1
    -------------------------------------------------
    [FAILED #1, line 1] echo 1
    @@ -1 +1 @@
    -2
    +1
    -------------------------------------------------
    Testing file x
    #2      echo 1
    -------------------------------------------------
    [FAILED #2, line 1] echo 1
    @@ -1 +1 @@
    -2
    +1
    -------------------------------------------------

        ok  fail  skip
        -     1     -    -
        -     1     -    x

    FAIL: 2 of 2 tests failed
@aureliojargas aureliojargas merged commit 7194fdd into master Jun 25, 2020
@aureliojargas aureliojargas deleted the stdin branch June 25, 2020 23:19
@aureliojargas aureliojargas mentioned this pull request Jun 25, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant