Joel E. Denny b163806cdc [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
2019-10-29 15:13:52 -04:00

39 lines
976 B
Plaintext

# RUN: echo 1 > %t.foo
# RUN: echo 2 >> %t.foo
# RUN: echo 3 >> %t.foo
# RUN: echo 4 >> %t.foo
# RUN: echo 5 >> %t.foo
# RUN: echo 6 foo >> %t.foo
# RUN: echo 7 >> %t.foo
# RUN: echo 8 >> %t.foo
# RUN: echo 9 >> %t.foo
# RUN: echo 10 >> %t.foo
# RUN: echo 11 >> %t.foo
# RUN: echo 1 > %t.bar
# RUN: echo 2 >> %t.bar
# RUN: echo 3 >> %t.bar
# RUN: echo 4 >> %t.bar
# RUN: echo 5 >> %t.bar
# RUN: echo 6 bar >> %t.bar
# RUN: echo 7 >> %t.bar
# RUN: echo 8 >> %t.bar
# RUN: echo 9 >> %t.bar
# RUN: echo 10 >> %t.bar
# RUN: echo 11 >> %t.bar
# Default is 3 lines of context.
# RUN: diff -u %t.foo %t.bar && false || true
# Override default of 3 lines of context.
# RUN: diff -U 2 %t.foo %t.bar && false || true
# RUN: diff -U4 %t.foo %t.bar && false || true
# RUN: diff -U0 %t.foo %t.bar && false || true
# Check bad -U argument.
# RUN: diff -U 30.1 %t.foo %t.foo && false || true
# RUN: diff -U-1 %t.foo %t.foo && false || true
# Fail so lit will print output.
# RUN: false