Index: llvm/test/tools/llvm-reduce/command-line-behavior.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-reduce/command-line-behavior.test @@ -0,0 +1,12 @@ +# Print the help output if no arguments are specified +# RUN: llvm-reduce --help | grep "LLVM automatic testcase reducer" +# RUN: llvm-reduce | grep "LLVM automatic testcase reducer" + +# Don't require any other arguments for --print-delta-passes +# RUN: llvm-reduce --print-delta-passes | grep "Delta passes (pass to \`--delta-passes=\` as a comma separated list)" + +# Missing test input +# RUN: not llvm-reduce --test FileCheck 2>&1 | grep "error: reduction testcase positional argument must be specified" + +# Missing test script +# RUN: not llvm-reduce some-input 2>&1 | grep "error: --test option must be specified" Index: llvm/tools/llvm-reduce/llvm-reduce.cpp =================================================================== --- llvm/tools/llvm-reduce/llvm-reduce.cpp +++ llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -45,18 +45,19 @@ "debugging (crash reports, llvm-symbolizer and core dumps)"), cl::cat(LLVMReduceOptions)); +// FIXME: should be able to do this without other arguments, also add in help. static cl::opt PrintDeltaPasses("print-delta-passes", cl::desc("Print list of delta passes, passable to " "--delta-passes as a comma separated list"), cl::cat(LLVMReduceOptions)); -static cl::opt InputFilename(cl::Positional, cl::Required, +static cl::opt InputFilename(cl::Positional, cl::desc(""), cl::cat(LLVMReduceOptions)); static cl::opt - TestFilename("test", cl::Required, + TestFilename("test", cl::desc("Name of the interesting-ness test to be run"), cl::cat(LLVMReduceOptions)); @@ -157,10 +158,21 @@ int main(int Argc, char **Argv) { InitLLVM X(Argc, Argv); + const StringRef ToolName(Argv[0]); cl::HideUnrelatedOptions({&LLVMReduceOptions, &getColorCategory()}); cl::ParseCommandLineOptions(Argc, Argv, "LLVM automatic testcase reducer.\n"); + if (Argc == 1) { + cl::PrintHelpMessage(); + return 0; + } + + if (PrintDeltaPasses) { + printDeltaPasses(outs()); + return 0; + } + bool ReduceModeMIR = false; if (InputLanguage != InputLanguages::None) { if (InputLanguage == InputLanguages::MIR) @@ -169,9 +181,15 @@ ReduceModeMIR = true; } - if (PrintDeltaPasses) { - printDeltaPasses(errs()); - return 0; + if (InputFilename.empty()) { + WithColor::error(errs(), ToolName) + << "reduction testcase positional argument must be specified\n"; + return 1; + } + + if (TestFilename.empty()) { + WithColor::error(errs(), ToolName) << "--test option must be specified\n"; + return 1; } if (!PreserveDebugEnvironment) @@ -181,7 +199,7 @@ std::unique_ptr TM; auto [OriginalProgram, InputIsBitcode] = - parseReducerWorkItem(Argv[0], InputFilename, Context, TM, ReduceModeMIR); + parseReducerWorkItem(ToolName, InputFilename, Context, TM, ReduceModeMIR); if (!OriginalProgram) { return 1; } @@ -193,7 +211,7 @@ // Initialize test environment TestRunner Tester(TestFilename, TestArguments, std::move(OriginalProgram), - std::move(TM), Argv[0], OutputFilename, InputIsBitcode, + std::move(TM), ToolName, OutputFilename, InputIsBitcode, OutputBitcode); // This parses and writes out the testcase into a temporary file copy for the