Fangrui Song d054c7ee2e Add test utility 'extract'
See https://lists.llvm.org/pipermail/llvm-dev/2020-July/143373.html
"[llvm-dev] Multiple documents in one test file" for some discussions.

`extract part filename` splits the input file into multiple parts separated by
regex `^(.|//)--- ` and extract the specified part to stdout or the
output file (if specified).

Use case A (organizing input of different formats (e.g. linker
script+assembly) in one file).

```
// RUN: extract lds %s -o %t.lds
// RUN: extract asm %s -o %t.s
// RUN: llvm-mc %t.s -o %t.o
// RUN: ld.lld -T %t.lds %t.o -o %t
This is sometimes better than the %S/Inputs/ approach because the user
can see the auxiliary files immediately and don't have to open another file.
```

Use case B (for utilities which don't have built-in input splitting
feature):

```
// RUN: extract case1 %s | llc | FileCheck %s --check-prefix=CASE1
// RUN: extract case2 %s | llc | FileCheck %s --check-prefix=CASE2
Combing tests prudently can improve readability.
This is sometimes better than having multiple test files.
```

Since this is a new utility, there is no git history concerns for
UpperCase variable names. I use lowerCase variable names like mlir/lld.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D83834
2020-07-23 19:15:35 -07:00

33 lines
784 B
Plaintext

# AA-NOT: {{.}}
# AA: {{^}}aa{{$}}
#--- aa
aa
; BB-NOT: {{.}}
; BB: {{^}}bb{{$}}
;--- bb
bb
// CC: // Comments are preserved.
//--- cc
cc
// Comments are preserved.
;--- dup
;--- dup
# RUN: extract aa %s | diff %S/Inputs/basic-aa.txt -
# RUN: extract bb - < %s | diff %S/Inputs/basic-bb.txt -
# RUN: extract cc %s -o %t
# RUN: FileCheck %s --check-prefix=CC < %t
# RUN: not %extract aa 2>&1 | FileCheck %s --check-prefix=NO_INPUT
# NO_INPUT: extract: error: input filename is not specified
# RUN: not %extract dup %s 2>&1 | FileCheck %s --check-prefix=DUP
# DUP: extract: error: {{.*}}.test: ';--- dup' occurs more than once
# RUN: not %extract not_exist %s 2>&1 | FileCheck %s --check-prefix=NOT_EXIST
# NOT_EXIST: extract: error: {{.*}}.test: ';--- not_exist' was not found