llvm.org GIT mirror llvm / e861874
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346272 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny 11 months ago
6 changed file(s) with 52 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2222
2323 OPTIONS
2424 -------
25
26 Options are parsed from the environment variable ``FILECHECK_OPTS``
27 and from the command line.
2528
2629 .. option:: -help
2730
5555 // Returns true on success. Otherwise, this will print the error message to
5656 // stderr and exit if \p Errs is not set (nullptr by default), or print the
5757 // error message to \p Errs and return false if \p Errs is provided.
58 //
59 // If EnvVar is not nullptr, command-line options are also parsed from the
60 // environment variable named by EnvVar. Precedence is given to occurrences
61 // from argv. This precedence is currently implemented by parsing argv after
62 // the environment variable, so it is only implemented correctly for options
63 // that give precedence to later occurrences. If your program supports options
64 // that give precedence to earlier occurrences, you will need to extend this
65 // function to support it correctly.
5866 bool ParseCommandLineOptions(int argc, const char *const *argv,
5967 StringRef Overview = "",
60 raw_ostream *Errs = nullptr);
68 raw_ostream *Errs = nullptr,
69 const char *EnvVar = nullptr);
6170
6271 //===----------------------------------------------------------------------===//
6372 // ParseEnvironmentOptions - Environment variable option processing alternate
10601060 }
10611061
10621062 bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
1063 StringRef Overview, raw_ostream *Errs) {
1064 return GlobalParser->ParseCommandLineOptions(argc, argv, Overview,
1063 StringRef Overview, raw_ostream *Errs,
1064 const char *EnvVar) {
1065 SmallVector NewArgv;
1066 BumpPtrAllocator A;
1067 StringSaver Saver(A);
1068 NewArgv.push_back(argv[0]);
1069
1070 // Parse options from environment variable.
1071 if (EnvVar) {
1072 if (llvm::Optional EnvValue =
1073 sys::Process::GetEnv(StringRef(EnvVar)))
1074 TokenizeGNUCommandLine(*EnvValue, Saver, NewArgv);
1075 }
1076
1077 // Append options from command line.
1078 for (int I = 1; I < argc; ++I)
1079 NewArgv.push_back(argv[I]);
1080 int NewArgc = static_cast(NewArgv.size());
1081
1082 // Parse all options.
1083 return GlobalParser->ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
10651084 Errs);
10661085 }
10671086
0 ; Create a case that produces a simple diagnostic.
1 ; RUN: echo foo > %t.in
2 ; CHECK: foo
3 ; CHECK: bar
4
5 ; RUN: FILECHECK_OPTS= \
6 ; RUN: not FileCheck %s -input-file %t.in 2>&1 \
7 ; RUN: | FileCheck -check-prefix QUIET %s
8
9 ; RUN: FILECHECK_OPTS=-v \
10 ; RUN: not FileCheck %s -input-file %t.in 2>&1 \
11 ; RUN: | FileCheck -check-prefix VERB %s
12
13 ; QUIET-NOT: remark: {{CHECK}}: expected string found in input
14 ; VERB: remark: {{CHECK}}: expected string found in input
113113 llvm::sys::Process::UseANSIEscapeCodes(true);
114114
115115 InitLLVM X(argc, argv);
116 cl::ParseCommandLineOptions(argc, argv);
116 cl::ParseCommandLineOptions(argc, argv, /*Overview*/ "", /*Errs*/ nullptr,
117 "FILECHECK_OPTS");
117118
118119 FileCheckRequest Req;
119120 for (auto Prefix : CheckPrefixes)
2525 'LSAN_OPTIONS', 'ADB', 'ANDROID_SERIAL',
2626 'SANITIZER_IGNORE_CVE_2016_2143', 'TMPDIR', 'TMP', 'TEMP',
2727 'TEMPDIR', 'AVRLIT_BOARD', 'AVRLIT_PORT',
28 'FILECHECK_DUMP_INPUT_ON_FAILURE']
28 'FILECHECK_DUMP_INPUT_ON_FAILURE', 'FILECHECK_OPTS']
2929 for var in pass_vars:
3030 val = os.environ.get(var, '')
3131 # Check for empty string as some variables such as LD_PRELOAD cannot be empty