diff --git a/llvm/test/tools/yaml2obj/help.test b/llvm/test/tools/yaml2obj/help.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/yaml2obj/help.test @@ -0,0 +1,13 @@ +## Show that help text is printed correctly when requested. + +RUN: yaml2obj -h | FileCheck %s --check-prefixes=CHECK,CATEG +RUN: yaml2obj --help | FileCheck %s --check-prefixes=CHECK,CATEG +RUN: yaml2obj --help-list | FileCheck %s --check-prefixes=CHECK,LIST + +CHECK: OVERVIEW: Create an object file from YAML description +CHECK: USAGE: yaml2obj{{(.exe)?}} [options] {{$}} +CHECK: OPTIONS: +CATEG: Generic Options: +LIST-NOT: Generic Options: +CATEG: yaml2obj Options: +LIST-NOT: yaml2obj Options: diff --git a/llvm/test/tools/yaml2obj/invalid-output-file.yaml b/llvm/test/tools/yaml2obj/output-file.yaml rename from llvm/test/tools/yaml2obj/invalid-output-file.yaml rename to llvm/test/tools/yaml2obj/output-file.yaml --- a/llvm/test/tools/yaml2obj/invalid-output-file.yaml +++ b/llvm/test/tools/yaml2obj/output-file.yaml @@ -2,3 +2,17 @@ ## Don't check the OS-dependent message "No such file or directory". # CHECK: yaml2obj: error: failed to open '{{.*}}/path/does/not/exist': {{.*}} + +# RUN: rm -f %t +# RUN: yaml2obj %s -o %t +# RUN: ls %t +# RUN: rm -f %t +# RUN: yaml2obj %s -o%t +# RUN: ls %t + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_NONE diff --git a/llvm/tools/yaml2obj/yaml2obj.cpp b/llvm/tools/yaml2obj/yaml2obj.cpp --- a/llvm/tools/yaml2obj/yaml2obj.cpp +++ b/llvm/tools/yaml2obj/yaml2obj.cpp @@ -28,22 +28,28 @@ using namespace llvm; -static cl::opt - Input(cl::Positional, cl::desc(""), cl::init("-")); +namespace { +cl::OptionCategory Cat("yaml2obj Options"); -static cl::opt +cl::opt Input(cl::Positional, cl::desc(""), + cl::init("-"), cl::cat(Cat)); + +cl::opt DocNum("docnum", cl::init(1), - cl::desc("Read specified document from input (default = 1)")); + cl::desc("Read specified document from input (default = 1)"), + cl::cat(Cat)); -static cl::opt OutputFilename("o", cl::desc("Output filename"), - cl::value_desc("filename")); +cl::opt OutputFilename("o", cl::desc("Output filename"), + cl::value_desc("filename"), cl::init("-"), + cl::Prefix, cl::cat(Cat)); +} // namespace int main(int argc, char **argv) { InitLLVM X(argc, argv); - cl::ParseCommandLineOptions(argc, argv); - - if (OutputFilename.empty()) - OutputFilename = "-"; + cl::HideUnrelatedOptions(Cat); + cl::ParseCommandLineOptions( + argc, argv, "Create an object file from YAML description", nullptr, + nullptr, /*LongOptionsUseDoubleDash=*/true); auto ErrHandler = [](const Twine &Msg) { WithColor::error(errs(), "yaml2obj") << Msg << "\n";