@@ -274,6 +274,33 @@ TEST(test_model_marks_what_is_under_a_condition) {
274274 PASS ();
275275}
276276
277+ /* A runner registration under a condition means some builds lack the suite.
278+ * A suite registered twice is conditional only when every site is. */
279+ TEST (test_model_marks_runner_suites_registered_under_a_condition ) {
280+ static const tm_source_t src [] = {{"tests/test_main.c" , "int main(void) {\n"
281+ " RUN_SELECTED_SUITE(always);\n"
282+ "#if defined(COV) && !defined(_WIN32)\n"
283+ " RUN_SELECTED_SUITE(guarded);\n"
284+ " RUN_SELECTED_SUITE(twice);\n"
285+ "#endif\n"
286+ " RUN_SELECTED_SUITE(twice);\n"
287+ " return 0;\n"
288+ "}\n" }};
289+ cbm_test_model_t * m = model_of (src , 1 );
290+ ASSERT_NOT_NULL (m );
291+ int n = 0 ;
292+ const cbm_test_runner_suite_t * suites = cbm_test_model_runner_suites (m , & n );
293+ ASSERT_EQ (n , 3 );
294+ ASSERT_STR_EQ (suites [0 ].name , "always" );
295+ ASSERT_FALSE (suites [0 ].conditional );
296+ ASSERT_STR_EQ (suites [1 ].name , "guarded" );
297+ ASSERT_TRUE (suites [1 ].conditional );
298+ ASSERT_STR_EQ (suites [2 ].name , "twice" );
299+ ASSERT_FALSE (suites [2 ].conditional );
300+ cbm_test_model_free (m );
301+ PASS ();
302+ }
303+
277304/* Both branches of an #if may open the same block. Counting both braces would
278305 * leave the scanner one level deep for the rest of the file, and every later
279306 * test and suite would be missed. */
@@ -1688,6 +1715,92 @@ TEST(test_selection_inventory_ambiguity_and_conditionals_use_whole_suite) {
16881715 PASS ();
16891716}
16901717
1718+ /* A suite the runner registers only under a preprocessor condition is absent
1719+ * from some builds, so however it is selected it must carry CONDITIONAL: the
1720+ * runner that lacks it then tolerates its absence. Its cases and registrations
1721+ * are unconditional here, so only the runner registration can say so. */
1722+ TEST (test_selection_conditionally_registered_suite_is_conditional_on_every_path ) {
1723+ /* A map covers every function it lists, so the changed one (0) is covered
1724+ * by the setup of a suite no runner registers: alpha's own rows stay
1725+ * quiet and each variant reaches alpha by its one path. */
1726+ static const char * quiet_rows = "alpha:*\tcomplete\t\t1\nalpha:stat\tcomplete\t\t1\n"
1727+ "alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\n"
1728+ "alpha:quiet\tcomplete\t\t1\nomega:*\tcomplete\t\t0\n" ;
1729+ struct {
1730+ const char * rows ;
1731+ bool admitted ;
1732+ bool reached , changed , rule ;
1733+ unsigned path ;
1734+ } variants [] = {
1735+ {"alpha:*\tincomplete\tlost setup\t1\nalpha:stat\tcomplete\t\t1\n"
1736+ "alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n"
1737+ "omega:*\tcomplete\t\t0\n" ,
1738+ true, false, false, false, CBM_TEST_SELECT_SETUP_UNKNOWN },
1739+ {"alpha:*\tcomplete\t\t0\nalpha:stat\tcomplete\t\t1\n"
1740+ "alpha:cov\tcomplete\t\t1\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n" ,
1741+ true, false, false, false, CBM_TEST_SELECT_SETUP_HIT },
1742+ {quiet_rows , true, true, false, false, CBM_TEST_SELECT_STATIC },
1743+ {quiet_rows , true, false, true, false, CBM_TEST_SELECT_CHANGED },
1744+ {quiet_rows , true, false, false, true, CBM_TEST_SELECT_RULE },
1745+ {quiet_rows , false, false, false, false, CBM_TEST_SELECT_ARTIFACT_REJECTED },
1746+ /* One covered case alone would otherwise name `alpha:cov`. */
1747+ {"alpha:*\tcomplete\t\t1\nalpha:stat\tcomplete\t\t1\n"
1748+ "alpha:cov\tcomplete\t\t0\nalpha:changed\tcomplete\t\t1\nalpha:quiet\tcomplete\t\t1\n" ,
1749+ true, false, false, false, CBM_TEST_SELECT_COVERAGE },
1750+ };
1751+ const char * runners [] = {
1752+ "void main(void) {\n#if defined(FEATURE) && !defined(_WIN32)\nRUN_SELECTED_SUITE(alpha);\n"
1753+ "#endif\n}\n" ,
1754+ "void main(void) { RUN_SELECTED_SUITE(alpha); }\n" ,
1755+ };
1756+ for (int r = 0 ; r < 2 ; r ++ ) {
1757+ char source [1024 ];
1758+ snprintf (source , sizeof (source ),
1759+ "TEST(stat) {}\nTEST(cov) {}\nTEST(changed) {}\nTEST(quiet) {}\n"
1760+ "SUITE(alpha) { RUN_TEST(stat); RUN_TEST(cov); RUN_TEST(changed); "
1761+ "RUN_TEST(quiet); }\n%s" ,
1762+ runners [r ]);
1763+ cbm_test_model_t * model = selection_model (source );
1764+ ASSERT_NOT_NULL (model );
1765+ for (int i = 0 ; i < (int )(sizeof (variants ) / sizeof (variants [0 ])); i ++ ) {
1766+ cbm_coverage_map_t * map = selection_map (variants [i ].rows );
1767+ ASSERT_NOT_NULL (map );
1768+ cbm_test_reach_t reach [] = SELECTION_REACH ;
1769+ for (int k = 0 ; k < 4 ; k ++ )
1770+ reach [k ].reached = reach [k ].changed = false;
1771+ int changed [] = {0 };
1772+ cbm_test_suite_trigger_t trigger = {.suite = "alpha" ,
1773+ .reached = variants [i ].reached ,
1774+ .changed = variants [i ].changed ,
1775+ .rule = variants [i ].rule };
1776+ cbm_test_selection_input_t input = selection_input (model , map , reach , changed );
1777+ input .coverage_admitted = variants [i ].admitted ;
1778+ input .suite_triggers = & trigger ;
1779+ input .suite_trigger_count = 1 ;
1780+ cbm_test_selection_t * result = cbm_test_select (& input );
1781+ ASSERT_NOT_NULL (result );
1782+ ASSERT_EQ (cbm_test_selection_run_all (result ), 0 );
1783+ int count ;
1784+ const cbm_test_selected_suite_t * suites = cbm_test_selection_suites (result , & count );
1785+ ASSERT_EQ (count , 1 );
1786+ ASSERT_TRUE (suites [0 ].reasons & variants [i ].path );
1787+ if (r == 0 ) {
1788+ ASSERT_TRUE (suites [0 ].whole );
1789+ ASSERT_TRUE (suites [0 ].reasons & CBM_TEST_SELECT_CONDITIONAL );
1790+ cbm_test_selection_cases (result , & count );
1791+ ASSERT_EQ (count , 0 );
1792+ } else {
1793+ /* Registered in every build: the strict contract stays. */
1794+ ASSERT_FALSE (suites [0 ].reasons & CBM_TEST_SELECT_CONDITIONAL );
1795+ }
1796+ cbm_test_selection_free (result );
1797+ cbm_coverage_map_free (map );
1798+ }
1799+ cbm_test_model_free (model );
1800+ }
1801+ PASS ();
1802+ }
1803+
16911804/* Uncertainty is scoped to the file it was found in. A file the model cannot
16921805 * read with certainty, but which defines its own suite, makes that suite
16931806 * uncertain (it can only run whole) and leaves every other suite narrowable.
@@ -3804,6 +3917,7 @@ SUITE(test_impact) {
38043917 RUN_TEST (test_selection_setup_and_rejected_artifacts_select_whole_suites );
38053918 RUN_TEST (test_selection_incomplete_global_evidence_never_narrows );
38063919 RUN_TEST (test_selection_inventory_ambiguity_and_conditionals_use_whole_suite );
3920+ RUN_TEST (test_selection_conditionally_registered_suite_is_conditional_on_every_path );
38073921 RUN_TEST (test_model_uncertainty_is_scoped_to_the_suites_of_its_file );
38083922 RUN_TEST (test_model_only_code_continuations_are_uncertain );
38093923 RUN_TEST (test_selection_scoped_uncertainty_runs_only_its_suite_whole );
@@ -3834,6 +3948,7 @@ SUITE(test_impact) {
38343948 RUN_TEST (test_model_ignores_comments_and_literals );
38353949 RUN_TEST (test_model_reads_suites_written_as_functions );
38363950 RUN_TEST (test_model_marks_what_is_under_a_condition );
3951+ RUN_TEST (test_model_marks_runner_suites_registered_under_a_condition );
38373952 RUN_TEST (test_model_keeps_brace_depth_across_else_branches );
38383953 RUN_TEST (test_model_resolves_registrations_in_their_own_file );
38393954 RUN_TEST (test_model_marks_suites_that_register_through_a_macro );
0 commit comments