gpsbabel icon indicating copy to clipboard operation
gpsbabel copied to clipboard

feat: Add testsuite validation for option types

Open robertlipe opened this issue 2 months ago • 7 comments

  • feat: Add runtime validation for option types
  • Revert "feat: Add runtime validation for option types"
  • feat: Add runtime validation for option types

robertlipe avatar Oct 07 '25 23:10 robertlipe

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
:white_check_mark: -0.23% :white_check_mark: 21.38%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (fb56e8a75956f43035e107a01456b41436b6deb7) 27512 17189 62.48%
Head commit (72ca40c0c36007cb2086f6311d84f505645dee24) 27652 (+140) 17213 (+24) 62.25% (-0.23%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1473) 145 31 21.38%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

codacy-production[bot] avatar Oct 07 '25 23:10 codacy-production[bot]

BTW the validation is not at startup, but when you run the validate_formats test. ./testo -p bld/gpsbabel validate_formats

tsteven4 avatar Oct 08 '25 01:10 tsteven4

If I take kalman-2, restore options.h and options.cc from main, take out the new check code in vecs.cc so only the original checks exist, and then introduce type mismatches in kalman.h:

-  OptionDouble gap_factor_option_;
+  OptionInt gap_factor_option_;

and

     {"r_scale", &r_scale_option_, "Measurement noise covariance scaling factor",
-      "1.0", ARGTYPE_FLOAT, ARG_NOMINMAX, nullptr
+      "1.0", ARGTYPE_INT, ARG_NOMINMAX, nullptr

the the test shows:

Running validate_formats.test
main: "kalman" OptionInt option without trailing data "gap_factor" is not of ARGTYPE_INT.
main: "kalman" Int option "gap_factor" default value "10.0" is not an integer.
main: "kalman" OptionDouble without trailing data "r_scale" is not of ARGTYPE_FLOAT.
bld/gpsbabel returned error 1

tsteven4 avatar Oct 08 '25 01:10 tsteven4

I see some activity in the kalman-2 branch that shows the kalman options were originally ARGTYPE_STRING instead of ARGTYPE_FLOAT. If I

  1. take the kalman-2 branch and
  2. restore vecs.cc, option.h and option.cc from master,
  3. and change ARGTYPE_FLOAT -> ARGTYPE_STRING in kalman.h to create the mismatches
  4. and run the test the mismatches are detected:
tsteven4@PEDALDAMNIT:~/work/kalman2$ ./testo -p bld/gpsbabel validate_formats
Running validate_formats.test
main: "kalman" OptionDouble without trailing data "gap_factor" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "r_scale" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "q_scale_pos" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "q_scale_vel" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "max_speed" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "interp_max_dt" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "interp_min_multiplier" is not of ARGTYPE_FLOAT.
bld/gpsbabel returned error 1

tsteven4 avatar Oct 08 '25 01:10 tsteven4

I see some activity in the kalman-2 branch that shows the kalman options were originally ARGTYPE_STRING instead of ARGTYPE_FLOAT. If I

  1. take the kalman-2 branch and
  2. restore vecs.cc, option.h and option.cc from master,
  3. and change ARGTYPE_FLOAT -> ARGTYPE_STRING in kalman.h to create the mismatches
  4. and run the test the mismatches are detected:
tsteven4@PEDALDAMNIT:~/work/kalman2$ ./testo -p bld/gpsbabel validate_formats
Running validate_formats.test
main: "kalman" OptionDouble without trailing data "gap_factor" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "r_scale" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "q_scale_pos" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "q_scale_vel" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "max_speed" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "interp_max_dt" is not of ARGTYPE_FLOAT.
main: "kalman" OptionDouble without trailing data "interp_min_multiplier" is not of ARGTYPE_FLOAT.
bld/gpsbabel returned error 1

@robertlipe My conclusion is the original option checking was sufficient to detect the errors you had. I suspect that you assumed the validation ran at startup instead of during the validate_formats test (which also validates the filter arguments).

tsteven4 avatar Oct 08 '25 01:10 tsteven4

@robertlipe note that catching any mismatches at test in CI prevents any mismatches from being merged through a PR, but it doesn't prevent them from confusing a developer who hasn't run the test yet.

tsteven4 avatar Oct 08 '25 01:10 tsteven4

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
:white_check_mark: +0.01% :white_check_mark: 67.86%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (fb56e8a75956f43035e107a01456b41436b6deb7) 27512 17189 62.48%
Head commit (2f540bb7e486ec6ecfaf40399100c85f3a390b21) 55091 (+27579) 34425 (+17236) 62.49% (+0.01%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1473) 28 19 67.86%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

codacy-production[bot] avatar Oct 08 '25 02:10 codacy-production[bot]