diff --git a/examples/example_2/src/ProductionCode.c b/examples/example_2/src/ProductionCode.c index 500b44b..3bafe20 100644 --- a/examples/example_2/src/ProductionCode.c +++ b/examples/example_2/src/ProductionCode.c @@ -11,7 +11,7 @@ int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; //some obnoxious a int FindFunction_WhichIsBroken(int NumberToFind) { int i = 0; - while (i <= 8) //Notice I should have been in braces + while (i < 8) //Notice I should have been in braces i++; if (NumbersToFind[i] == NumberToFind) //Yikes! I'm getting run after the loop finishes instead of during it! return i; diff --git a/examples/example_3/src/ProductionCode.c b/examples/example_3/src/ProductionCode.c index 500b44b..3bafe20 100644 --- a/examples/example_3/src/ProductionCode.c +++ b/examples/example_3/src/ProductionCode.c @@ -11,7 +11,7 @@ int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; //some obnoxious a int FindFunction_WhichIsBroken(int NumberToFind) { int i = 0; - while (i <= 8) //Notice I should have been in braces + while (i < 8) //Notice I should have been in braces i++; if (NumbersToFind[i] == NumberToFind) //Yikes! I'm getting run after the loop finishes instead of during it! return i; diff --git a/extras/fixture/readme.md b/extras/fixture/readme.md index 38a3132..2e0c2f0 100644 --- a/extras/fixture/readme.md +++ b/extras/fixture/readme.md @@ -15,3 +15,15 @@ Fixtures, by default, uses the Memory addon as well. This is to make it simple f follow along with James' book. Using them together is completely optional. You may choose to use Fixtures without Memory handling by defining `UNITY_FIXTURE_NO_EXTRAS`. It will then stop automatically pulling in extras and leave you to do it as desired. + +# Usage information + +By default the test executables produced by Unity Fixtures run all tests once, but the behavior can +be configured with command-line flags. Run the test executable with the `--help` flag for more +information. + +It's possible to add a custom line at the end of the help message, typically to point to +project-specific or company-specific unit test documentation. Define `UNITY_CUSTOM_HELP_MSG` to +provide a custom message, e.g.: + + #define UNITY_CUSTOM_HELP_MSG "If any test fails see https://example.com/troubleshooting" diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 3b66a6d..c3dda79 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -192,7 +192,42 @@ int UnityGetCommandLineOptions(int argc, const char* argv[]) for (i = 1; i < argc; ) { - if (strcmp(argv[i], "-v") == 0) + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) + { + /* Usage */ + UnityPrint("Runs a series of unit tests."); + UNITY_PRINT_EOL(); + UNITY_PRINT_EOL(); + UnityPrint("When no flag is specified, all tests are run."); + UNITY_PRINT_EOL(); + UNITY_PRINT_EOL(); + UnityPrint("Optional flags:"); + UNITY_PRINT_EOL(); + UnityPrint(" -v Verbose output: show all tests executed even if they pass"); + UNITY_PRINT_EOL(); + UnityPrint(" -s Silent mode: minimal output showing only test failures"); + UNITY_PRINT_EOL(); + UnityPrint(" -g NAME Only run tests in groups that contain the string NAME"); + UNITY_PRINT_EOL(); + UnityPrint(" -n NAME Only run tests whose name contains the string NAME"); + UNITY_PRINT_EOL(); + UnityPrint(" -r NUMBER Repeatedly run all tests NUMBER times"); + UNITY_PRINT_EOL(); + UnityPrint(" -h, --help Display this help message"); + UNITY_PRINT_EOL(); + UNITY_PRINT_EOL(); +#ifdef UNITY_CUSTOM_HELP_MSG + /* User-defined help message, e.g. to point to project-specific documentation */ + UnityPrint(UNITY_CUSTOM_HELP_MSG); + UNITY_PRINT_EOL(); +#else + /* Default help suffix if a custom one is not defined */ + UnityPrint("More information about Unity: https://www.throwtheswitch.org/unity"); + UNITY_PRINT_EOL(); +#endif + return 1; /* Exit without running the tests */ + } + else if (strcmp(argv[i], "-v") == 0) { UnityFixture.Verbose = 1; i++;