@@ -974,6 +974,8 @@ easier for the developer to write, run, and analyze tests.
974974 * Test Fixtures ::
975975 * Multiple Suites in one SRunner ::
976976 * Selective Running of Tests ::
977+ * Selecting Tests by Suite or Test Case ::
978+ * Selecting Tests Based on Arbitrary Tags ::
977979 * Testing Signal Handling and Exit Values ::
978980 * Looping Tests ::
979981 * Test Timeouts ::
@@ -1302,19 +1304,105 @@ srunner_add_suite (sr, make_pack_suite ());
13021304@end example
13031305
13041306@node Selective Running of Tests , Testing Signal Handling and Exit Values , Multiple Suites in one SRunner , Advanced Features
1307+
13051308@section Selective Running of Tests
13061309
1310+ After adding a couple of suites and some test cases in each, it is
1311+ sometimes practical to be able to run only one suite, or one specific
1312+ test case, without recompiling the test code. Check provides two ways
1313+ to accomplish this, either by specifying a suite or test case by name
1314+ or by assigning tags to test cases and specifying one or more tags to
1315+ run.
1316+
1317+ @menu
1318+ * Selecting Tests by Suite or Test Case ::
1319+ * Selecting Tests Based on Arbitrary Tags ::
1320+ @end menu
1321+
1322+ @node Selecting Tests by Suite or Test Case , Selecting Tests Based on Arbitrary Tags , Selective Running of Tests , Selective Running of Tests
1323+ @subsection Selecting Tests by Suite or Test Case
1324+
13071325@vindex CK_RUN_SUITE
13081326@vindex CK_RUN_CASE
1309- After adding a couple of suites and some test cases in each, it is
1310- sometimes practical to be able to run only one suite, or one
1311- specific test case, without recompiling the test code. There are
1312- two environment variables available that offers this ability,
1313- @code {CK_RUN_SUITE } and @code {CK_RUN_CASE }. Just set the value to
1314- the name of the suite and/or test case you want to run. These
1315- environment variables can also be a good integration tool for
1316- running specific tests from within another tool, e.g. an IDE.
1317-
1327+
1328+ There are two environment variables available that offer this
1329+ ability, @code {CK_RUN_SUITE } and @code {CK_RUN_CASE }. Just set the
1330+ value to the name of the suite and/or test case you want to run. These
1331+ environment variables can also be a good integration tool for running
1332+ specific tests from within another tool, e.g. an IDE.
1333+
1334+ @node Selecting Tests Based on Arbitrary Tags , ,Selecting Tests by Suite or Test Case , Selective Running of Tests
1335+ @subsection Selecting Tests Based on Arbitrary Tags
1336+
1337+ @vindex CK_INCLUDE_TAGS
1338+ @vindex CK_EXCLUDE_TAGS
1339+
1340+ It can be useful to dynamically include or exclude groups of tests to
1341+ be run based on criteria other than the suite or test case name. For
1342+ example, one or more tags can be assigned to test cases. The tags
1343+ could indicate if a test runs for a long time, so such tests could be
1344+ excluded in order to run quicker tests for a sanity
1345+ check. Alternately, tags may be used to indicate which functional
1346+ areas test cover. Tests can then be run that include all test cases
1347+ for a given set of functional areas.
1348+
1349+ In Check, a tag is a string of characters without white space. One or
1350+ more tags can be assigned to a test case by using the
1351+ @code {tcase_set_tags } function. This function accepts a string, and
1352+ multiple tags can be specified by delimiting them with spaces. For
1353+ example:
1354+
1355+ @example
1356+ @verbatim
1357+ Suite *s;
1358+
1359+ TCase *red, *blue, *purple, *yellow, *black;
1360+
1361+ s = suite_create("Check Tag Filtering");
1362+
1363+ red = tcase_create("Red");
1364+ tcase_set_tags(red, "Red");
1365+ suite_add_tcase (s, red);
1366+ tcase_add_test(red, red_test1);
1367+
1368+ blue = tcase_create("Blue");
1369+ tcase_set_tags(blue, "Blue");
1370+ suite_add_tcase (s, blue);
1371+ tcase_add_test(blue, blue_test1);
1372+
1373+ purple = tcase_create("Purple");
1374+ tcase_set_tags(purple, "Red Blue");
1375+ suite_add_tcase (s, purple);
1376+ tcase_add_test(purple, purple_test1);
1377+
1378+ @end verbatim
1379+ @end example
1380+
1381+ Once test cases are tagged they may be selectively run in one of two ways:
1382+
1383+ a) Using Environment Variables
1384+
1385+ There are two environment variables available for selecting test cases
1386+ based on tags: @code {CK_INCLUDE_TAGS } and
1387+ @code {CK_EXCLUDE_TAGS }. These can be set to a space separated list of
1388+ tag names. If @code {CK_INCLUDE_TAGS } is set then test cases which
1389+ include at least one tag in common with @code {CK_INCLUDE_TAGS } will be
1390+ run. If @code {CK_EXCLUDE_TAGS } is set then test cases with one tag in
1391+ common with @code {CK_EXCLUDE_TAGS } will not be run. In cases where
1392+ both @code {CK_INCLUDE_TAGS } and @code {CK_EXCLUDE_TAGS } match a tag for
1393+ a test case the test will be excluded.
1394+
1395+ Both @code {CK_INCLUDE_TAGS } and @code {CK_EXCLUDE_TAGS } can be
1396+ specified in conjunction with @code {CK_RUN_SUITE } or even
1397+ @code {CK_RUN_CASE } in which case they will have the effect of further
1398+ narrowing the selection.
1399+
1400+ b) Programmatically
1401+
1402+ The @code {srunner_run_tagged } function allows one to specify which
1403+ tags to run or exclude from a suite runner. This can be used to
1404+ programmatically control which test cases may run.
1405+
13181406@node Testing Signal Handling and Exit Values , Looping Tests , Selective Running of Tests , Advanced Features
13191407@section Testing Signal Handling and Exit Values
13201408
@@ -1975,6 +2063,10 @@ CK_RUN_CASE: Name of a test case, runs only that test. See section @ref{Selectiv
19752063
19762064CK_RUN_SUITE: Name of a test suite, runs only that suite. See section @ref {Selective Running of Tests }.
19772065
2066+ CK_INCLUDE_TAGS: String of space separated tags, runs only test cases associated with at least one of the tags, See section @ref {Selecting Tests Based on Arbitrary Tags }.
2067+
2068+ CK_EXCLUDE_TAGS: String of space separated tags, runs only test cases not associated with any of the tags, See section @ref {Selecting Tests Based on Arbitrary Tags }.
2069+
19782070CK_VERBOSITY: How much output to emit, accepts: ``silent'', ``minimal'', ``normal'', ``subunit'', or ``verbose''. See section @ref {SRunner Output }.
19792071
19802072CK_FORK: Set to ``no'' to disable using fork() to run unit tests in their own process. This is useful for debugging segmentation faults. See section @ref {No Fork Mode }.
0 commit comments