diff --git a/CMakeLists.txt b/CMakeLists.txt index da67055..83d7b91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -609,6 +609,15 @@ set(FORTRAN_TESTS_SOURCES_LIST trivial.f90 ) +# Add a smoke test of the fparse-llvm script +add_test(NAME fparse_llvm_smoke_test + COMMAND ${CMAKE_BINARY_DIR}/fparse-llvm -h) +set_tests_properties(fparse_llvm_smoke_test + PROPERTIES + LABELS smoke + PASS_REGULAR_EXPRESSION "Usage" +) + foreach(test_source IN LISTS FORTRAN_TESTS_SOURCES_LIST) add_test(NAME instrument_${test_source} COMMAND ./fparse-llvm ${CMAKE_SOURCE_DIR}/tests/fortran/${test_source} diff --git a/src/fparse-llvm.in b/src/fparse-llvm.in index 5dd07f6..a92fa9a 100755 --- a/src/fparse-llvm.in +++ b/src/fparse-llvm.in @@ -21,6 +21,22 @@ set -o pipefail #set -o verbose #set -o xtrace +# Add a help/usage message function +function usage { + echo "Usage: $0 [-h] [-o output_file] [-show] input_file [args]" + echo " -h: print this help message and exit" + echo " -o output_file: specify the output file name" + echo " -show: print the command line without running it" + echo " input_file: the Fortran source file to parse and instrument" + echo " args: additional arguments to pass to the flang compiler (include flags etc.)" + +} + +if [[ $# -eq 0 ]]; then + usage + exit 1 +fi + # Loop over the arguments and check for the output file -o flag and it's argument # If found, set the output file name to the argument following the -o flag and remove the -o flag and argument from the argument list # If not found, set the output file name to the first argument with a .inst extension @@ -28,8 +44,11 @@ args=() expecting_output_file=false show=false for arg in "$@"; do - echo "working on arg: $arg" - if $expecting_output_file; then + #echo "working on arg: $arg" + if [[ $arg == -h ]]; then + usage + exit 0 + elif $expecting_output_file; then output_file="$arg" expecting_output_file=false shift || true @@ -91,4 +110,5 @@ if $show; then else echo "Running: ${cmd[*]}" "${cmd[@]}" + exit $? fi