From 213d21fc90b54d8fc304efd4534fa5eb384fb401 Mon Sep 17 00:00:00 2001 From: David Kopriva Date: Wed, 4 Dec 2024 11:25:12 -0800 Subject: [PATCH 1/5] Update HOHQMeshMain.f90 Add help to be printed with the -help option. --- Source/HOHQMeshMain.f90 | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/Source/HOHQMeshMain.f90 b/Source/HOHQMeshMain.f90 index 84ab94ff..3255e795 100644 --- a/Source/HOHQMeshMain.f90 +++ b/Source/HOHQMeshMain.f90 @@ -149,7 +149,6 @@ END PROGRAM HOQMeshMain SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName, path) USE CommandLineReader USE ProgramGlobals - USE, INTRINSIC :: iso_fortran_env, only : stderr => ERROR_UNIT IMPLICIT NONE ! ! --------- @@ -162,13 +161,13 @@ SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName IF ( CommandLineArgumentIsPresent("-version") ) THEN - PRINT *, "HOMesh Version ", version + PRINT *, "HOHQMesh Version ", version STOP END IF IF ( CommandLineArgumentIsPresent("-help") ) THEN - WRITE(stderr,*) "No help available yet. Sorry!" - ERROR STOP "No help available" + CALL PrintHelpMessage() + STOP END IF test = .false. @@ -201,3 +200,33 @@ SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName END IF END SUBROUTINE ReadCommandLineArguments +! +!//////////////////////////////////////////////////////////////////////// +! + SUBROUTINE PrintHelpMessage() + USE, INTRINSIC :: iso_fortran_env, only : OUTPUT_UNIT + IMPLICIT NONE + WRITE(OUTPUT_UNIT,*) "HOHQMesh Help..." + WRITE(OUTPUT_UNIT,*) "Invocation:" + WRITE(OUTPUT_UNIT,*) " ./HOHQMesh [options]" + WRITE(OUTPUT_UNIT,*) "Options:" + WRITE(OUTPUT_UNIT,*) "-help" + WRITE(OUTPUT_UNIT,*) " Prints this message. For the user manual, " + WRITE(OUTPUT_UNIT,*) " see https://trixi-framework.github.io/HOHQMesh/." + WRITE(OUTPUT_UNIT,*) "-version" + WRITE(OUTPUT_UNIT,*) " Prints the current version number of the software." + WRITE(OUTPUT_UNIT,*) "-f " + WRITE(OUTPUT_UNIT,*) " Generates a mesh using the control file ." + WRITE(OUTPUT_UNIT,*) "-verbose" + WRITE(OUTPUT_UNIT,*) " Log the meshing progress to the screen." + WRITE(OUTPUT_UNIT,*) "-test" + WRITE(OUTPUT_UNIT,*) " Runs the test sequence" + WRITE(OUTPUT_UNIT,*) "-path " + WRITE(OUTPUT_UNIT,*) " Use to specify location of the HOHQMesh directory for the test sequence." + WRITE(OUTPUT_UNIT,*) "-sLimit n" + WRITE(OUTPUT_UNIT,*) " Increase the number of subdivisions allowed to 2^n. Default is n = 8." + WRITE(OUTPUT_UNIT,*) "-generateTest" + WRITE(OUTPUT_UNIT,*) " Generates a test mesh using the control file. " + WRITE(OUTPUT_UNIT,*) " See https://trixi-framework.github.io/HOHQMesh/adding-a-new-test/" + + END SUBROUTINE PrintHelpMessage From 13b1cab7d0a482b657272abe0894aea9251a00fb Mon Sep 17 00:00:00 2001 From: David Kopriva Date: Thu, 5 Dec 2024 10:38:05 -0800 Subject: [PATCH 2/5] Modify command line behavior Now accepts -h, -help, --help for help. Prints out help when there is an error in the command line arguments. --- Source/HOHQMeshMain.f90 | 86 +++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/Source/HOHQMeshMain.f90 b/Source/HOHQMeshMain.f90 index 3255e795..e4f5e728 100644 --- a/Source/HOHQMeshMain.f90 +++ b/Source/HOHQMeshMain.f90 @@ -147,6 +147,7 @@ END PROGRAM HOQMeshMain !//////////////////////////////////////////////////////////////////////// ! SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName, path) + USE, INTRINSIC :: iso_fortran_env, only : OUTPUT_UNIT USE CommandLineReader USE ProgramGlobals IMPLICIT NONE @@ -155,10 +156,12 @@ SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName ! Arguments ! --------- ! - CHARACTER(LEN=DEFAULT_CHARACTER_LENGTH) :: controlFileName, path - CHARACTER(LEN=*) :: version - LOGICAL :: test, generateTest + CHARACTER(LEN=DEFAULT_CHARACTER_LENGTH) :: controlFileName, path + CHARACTER(LEN=*) :: version + LOGICAL :: test, generateTest + INTEGER :: argCount + argCount = COMMAND_ARGUMENT_COUNT() IF ( CommandLineArgumentIsPresent("-version") ) THEN PRINT *, "HOHQMesh Version ", version @@ -166,67 +169,94 @@ SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName END IF IF ( CommandLineArgumentIsPresent("-help") ) THEN - CALL PrintHelpMessage() + CALL PrintHelpMessage(OUTPUT_UNIT) + STOP + END IF + + IF ( CommandLineArgumentIsPresent("-h") ) THEN + CALL PrintHelpMessage(OUTPUT_UNIT) + STOP + END IF + + IF ( CommandLineArgumentIsPresent("--help") ) THEN + CALL PrintHelpMessage(OUTPUT_UNIT) STOP END IF test = .false. IF ( CommandLineArgumentIsPresent("-test") ) THEN test = .true. + argCount = argCount - 1 END IF generateTest = .false. IF ( CommandLineArgumentIsPresent("-generateTest") ) THEN generateTest = .true. + argCount = argCount - 1 END IF printMessage = .false. IF ( CommandLineArgumentIsPresent("-verbose") ) THEN printMessage = .true. + argCount = argCount - 1 END IF controlFileName = "none" IF ( CommandLineArgumentIsPresent(argument = "-f") ) THEN controlFileName = StringValueForArgument(argument = "-f") + argCount = argCount - 2 END IF path = "" IF ( CommandLineArgumentIsPresent(argument = "-path") ) THEN path = StringValueForArgument(argument = "-path") + argCount = argCount - 2 END IF IF ( CommandLineArgumentIsPresent(argument = "-sLimit") ) THEN maxLevelLimit = IntegerValueForArgument(argument = "-sLimit") + argCount = argCount - 2 + END IF +! +! --------------------------------------- +! See if there are any uncaught arguments +! --------------------------------------- +! + IF(argCount .ne. 0) THEN + WRITE(OUTPUT_UNIT,*) "Command line argument error" + CALL PrintHelpMessage(OUTPUT_UNIT) + ERROR STOP "Error in command line argument (see `-help` for a list of available options)" END IF END SUBROUTINE ReadCommandLineArguments ! !//////////////////////////////////////////////////////////////////////// ! - SUBROUTINE PrintHelpMessage() - USE, INTRINSIC :: iso_fortran_env, only : OUTPUT_UNIT + SUBROUTINE PrintHelpMessage(iUnit) IMPLICIT NONE - WRITE(OUTPUT_UNIT,*) "HOHQMesh Help..." - WRITE(OUTPUT_UNIT,*) "Invocation:" - WRITE(OUTPUT_UNIT,*) " ./HOHQMesh [options]" - WRITE(OUTPUT_UNIT,*) "Options:" - WRITE(OUTPUT_UNIT,*) "-help" - WRITE(OUTPUT_UNIT,*) " Prints this message. For the user manual, " - WRITE(OUTPUT_UNIT,*) " see https://trixi-framework.github.io/HOHQMesh/." - WRITE(OUTPUT_UNIT,*) "-version" - WRITE(OUTPUT_UNIT,*) " Prints the current version number of the software." - WRITE(OUTPUT_UNIT,*) "-f " - WRITE(OUTPUT_UNIT,*) " Generates a mesh using the control file ." - WRITE(OUTPUT_UNIT,*) "-verbose" - WRITE(OUTPUT_UNIT,*) " Log the meshing progress to the screen." - WRITE(OUTPUT_UNIT,*) "-test" - WRITE(OUTPUT_UNIT,*) " Runs the test sequence" - WRITE(OUTPUT_UNIT,*) "-path " - WRITE(OUTPUT_UNIT,*) " Use to specify location of the HOHQMesh directory for the test sequence." - WRITE(OUTPUT_UNIT,*) "-sLimit n" - WRITE(OUTPUT_UNIT,*) " Increase the number of subdivisions allowed to 2^n. Default is n = 8." - WRITE(OUTPUT_UNIT,*) "-generateTest" - WRITE(OUTPUT_UNIT,*) " Generates a test mesh using the control file. " - WRITE(OUTPUT_UNIT,*) " See https://trixi-framework.github.io/HOHQMesh/adding-a-new-test/" + INTEGER :: iUnit + + WRITE(iUnit,*) "HOHQMesh Help..." + WRITE(iUnit,*) "Invocation:" + WRITE(iUnit,*) " ./HOHQMesh [options]" + WRITE(iUnit,*) "Options:" + WRITE(iUnit,*) "-help or --help or -h" + WRITE(iUnit,*) " Prints this message. For the user manual, " + WRITE(iUnit,*) " see https://trixi-framework.github.io/HOHQMesh/." + WRITE(iUnit,*) "-version" + WRITE(iUnit,*) " Prints the current version number of the software." + WRITE(iUnit,*) "-f " + WRITE(iUnit,*) " Generates a mesh using the control file ." + WRITE(iUnit,*) "-verbose" + WRITE(iUnit,*) " Log the meshing progress to the screen." + WRITE(iUnit,*) "-test" + WRITE(iUnit,*) " Runs the test sequence" + WRITE(iUnit,*) "-path " + WRITE(iUnit,*) " Use to specify location of the HOHQMesh directory for the test sequence." + WRITE(iUnit,*) "-sLimit n" + WRITE(iUnit,*) " Increase the number of subdivisions allowed to 2^n. Default is n = 8." + WRITE(iUnit,*) "-generateTest" + WRITE(iUnit,*) " Generates a test mesh using the control file. " + WRITE(iUnit,*) " See https://trixi-framework.github.io/HOHQMesh/adding-a-new-test/" END SUBROUTINE PrintHelpMessage From e9501b467e1729eaabdb2bd2d07e7827e21c86e5 Mon Sep 17 00:00:00 2001 From: David Kopriva Date: Thu, 5 Dec 2024 13:45:10 -0800 Subject: [PATCH 3/5] UpdateHelp Remove -h option. Add comment that partial command line aregumens are handled. --- Source/Foundation/CommandLineReader.f90 | 2 +- Source/HOHQMeshMain.f90 | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Source/Foundation/CommandLineReader.f90 b/Source/Foundation/CommandLineReader.f90 index 5837878b..b007a35c 100644 --- a/Source/Foundation/CommandLineReader.f90 +++ b/Source/Foundation/CommandLineReader.f90 @@ -123,7 +123,7 @@ LOGICAL FUNCTION CommandLineArgumentIsPresent(argument) substringLength = MIN(argumentLength,LEN_TRIM(argument)) IF ( TRIM(arg) == TRIM(argument) .OR.& - TRIM(arg) == argument(1:substringLength) ) THEN + TRIM(arg) == argument(1:substringLength) ) THEN !Allows partial command CommandLineArgumentIsPresent = .true. lastArgumentID = i RETURN diff --git a/Source/HOHQMeshMain.f90 b/Source/HOHQMeshMain.f90 index e4f5e728..2bf2de9f 100644 --- a/Source/HOHQMeshMain.f90 +++ b/Source/HOHQMeshMain.f90 @@ -173,11 +173,6 @@ SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName STOP END IF - IF ( CommandLineArgumentIsPresent("-h") ) THEN - CALL PrintHelpMessage(OUTPUT_UNIT) - STOP - END IF - IF ( CommandLineArgumentIsPresent("--help") ) THEN CALL PrintHelpMessage(OUTPUT_UNIT) STOP @@ -240,7 +235,7 @@ SUBROUTINE PrintHelpMessage(iUnit) WRITE(iUnit,*) "Invocation:" WRITE(iUnit,*) " ./HOHQMesh [options]" WRITE(iUnit,*) "Options:" - WRITE(iUnit,*) "-help or --help or -h" + WRITE(iUnit,*) "-help or --help" WRITE(iUnit,*) " Prints this message. For the user manual, " WRITE(iUnit,*) " see https://trixi-framework.github.io/HOHQMesh/." WRITE(iUnit,*) "-version" From cbb49a10ef89c626deac234f8afc975e1e25c15f Mon Sep 17 00:00:00 2001 From: David Kopriva Date: Thu, 5 Dec 2024 13:46:18 -0800 Subject: [PATCH 4/5] Update MeshingTests.f90 Add a MiscTests procedure to put in miscellaneous tests from now on. Right now, it calls the PrintHelpMessage procedure to scratch to include covereage. --- Source/Testing/MeshingTests.f90 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/Testing/MeshingTests.f90 b/Source/Testing/MeshingTests.f90 index be265ef1..8fc9280c 100644 --- a/Source/Testing/MeshingTests.f90 +++ b/Source/Testing/MeshingTests.f90 @@ -73,7 +73,7 @@ SUBROUTINE RunTests(pathToTestFiles, numberOfFailedTests) CHARACTER(LEN=DEFAULT_CHARACTER_LENGTH) :: fullPath, path, str INTEGER :: k, fUnit, nControlFiles EXTERNAL :: TestCurves, TestGaussianCurvature - EXTERNAL :: TestBiCubicInterpolation + EXTERNAL :: TestBiCubicInterpolation, MiscTests LOGICAL :: exst CHARACTER(LEN=ERROR_MESSAGE_LENGTH) :: msg ! @@ -92,6 +92,7 @@ SUBROUTINE RunTests(pathToTestFiles, numberOfFailedTests) CALL testSuite % addTestSubroutineWithName(TestCurves,"Curve evaluation tests") CALL testSuite % addTestSubroutineWithName(TestGaussianCurvature,"Gaussian Curvature evaluation tests") CALL testSuite % addTestSubroutineWithName(TestBiCubicInterpolation,"BiCubic Interpolation tests") + CALL testSuite % addTestSubroutineWithName(MiscTests,"Miscellaneous Tests") ! ! -------------------------------- ! Get the list of meshing tests... @@ -396,3 +397,18 @@ SUBROUTINE GatherTestFileData(tData, project, stats) END SUBROUTINE GatherTestFileData END Module MeshingTests +! +!//////////////////////////////////////////////////////////////////////// +! + SUBROUTINE MiscTests + USE TestSuiteManagerClass + USE FTAssertions + IMPLICIT NONE + INTEGER :: iUnit, s + + OPEN(NEWUNIT = iUnit, STATUS='SCRATCH', IOSTAT = s) + CALL FTAssertEqual(expectedValue = 0,actualValue = s,msg = "Scratch file not opening") + CALL PrintHelpMessage(iUnit) + CLOSE(iUnit) + + END SUBROUTINE MiscTests From cddf7f7767cd95552ad918c7479e82b87cf45f41 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Fri, 6 Dec 2024 06:33:56 +0100 Subject: [PATCH 5/5] Improve test coverage --- .github/workflows/ci.yml | 6 +++++- Source/HOHQMeshMain.f90 | 10 ++++++++++ Utilities/createcoverage | 3 +++ Utilities/exercisecommandlineargs | 11 +++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100755 Utilities/exercisecommandlineargs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76ce4a4c..485c4315 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -195,6 +195,10 @@ jobs: if: ${{ matrix.test_type == 'regular' }} run: | ./HOHQMesh -test + - name: Exercise command line arguments + if: ${{ matrix.test_type == 'regular' }} + run: | + ./Utilities/exercisecommandlineargs - name: Run memory checks with Valgrind (only Linux) if: ${{ matrix.os_name == 'linux' && matrix.test_type == 'valgrind' }} run: | @@ -224,4 +228,4 @@ jobs: uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: ./lcov.info \ No newline at end of file + path-to-lcov: ./lcov.info diff --git a/Source/HOHQMeshMain.f90 b/Source/HOHQMeshMain.f90 index 2bf2de9f..3255e86f 100644 --- a/Source/HOHQMeshMain.f90 +++ b/Source/HOHQMeshMain.f90 @@ -162,6 +162,16 @@ SUBROUTINE ReadCommandLineArguments(version, test, generateTest, controlFileName INTEGER :: argCount argCount = COMMAND_ARGUMENT_COUNT() +! +! ------------------------------------------ +! Ensure that there is at least one argument +! ------------------------------------------ +! + IF(argCount .eq. 0) THEN + WRITE(OUTPUT_UNIT,*) "Command line argument error" + CALL PrintHelpMessage(OUTPUT_UNIT) + ERROR STOP "Error in command line argument (see `-help` for a list of available options)" + END IF IF ( CommandLineArgumentIsPresent("-version") ) THEN PRINT *, "HOHQMesh Version ", version diff --git a/Utilities/createcoverage b/Utilities/createcoverage index 2eddef0d..437f87d0 100755 --- a/Utilities/createcoverage +++ b/Utilities/createcoverage @@ -15,5 +15,8 @@ lcov --directory . --exclude '*/FTObjectLibrary/*' --zerocounters # Run tests ./HOHQMesh -test +# Exercise command line arguments +./Utilities/exercisecommandlineargs + # Process coverage lcov --directory . --exclude '*/FTObjectLibrary/*' --capture --output-file lcov.info diff --git a/Utilities/exercisecommandlineargs b/Utilities/exercisecommandlineargs new file mode 100755 index 00000000..eb02407b --- /dev/null +++ b/Utilities/exercisecommandlineargs @@ -0,0 +1,11 @@ +#!/bin/bash + +# Fail fast and verbosely +set -eox pipefail + +./HOHQMesh -version +./HOHQMesh --help +./HOHQMesh -help +./HOHQMesh -verbose -f Examples/2D/GingerbreadMan/GingerbreadMan.control -sLimit 8 +./HOHQMesh || true # will fail +./HOHQMesh -this-does-not-exist || true # will fail