forked from OSchip/llvm-project
[FileCheck] Parse command-line options from FILECHECK_OPTS
This feature makes it easy to tune FileCheck diagnostic output when running the test suite via ninja, a bot, or an IDE. For example: ``` $ FILECHECK_OPTS='-color -v -dump-input-on-failure' \ LIT_FILTER='OpenMP/for_codegen.cpp' ninja check-clang \ | less -R ``` Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D53517 llvm-svn: 346272
This commit is contained in:
parent
c3ad28d5e8
commit
24994d77b8
|
@ -24,6 +24,9 @@ match. The file to verify is read from standard input unless the
|
|||
OPTIONS
|
||||
-------
|
||||
|
||||
Options are parsed from the environment variable ``FILECHECK_OPTS``
|
||||
and from the command line.
|
||||
|
||||
.. option:: -help
|
||||
|
||||
Print a summary of command line options.
|
||||
|
|
|
@ -56,9 +56,18 @@ namespace cl {
|
|||
// Returns true on success. Otherwise, this will print the error message to
|
||||
// stderr and exit if \p Errs is not set (nullptr by default), or print the
|
||||
// error message to \p Errs and return false if \p Errs is provided.
|
||||
//
|
||||
// If EnvVar is not nullptr, command-line options are also parsed from the
|
||||
// environment variable named by EnvVar. Precedence is given to occurrences
|
||||
// from argv. This precedence is currently implemented by parsing argv after
|
||||
// the environment variable, so it is only implemented correctly for options
|
||||
// that give precedence to later occurrences. If your program supports options
|
||||
// that give precedence to earlier occurrences, you will need to extend this
|
||||
// function to support it correctly.
|
||||
bool ParseCommandLineOptions(int argc, const char *const *argv,
|
||||
StringRef Overview = "",
|
||||
raw_ostream *Errs = nullptr);
|
||||
raw_ostream *Errs = nullptr,
|
||||
const char *EnvVar = nullptr);
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ParseEnvironmentOptions - Environment variable option processing alternate
|
||||
|
|
|
@ -1061,8 +1061,27 @@ void cl::ParseEnvironmentOptions(const char *progName, const char *envVar,
|
|||
}
|
||||
|
||||
bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
|
||||
StringRef Overview, raw_ostream *Errs) {
|
||||
return GlobalParser->ParseCommandLineOptions(argc, argv, Overview,
|
||||
StringRef Overview, raw_ostream *Errs,
|
||||
const char *EnvVar) {
|
||||
SmallVector<const char *, 20> NewArgv;
|
||||
BumpPtrAllocator A;
|
||||
StringSaver Saver(A);
|
||||
NewArgv.push_back(argv[0]);
|
||||
|
||||
// Parse options from environment variable.
|
||||
if (EnvVar) {
|
||||
if (llvm::Optional<std::string> EnvValue =
|
||||
sys::Process::GetEnv(StringRef(EnvVar)))
|
||||
TokenizeGNUCommandLine(*EnvValue, Saver, NewArgv);
|
||||
}
|
||||
|
||||
// Append options from command line.
|
||||
for (int I = 1; I < argc; ++I)
|
||||
NewArgv.push_back(argv[I]);
|
||||
int NewArgc = static_cast<int>(NewArgv.size());
|
||||
|
||||
// Parse all options.
|
||||
return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
|
||||
Errs);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
; Create a case that produces a simple diagnostic.
|
||||
; RUN: echo foo > %t.in
|
||||
; CHECK: foo
|
||||
; CHECK: bar
|
||||
|
||||
; RUN: FILECHECK_OPTS= \
|
||||
; RUN: not FileCheck %s -input-file %t.in 2>&1 \
|
||||
; RUN: | FileCheck -check-prefix QUIET %s
|
||||
|
||||
; RUN: FILECHECK_OPTS=-v \
|
||||
; RUN: not FileCheck %s -input-file %t.in 2>&1 \
|
||||
; RUN: | FileCheck -check-prefix VERB %s
|
||||
|
||||
; QUIET-NOT: remark: {{CHECK}}: expected string found in input
|
||||
; VERB: remark: {{CHECK}}: expected string found in input
|
|
@ -114,7 +114,8 @@ int main(int argc, char **argv) {
|
|||
llvm::sys::Process::UseANSIEscapeCodes(true);
|
||||
|
||||
InitLLVM X(argc, argv);
|
||||
cl::ParseCommandLineOptions(argc, argv);
|
||||
cl::ParseCommandLineOptions(argc, argv, /*Overview*/ "", /*Errs*/ nullptr,
|
||||
"FILECHECK_OPTS");
|
||||
|
||||
FileCheckRequest Req;
|
||||
for (auto Prefix : CheckPrefixes)
|
||||
|
|
|
@ -26,7 +26,7 @@ class TestingConfig:
|
|||
'LSAN_OPTIONS', 'ADB', 'ANDROID_SERIAL',
|
||||
'SANITIZER_IGNORE_CVE_2016_2143', 'TMPDIR', 'TMP', 'TEMP',
|
||||
'TEMPDIR', 'AVRLIT_BOARD', 'AVRLIT_PORT',
|
||||
'FILECHECK_DUMP_INPUT_ON_FAILURE']
|
||||
'FILECHECK_DUMP_INPUT_ON_FAILURE', 'FILECHECK_OPTS']
|
||||
for var in pass_vars:
|
||||
val = os.environ.get(var, '')
|
||||
# Check for empty string as some variables such as LD_PRELOAD cannot be empty
|
||||
|
|
Loading…
Reference in New Issue