[lit] Make internal diff work in pipelines
authorJoel E. Denny <jdenny.ornl@gmail.com>
Thu, 17 Oct 2019 14:02:42 +0000 (14:02 +0000)
committerJoel E. Denny <dennyje@ornl.gov>
Tue, 29 Oct 2019 19:13:52 +0000 (15:13 -0400)
commitb163806cdc317ee160a2ce694958c088a949fa7d
tree12022f7999d0698318fd87bd22c1f278bc12170a
parent772533d9214b6e23762847fc7080a4201396fb10
[lit] Make internal diff work in pipelines

When using lit's internal shell, RUN lines like the following
accidentally execute an external `diff` instead of lit's internal
`diff`:

```
 # RUN: program | diff file -
 # RUN: not diff file1 file2 | FileCheck %s
```

Such cases exist now, in `clang/test/Analysis` for example.  We are
preparing patches to ensure lit's internal `diff` is called in such
cases, which will then fail because lit's internal `diff` cannot
currently be used in pipelines and doesn't recognize `-` as a
command-line option.

To enable pipelines, this patch moves lit's `diff` implementation into
an out-of-process script, similar to lit's `cat` implementation.  A
follow-up patch will implement `-` to mean stdin.

Also, when lit's `diff` prints differences to stdout in Windows, this
patch ensures it always terminate lines with `\n` not `\r\n`.  That
way, strict FileCheck directives checking the `diff` output succeed in
both Linux and Windows.  This wasn't an issue when `diff` was internal
to lit because `diff` didn't then write to the true stdout, which is
where the `\n` -> `\r\n` conversion happened in Python.

Reviewed By: probinson, stella.stamenova

Differential Revision: https://reviews.llvm.org/D66574
llvm/utils/lit/lit/TestRunner.py
llvm/utils/lit/lit/builtin_commands/diff.py [new file with mode: 0644]
llvm/utils/lit/tests/Inputs/shtest-shell/diff-error-0.txt [deleted file]
llvm/utils/lit/tests/Inputs/shtest-shell/diff-pipes.txt [new file with mode: 0644]
llvm/utils/lit/tests/Inputs/shtest-shell/diff-unified-error-0.txt [deleted file]
llvm/utils/lit/tests/Inputs/shtest-shell/diff-unified-error-1.txt [deleted file]
llvm/utils/lit/tests/Inputs/shtest-shell/diff-unified.txt
llvm/utils/lit/tests/max-failures.py
llvm/utils/lit/tests/shtest-shell.py