ceedling 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/GIT_COMMIT_SHA +1 -1
- data/README.md +1 -1
- data/assets/fixtures/tests_with_partials_coverage/src/private_macro.c +7 -0
- data/assets/fixtures/tests_with_partials_coverage/src/private_macro.h +5 -0
- data/assets/fixtures/tests_with_partials_coverage/src/tally.c +13 -0
- data/assets/fixtures/tests_with_partials_coverage/src/tally.h +4 -0
- data/assets/fixtures/tests_with_partials_coverage/test/test_private_macro.c +10 -0
- data/assets/fixtures/tests_with_partials_coverage/test/test_tally.c +9 -0
- data/docs/BreakingChanges.md +16 -0
- data/docs/Changelog.md +71 -0
- data/docs/KnownIssues.md +91 -4
- data/examples/wondrous_forest/README.md +29 -1
- data/examples/wondrous_forest/src/ForestUnits.h +23 -0
- data/examples/wondrous_forest/src/RainGauge.c +59 -0
- data/examples/wondrous_forest/src/RainGauge.h +39 -0
- data/examples/wondrous_forest/src/RainTipIsr.c +17 -0
- data/examples/wondrous_forest/src/RainTipIsr.h +14 -0
- data/examples/wondrous_forest/test/TestRainGauge.c +126 -0
- data/lib/ceedling/c_extractor/README.md +15 -7
- data/lib/ceedling/c_extractor/c_extractor.rb +25 -14
- data/lib/ceedling/c_extractor/c_extractor_code_text.rb +84 -54
- data/lib/ceedling/c_extractor/c_extractor_constants.rb +18 -7
- data/lib/ceedling/c_extractor/c_extractor_declarations.rb +319 -283
- data/lib/ceedling/c_extractor/c_extractor_declarator.rb +285 -0
- data/lib/ceedling/c_extractor/c_extractor_defined_type.rb +111 -0
- data/lib/ceedling/c_extractor/c_extractor_definitions.rb +174 -121
- data/lib/ceedling/c_extractor/c_extractor_functions.rb +191 -162
- data/lib/ceedling/c_extractor/c_extractor_preprocessing.rb +46 -55
- data/lib/ceedling/c_extractor/c_extractor_statement.rb +30 -0
- data/lib/ceedling/c_extractor/c_extractor_types.rb +63 -41
- data/lib/ceedling/c_extractor/c_module_edits.rb +48 -0
- data/lib/ceedling/c_identifier.rb +21 -0
- data/lib/ceedling/ceedling.h +8 -0
- data/lib/ceedling/config/configurator.rb +4 -3
- data/lib/ceedling/config/configurator_builder.rb +17 -0
- data/lib/ceedling/config/configurator_setup.rb +29 -5
- data/lib/ceedling/constants.rb +5 -1
- data/lib/ceedling/defaults.rb +31 -1
- data/lib/ceedling/dependencies/CACHE_SCHEMA.md +118 -0
- data/lib/ceedling/dependencies/README.md +1 -1
- data/lib/ceedling/dependencies/dependency_cache_store.rb +30 -25
- data/lib/ceedling/dependencies/dependency_tracker.rb +9 -3
- data/lib/ceedling/dependencies/dependinator.rb +13 -1
- data/lib/ceedling/diagnostics/DOCTOR.md +142 -0
- data/lib/ceedling/diagnostics/README.md +5 -0
- data/lib/ceedling/diagnostics/build_step_doctor.rb +110 -0
- data/lib/ceedling/diagnostics/duplicate_symbol_specialist.rb +108 -0
- data/lib/ceedling/diagnostics/guidance_phrases.rb +30 -0
- data/lib/ceedling/diagnostics/header_collision_guidance.rb +56 -0
- data/lib/ceedling/diagnostics/header_collision_specialist.rb +152 -0
- data/lib/ceedling/diagnostics/include_depth_specialist.rb +132 -0
- data/lib/ceedling/diagnostics/missing_symbol_specialist.rb +111 -0
- data/lib/ceedling/diagnostics/partial_name_specialist.rb +134 -0
- data/lib/ceedling/diagnostics/toolchain_output.rb +44 -0
- data/lib/ceedling/filesystem/PATH_HANDLING.md +83 -27
- data/lib/ceedling/filesystem/README.md +6 -1
- data/lib/ceedling/filesystem/build_roots.rb +105 -0
- data/lib/ceedling/filesystem/build_subpath.rb +110 -25
- data/lib/ceedling/filesystem/file_finder.rb +76 -110
- data/lib/ceedling/filesystem/file_finder_helper.rb +33 -11
- data/lib/ceedling/filesystem/file_path_utils.rb +113 -91
- data/lib/ceedling/filesystem/file_wrapper.rb +105 -28
- data/lib/ceedling/filesystem/path_matcher.rb +21 -0
- data/lib/ceedling/filesystem/test_build_layout.rb +114 -0
- data/lib/ceedling/filesystem/win_long_paths.rb +153 -0
- data/lib/ceedling/filesystem/win_path_limit.rb +83 -0
- data/lib/ceedling/filesystem/win_path_prober.rb +52 -0
- data/lib/ceedling/generators/generator.rb +27 -64
- data/lib/ceedling/generators/generator_helper.rb +0 -44
- data/lib/ceedling/generators/generator_mocks.rb +5 -0
- data/lib/ceedling/generators/generator_partials.rb +305 -243
- data/lib/ceedling/generators/generator_test_runner.rb +5 -8
- data/lib/ceedling/generators/partial_header_writer.rb +95 -0
- data/lib/ceedling/generators/partial_source_writer.rb +137 -0
- data/lib/ceedling/includes/header_search.rb +225 -0
- data/lib/ceedling/includes/include_factory.rb +9 -12
- data/lib/ceedling/includes/include_pathinator.rb +53 -31
- data/lib/ceedling/includes/includes.rb +149 -37
- data/lib/ceedling/objects.yml +89 -4
- data/lib/ceedling/partials/README.md +110 -16
- data/lib/ceedling/partials/carry_plan.rb +71 -0
- data/lib/ceedling/partials/definition_head.rb +74 -0
- data/lib/ceedling/partials/include_groups.rb +37 -0
- data/lib/ceedling/partials/interface_extras.rb +25 -0
- data/lib/ceedling/partials/partializer.rb +599 -120
- data/lib/ceedling/partials/partializer_config.rb +5 -0
- data/lib/ceedling/partials/partializer_helper.rb +851 -145
- data/lib/ceedling/partials/partializer_reconciler.rb +174 -0
- data/lib/ceedling/partials/partializer_utils.rb +89 -109
- data/lib/ceedling/partials/partials.rb +153 -10
- data/lib/ceedling/partials/type_macros.rb +126 -0
- data/lib/ceedling/preprocess/README.md +43 -33
- data/lib/ceedling/preprocess/preprocessinator.rb +100 -186
- data/lib/ceedling/preprocess/preprocessinator_code_finder.rb +65 -72
- data/lib/ceedling/preprocess/preprocessinator_file_assembler.rb +31 -75
- data/lib/ceedling/preprocess/preprocessinator_reconstructor.rb +51 -14
- data/lib/ceedling/setupinator.rb +16 -3
- data/lib/ceedling/test_invoker/HEADER_COLLISIONS.md +21 -7
- data/lib/ceedling/test_invoker/PIPELINE.md +57 -16
- data/lib/ceedling/test_invoker/README.md +1 -1
- data/lib/ceedling/test_invoker/derived_search_path_notices.rb +45 -0
- data/lib/ceedling/test_invoker/mock_locator.rb +116 -9
- data/lib/ceedling/test_invoker/partial_files_preprocessinator.rb +181 -0
- data/lib/ceedling/test_invoker/partials_manager.rb +265 -308
- data/lib/ceedling/test_invoker/standin_headerinator.rb +8 -15
- data/lib/ceedling/test_invoker/test_bare_includes_extractinator.rb +26 -3
- data/lib/ceedling/test_invoker/test_build_executor.rb +338 -198
- data/lib/ceedling/test_invoker/test_build_planner.rb +13 -19
- data/lib/ceedling/test_invoker/test_build_setup.rb +26 -6
- data/lib/ceedling/test_invoker/test_build_validations.rb +23 -20
- data/lib/ceedling/test_invoker/test_derived_search_paths.rb +189 -0
- data/lib/ceedling/test_invoker/test_file_preprocessinator.rb +1 -2
- data/lib/ceedling/test_invoker/test_includes_reconcilinator.rb +1 -1
- data/lib/ceedling/test_invoker/test_invoker_types.rb +28 -20
- data/lib/ceedling/test_invoker/test_pipeline_helpers.rb +5 -3
- data/lib/ceedling/test_invoker/test_pipeline_manager.rb +25 -8
- data/lib/ceedling/test_invoker/test_runner_generatinator.rb +31 -3
- data/lib/ceedling/test_invoker/test_search_paths.rb +30 -8
- data/lib/ceedling/test_invoker/test_substitutions.rb +72 -0
- data/lib/ceedling/tools/shell_quoting.rb +45 -0
- data/lib/ceedling/tools/tool_quoting.rb +79 -0
- data/lib/ceedling/{tool_validator.rb → tools/tool_validator.rb} +18 -7
- data/lib/version.rb +1 -1
- data/plugins/bullseye/bullseye.rake +1 -3
- data/plugins/bullseye/lib/bullseye.rb +15 -2
- data/plugins/command_hooks/lib/command_hooks.rb +1 -1
- data/plugins/fff/lib/fff.rb +42 -15
- data/plugins/fff/lib/fff_mock_generator.rb +12 -9
- data/plugins/fff/spec/fff_cmock_wrapper_spec.rb +134 -0
- data/plugins/fff/spec/fff_mock_header_generator_spec.rb +9 -0
- data/plugins/fff/spec/fff_mock_source_generator_spec.rb +20 -0
- data/plugins/gcov/lib/console_reportinator.rb +25 -19
- data/plugins/gcov/lib/reportgenerator_reportinator.rb +2 -1
- data/site-local/404.html +2 -2
- data/site-local/assets/javascripts/{bundle.c21346df.min.js → bundle.a5f9d56c.min.js} +1 -1
- data/site-local/assets/javascripts/{bundle.c21346df.min.js.map → bundle.a5f9d56c.min.js.map} +2 -2
- data/site-local/configuration/environment-vars.html +2 -2
- data/site-local/configuration/global-collections.html +3 -3
- data/site-local/configuration/index.html +2 -2
- data/site-local/configuration/loading.html +2 -2
- data/site-local/configuration/mixins.html +2 -2
- data/site-local/configuration/parallel-builds.html +2 -2
- data/site-local/configuration/project-file.html +2 -2
- data/site-local/configuration/reference/cexception.html +2 -2
- data/site-local/configuration/reference/cmock.html +5 -2
- data/site-local/configuration/reference/defines.html +2 -2
- data/site-local/configuration/reference/environment.html +2 -2
- data/site-local/configuration/reference/extension.html +2 -2
- data/site-local/configuration/reference/files.html +56 -9
- data/site-local/configuration/reference/flags.html +2 -2
- data/site-local/configuration/reference/index.html +2 -2
- data/site-local/configuration/reference/libraries.html +2 -2
- data/site-local/configuration/reference/mixins.html +2 -2
- data/site-local/configuration/reference/partials.html +84 -2
- data/site-local/configuration/reference/paths.html +7 -2
- data/site-local/configuration/reference/plugins.html +2 -2
- data/site-local/configuration/reference/project.html +247 -5
- data/site-local/configuration/reference/release-build.html +2 -2
- data/site-local/configuration/reference/test-build.html +2 -2
- data/site-local/configuration/reference/test-runner.html +2 -2
- data/site-local/configuration/reference/tools.html +49 -4
- data/site-local/configuration/reference/unity.html +2 -2
- data/site-local/configuration/which-ceedling.html +2 -2
- data/site-local/development/index.html +2 -2
- data/site-local/development/plugins/configuration.html +2 -2
- data/site-local/development/plugins/index.html +2 -2
- data/site-local/development/plugins/plugin-subclass.html +5 -4
- data/site-local/development/plugins/rake-tasks.html +2 -2
- data/site-local/development/releases.html +2 -2
- data/site-local/development/workflow.html +2 -2
- data/site-local/getting-started/builds.html +2 -2
- data/site-local/getting-started/command-line.html +2 -2
- data/site-local/getting-started/example-projects/cipher-quest.html +2 -2
- data/site-local/getting-started/example-projects/index.html +2 -2
- data/site-local/getting-started/example-projects/temp-sensor.html +2 -2
- data/site-local/getting-started/example-projects/wondrous-forest.html +10 -2
- data/site-local/getting-started/index.html +2 -2
- data/site-local/getting-started/installation.html +2 -2
- data/site-local/getting-started/quick-start.html +2 -2
- data/site-local/help.html +2 -2
- data/site-local/index.html +2 -2
- data/site-local/overview/build-system.html +2 -2
- data/site-local/overview/index.html +2 -2
- data/site-local/overview/test-environments.html +2 -2
- data/site-local/overview/tools-and-frameworks.html +2 -2
- data/site-local/plugins/beep.html +2 -2
- data/site-local/plugins/bullseye/index.html +45 -38
- data/site-local/plugins/bullseye/licensing.html +2 -2
- data/site-local/plugins/command-hooks.html +4 -4
- data/site-local/plugins/compile-commands-json-db.html +2 -2
- data/site-local/plugins/cppcheck.html +2 -2
- data/site-local/plugins/dependencies.html +2 -2
- data/site-local/plugins/fff.html +16 -2
- data/site-local/plugins/gcov/examples.html +2 -2
- data/site-local/plugins/gcov/gcovr.html +8 -2
- data/site-local/plugins/gcov/index.html +2 -2
- data/site-local/plugins/gcov/overview.html +2 -2
- data/site-local/plugins/gcov/reportgenerator.html +18 -14
- data/site-local/plugins/gcov/reporting.html +2 -2
- data/site-local/plugins/gcov/setup.html +2 -2
- data/site-local/plugins/gcov/tool-versions.html +2 -2
- data/site-local/plugins/gcov/troubleshooting.html +2 -2
- data/site-local/plugins/index.html +2 -2
- data/site-local/plugins/module-generator.html +2 -2
- data/site-local/plugins/report-build-warnings-log.html +2 -2
- data/site-local/plugins/report-tests-gtestlike-stdout.html +2 -2
- data/site-local/plugins/report-tests-ide-stdout.html +2 -2
- data/site-local/plugins/report-tests-log-factory.html +2 -2
- data/site-local/plugins/report-tests-pretty-stdout.html +2 -2
- data/site-local/plugins/report-tests-raw-output-log.html +2 -2
- data/site-local/plugins/report-tests-teamcity-stdout.html +2 -2
- data/site-local/plugins/sanitize.html +2 -2
- data/site-local/plugins/valgrind.html +2 -2
- data/site-local/project/index.html +2 -2
- data/site-local/project/release-history.html +2 -2
- data/site-local/project/sbom.html +2 -2
- data/site-local/project/upgrade.html +2 -2
- data/site-local/reference/build-directives.html +2 -2
- data/site-local/reference/command-line.html +2 -2
- data/site-local/reference/environment-vars.html +2 -2
- data/site-local/reference/gcov-plugin.html +2 -2
- data/site-local/reference/global-collections.html +12 -12
- data/site-local/reference/index.html +2 -2
- data/site-local/reference/partials-macros.html +47 -2
- data/site-local/reference/project-configuration.html +2 -2
- data/site-local/sitemap.xml.gz +0 -0
- data/site-local/snapshot/examples/cipher_quest/index.html +2 -2
- data/site-local/snapshot/examples/temp_sensor/index.html +2 -2
- data/site-local/snapshot/examples/wondrous_forest/index.html +72 -15
- data/site-local/testing-guide/build-directives.html +2 -2
- data/site-local/testing-guide/conventions.html +67 -22
- data/site-local/testing-guide/frameworks.html +2 -2
- data/site-local/testing-guide/index.html +2 -2
- data/site-local/testing-guide/partials/configuration.html +31 -4
- data/site-local/testing-guide/partials/conventions.html +509 -8
- data/site-local/testing-guide/partials/directives.html +4 -3
- data/site-local/testing-guide/partials/example.html +2 -2
- data/site-local/testing-guide/partials/index.html +2 -2
- data/site-local/testing-guide/partials/overview.html +30 -12
- data/site-local/testing-guide/partials/variables.html +169 -4
- data/site-local/testing-guide/test-cases.html +2 -2
- data/site-local/testing-guide/test-sample.html +2 -2
- data/site-local/testing-guide/test-suite-anatomy.html +2 -2
- data/spec/integration/build_step_doctor_spec.rb +270 -0
- data/spec/integration/c_extractor_composition_spec.rb +254 -4
- data/spec/integration/includes_extraction_spec.rb +27 -14
- data/spec/integration/nested_test_artifacts_spec.rb +1 -1
- data/spec/integration/partial_files_preprocessing_spec.rb +128 -0
- data/spec/integration/partials_carry_spec.rb +520 -0
- data/spec/integration/partials_declarations_spec.rb +655 -0
- data/spec/integration/partials_fallback_preprocessing_spec.rb +65 -0
- data/spec/integration/partials_function_pointers_spec.rb +277 -0
- data/spec/integration/partials_header_composition_spec.rb +268 -35
- data/spec/integration/partials_macro_decorators_spec.rb +267 -0
- data/spec/integration/partials_module_resolution_spec.rb +26 -19
- data/spec/integration/partials_symbol_linkage_spec.rb +13 -0
- data/spec/integration/path_length_reporting_spec.rb +64 -0
- data/spec/integration/path_scenarios_spec.rb +80 -3
- data/spec/integration/quote_include_isolator_spec.rb +56 -0
- data/spec/integration/test_build_parallel_barrier_spec.rb +1 -1
- data/spec/integration/test_includes_extractinator_spec.rb +70 -5
- data/spec/integration/test_naming_spec.rb +6 -3
- data/spec/integration/test_source_file_checks_spec.rb +5 -3
- data/spec/integration/tool_executor_spec.rb +1 -1
- data/spec/integration/tool_validator_spec.rb +2 -2
- data/spec/integration/win_long_paths_probe_spec.rb +46 -0
- data/spec/integration/win_path_limit_spec.rb +53 -0
- data/spec/integration/windows_registry_query_tool_spec.rb +41 -0
- data/spec/support/integration/configurator_integration_helper.rb +8 -3
- data/spec/support/integration/partial_files_harness.rb +181 -0
- data/spec/support/integration/partials_generation_integration_helper.rb +237 -141
- data/spec/support/integration/path_scenario_harness.rb +4 -2
- data/spec/support/integration/spec_integration_helper.rb +8 -3
- data/spec/support/integration/test_includes_harness.rb +56 -35
- data/spec/support/integration/tool_executor_integration_helper.rb +14 -2
- data/spec/system/bullseye_deployment_spec.rb +2 -0
- data/spec/system/delta_builds_spec.rb +26 -12
- data/spec/system/encoding_stress_spec.rb +4 -4
- data/spec/system/example_wondrous_forest_spec.rb +2 -2
- data/spec/system/gcov_deployment_spec.rb +2 -0
- data/spec/system/header_include_path_validation_spec.rb +4 -4
- data/spec/system/header_search_paths_spec.rb +1083 -0
- data/spec/system/mock_include_folders_spec.rb +121 -0
- data/spec/system/mockable_header_reassembly_spec.rb +184 -0
- data/spec/system/partials_carry_spec.rb +581 -0
- data/spec/system/partials_delta_builds_spec.rb +280 -0
- data/spec/system/partials_function_pointers_spec.rb +106 -0
- data/spec/system/partials_macro_decorators_spec.rb +127 -0
- data/spec/system/partials_module_disambiguation_spec.rb +125 -0
- data/spec/system/path_handling_probes_spec.rb +16 -12
- data/spec/system/pinned_thread_count_spec.rb +4 -4
- data/spec/system/preprocessing_fallback_conditionals_spec.rb +1 -1
- data/spec/system/short_build_paths_spec.rb +87 -0
- data/spec/system/sibling_header_collision_spec.rb +30 -6
- data/spec/system/support/bullseye_common_test_cases.rb +42 -0
- data/spec/system/support/common_test_cases.rb +2 -2
- data/spec/system/support/gcov_partials_test_cases.rb +48 -0
- data/spec/system/test_build_layout_spec.rb +209 -0
- data/spec/system/test_source_file_directive_spec.rb +35 -5
- data/spec/units/c_extractor/c_extractor_code_text_spec.rb +67 -10
- data/spec/units/c_extractor/c_extractor_declarations_spec.rb +501 -4
- data/spec/units/c_extractor/c_extractor_declarator_spec.rb +245 -0
- data/spec/units/c_extractor/c_extractor_defined_type_spec.rb +45 -0
- data/spec/units/c_extractor/c_extractor_definitions_spec.rb +163 -3
- data/spec/units/c_extractor/c_extractor_functions_spec.rb +462 -21
- data/spec/units/c_extractor/c_extractor_preprocessing_spec.rb +39 -0
- data/spec/units/c_extractor/c_extractor_spec.rb +4 -4
- data/spec/units/c_extractor/c_extractor_types_spec.rb +163 -0
- data/spec/units/c_identifier_spec.rb +35 -0
- data/spec/units/config/configurator_builder_spec.rb +24 -0
- data/spec/units/config/configurator_setup_spec.rb +72 -4
- data/spec/units/config/configurator_spec.rb +27 -1
- data/spec/units/dependencies/dependency_cache_store_spec.rb +68 -3
- data/spec/units/dependencies/dependency_tracker_spec.rb +25 -0
- data/spec/units/dependencies/dependinator_spec.rb +17 -2
- data/spec/units/diagnostics/build_step_doctor_spec.rb +170 -0
- data/spec/units/diagnostics/duplicate_symbol_specialist_spec.rb +117 -0
- data/spec/units/diagnostics/header_collision_specialist_spec.rb +267 -0
- data/spec/units/diagnostics/include_depth_specialist_spec.rb +137 -0
- data/spec/units/diagnostics/missing_symbol_specialist_spec.rb +154 -0
- data/spec/units/diagnostics/partial_name_specialist_spec.rb +129 -0
- data/spec/units/diagnostics/toolchain_output_spec.rb +86 -0
- data/spec/units/encodinator_spec.rb +3 -4
- data/spec/units/filesystem/build_roots_spec.rb +131 -0
- data/spec/units/filesystem/build_subpath_spec.rb +113 -0
- data/spec/units/filesystem/file_finder_helper_spec.rb +80 -0
- data/spec/units/filesystem/file_finder_spec.rb +242 -58
- data/spec/units/filesystem/file_path_utils_spec.rb +251 -118
- data/spec/units/filesystem/file_wrapper_spec.rb +191 -6
- data/spec/units/filesystem/path_matcher_spec.rb +36 -0
- data/spec/units/filesystem/test_build_layout_spec.rb +216 -0
- data/spec/units/filesystem/win_long_paths_spec.rb +204 -0
- data/spec/units/filesystem/win_path_prober_spec.rb +158 -0
- data/spec/units/generators/generator_helper_spec.rb +0 -60
- data/spec/units/generators/generator_mocks_spec.rb +13 -0
- data/spec/units/generators/generator_partials_spec.rb +656 -55
- data/spec/units/generators/generator_spec.rb +26 -0
- data/spec/units/generators/generator_test_runner_spec.rb +9 -5
- data/spec/units/generators/partial_source_writer_spec.rb +129 -0
- data/spec/units/includes/header_search_spec.rb +406 -0
- data/spec/units/includes/include_factory_spec.rb +22 -5
- data/spec/units/includes/include_pathinator_spec.rb +77 -13
- data/spec/units/includes/include_spec.rb +14 -0
- data/spec/units/includes/includes_spec.rb +176 -19
- data/spec/units/loginator_spec.rb +31 -0
- data/spec/units/mock_locator_spec.rb +199 -5
- data/spec/units/partials/include_groups_spec.rb +42 -0
- data/spec/units/partials/partializer_config_spec.rb +25 -0
- data/spec/units/partials/partializer_helper_carry_spec.rb +661 -0
- data/spec/units/partials/partializer_helper_interface_extras_spec.rb +396 -0
- data/spec/units/partials/partializer_helper_spec.rb +529 -277
- data/spec/units/partials/partializer_reconciler_spec.rb +661 -0
- data/spec/units/partials/partializer_spec.rb +1578 -270
- data/spec/units/partials/partializer_utils_spec.rb +269 -232
- data/spec/units/partials/partials_rename_spec.rb +160 -0
- data/spec/units/partials_manager_spec.rb +554 -261
- data/spec/units/plugins/bullseye_spec.rb +34 -0
- data/spec/units/plugins/console_reportinator_spec.rb +58 -9
- data/spec/units/plugins/report_tests_teamcity_stdout_spec.rb +1 -1
- data/spec/units/plugins/reportgenerator_reportinator_spec.rb +51 -3
- data/spec/units/preprocess/preprocessinator_code_finder_spec.rb +73 -10
- data/spec/units/preprocess/preprocessinator_file_assembler_spec.rb +125 -37
- data/spec/units/preprocess/preprocessinator_includes_handler_spec.rb +15 -0
- data/spec/units/preprocess/preprocessinator_reconstructor_spec.rb +197 -0
- data/spec/units/preprocess/preprocessinator_spec.rb +153 -95
- data/spec/units/setupinator_spec.rb +51 -0
- data/spec/units/standin_headerinator_spec.rb +27 -11
- data/spec/units/test_build_executor_spec.rb +780 -166
- data/spec/units/test_build_planner_spec.rb +116 -28
- data/spec/units/test_build_setup_spec.rb +83 -18
- data/spec/units/test_context_extractor_spec.rb +11 -2
- data/spec/units/test_derived_search_paths_spec.rb +259 -0
- data/spec/units/test_includes_extractinator_spec.rb +56 -8
- data/spec/units/test_invoker/objects_wiring_spec.rb +20 -3
- data/spec/units/test_invoker/partial_files_preprocessinator_spec.rb +264 -0
- data/spec/units/test_invoker/test_substitutions_spec.rb +122 -0
- data/spec/units/test_invoker_types_spec.rb +8 -7
- data/spec/units/test_pipeline_manager_spec.rb +54 -13
- data/spec/units/test_runner_generatinator_spec.rb +93 -1
- data/spec/units/test_search_paths_spec.rb +73 -5
- data/spec/units/{default_tools_quoting_spec.rb → tools/default_tools_quoting_spec.rb} +39 -5
- data/spec/units/tools/shell_quoting_spec.rb +76 -0
- data/spec/units/{tool_executor_helper_spec.rb → tools/tool_executor_helper_spec.rb} +1 -1
- data/spec/units/{tool_executor_spec.rb → tools/tool_executor_spec.rb} +1 -1
- data/spec/units/{tool_validator_spec.rb → tools/tool_validator_spec.rb} +110 -1
- data/spec/units/windows_registry_query_tool_spec.rb +53 -0
- metadata +161 -16
- /data/lib/ceedling/{tool_executor.rb → tools/tool_executor.rb} +0 -0
- /data/lib/ceedling/{tool_executor_helper.rb → tools/tool_executor_helper.rb} +0 -0
|
@@ -0,0 +1,1083 @@
|
|
|
1
|
+
# =========================================================================
|
|
2
|
+
# Ceedling - Test-Centered Build System for C
|
|
3
|
+
# ThrowTheSwitch.org
|
|
4
|
+
# Copyright (c) 2010-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
|
5
|
+
# SPDX-License-Identifier: MIT
|
|
6
|
+
# =========================================================================
|
|
7
|
+
|
|
8
|
+
require 'spec_system_helper'
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
## Headers Found Through Search Paths as the Compiler Finds Them
|
|
12
|
+
## =============================================================
|
|
13
|
+
##
|
|
14
|
+
## A test's #include names a header by its path below a search path, and the compiler
|
|
15
|
+
## joins each search path with that path in turn. Ceedling finds a mock's header, and
|
|
16
|
+
## checks a test's plain #includes, the same way, so a search path need not list every
|
|
17
|
+
## directory below it.
|
|
18
|
+
##
|
|
19
|
+
|
|
20
|
+
HEADER_SEARCH_PREAMBLE = "#include \"unity.h\"\nvoid setUp(void) {}\nvoid tearDown(void) {}\n"
|
|
21
|
+
|
|
22
|
+
# A header below a search path that doesn't list its directory
|
|
23
|
+
HEADER_SEARCH_DRIVERS_FOO = "#ifndef FOO_H\n#define FOO_H\ntypedef int foo_t;\nint foo_read(void);\n#endif\n"
|
|
24
|
+
|
|
25
|
+
ceedling_system_tests do
|
|
26
|
+
include_context "a fresh ceedling gem project", "header_search"
|
|
27
|
+
|
|
28
|
+
def write(path, content)
|
|
29
|
+
FileUtils.mkdir_p( File.dirname( path ) )
|
|
30
|
+
File.write( path, content )
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Merging adds to a list, so the new project's own include paths are removed first
|
|
34
|
+
def configure(include_paths, preprocessor, extra = {})
|
|
35
|
+
@c.remove_project_yml_option_for_test( :paths, :include )
|
|
36
|
+
@c.merge_project_yml_for_test( { :project => { :use_test_preprocessor => preprocessor }, :paths => { :include => include_paths } }.merge( extra ) )
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def build_passes
|
|
40
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
41
|
+
|
|
42
|
+
expect(@c.last_exit_status).to eq(0), output
|
|
43
|
+
expect(output).to match(/PASSED:\s+1/)
|
|
44
|
+
return output
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
[:none, :mocks, :all].each do |preprocessor|
|
|
48
|
+
context "with :use_test_preprocessor #{preprocessor}" do
|
|
49
|
+
it "mocks a header named by its directory below a search path that doesn't list that directory" do
|
|
50
|
+
in_project do
|
|
51
|
+
write( 'src/drivers/foo.h', "int foo_read(void);\n" )
|
|
52
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
53
|
+
"void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
54
|
+
|
|
55
|
+
configure( ['src'], preprocessor )
|
|
56
|
+
build_passes
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "includes a header named by its directory below a search path that doesn't list that directory" do
|
|
61
|
+
in_project do
|
|
62
|
+
write( 'src/drivers/foo.h', "#define FOO_MAGIC 7\n" )
|
|
63
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n" \
|
|
64
|
+
"void test_magic(void) { TEST_ASSERT_EQUAL_INT(7, FOO_MAGIC); }\n" )
|
|
65
|
+
|
|
66
|
+
configure( ['src'], preprocessor )
|
|
67
|
+
build_passes
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "includes the header below the first search path holding the path, as the compiler does" do
|
|
72
|
+
in_project do
|
|
73
|
+
write( 'a/drivers/foo.h', "#define FOO_MAGIC 1\n" )
|
|
74
|
+
write( 'b/drivers/foo.h', "#define FOO_MAGIC 2\n" )
|
|
75
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n" \
|
|
76
|
+
"void test_magic(void) { TEST_ASSERT_EQUAL_INT(1, FOO_MAGIC); }\n" )
|
|
77
|
+
|
|
78
|
+
configure( ['a', 'b'], preprocessor )
|
|
79
|
+
output = build_passes
|
|
80
|
+
|
|
81
|
+
# A preprocessed test file's #include names the header GCC already chose
|
|
82
|
+
expect(output).to include( "Multiple files matched 'drivers/foo.h' but chose 'a/drivers/foo.h'" ) unless preprocessor == :all
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "mocks the header below the search path TEST_INCLUDE_PATH() puts first" do
|
|
87
|
+
in_project do
|
|
88
|
+
write( 'a/drivers/foo.h', "int a_read(void);\n" )
|
|
89
|
+
write( 'b/drivers/foo.h', "int b_read(void);\n" )
|
|
90
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "TEST_INCLUDE_PATH(\"b\")\n#include \"drivers/mock_foo.h\"\n" \
|
|
91
|
+
"void test_reads(void) { b_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, b_read()); }\n" )
|
|
92
|
+
|
|
93
|
+
configure( ['a', 'b'], preprocessor )
|
|
94
|
+
build_passes
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# A preprocessed test's mock keeps the #include the test wrote. A header of the path its
|
|
101
|
+
# mirrored place would name, below an earlier search path, is a different header.
|
|
102
|
+
it "mocks and includes the header a preprocessed test's #include names, not one of its mirrored path in an earlier search path" do
|
|
103
|
+
in_project do
|
|
104
|
+
write( 'test/support/hal/foo.h', "int fake_read(void);\n" )
|
|
105
|
+
write( 'inc/hal/foo.h', "int foo_read(void);\n" )
|
|
106
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_foo.h\"\n" \
|
|
107
|
+
"void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
108
|
+
configure( ['inc/**'], :all, { :paths => { :include => ['inc/**'], :support => ['test/support'] } } )
|
|
109
|
+
|
|
110
|
+
build_passes
|
|
111
|
+
expect(File.read( 'build/test/mocks/test/test_c/_t_/hal/mock_foo.h' )).to include( 'foo_read' )
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# The compiler joins a mock's #include with each search path in order, under test
|
|
116
|
+
# preprocessing as without it
|
|
117
|
+
[:none, :all].each do |preprocessor|
|
|
118
|
+
it "mocks the header a mock's folder joins to first under :use_test_preprocessor #{preprocessor}" do
|
|
119
|
+
in_project do
|
|
120
|
+
write( 'test/support/hal/foo.h', "int fake_read(void);\n" )
|
|
121
|
+
write( 'inc/hal/foo.h', "int foo_read(void);\n" )
|
|
122
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"hal/mock_foo.h\"\n" \
|
|
123
|
+
"void test_reads(void) { fake_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, fake_read()); }\n" )
|
|
124
|
+
configure( ['inc/**'], preprocessor, { :paths => { :include => ['inc/**'], :support => ['test/support'] } } )
|
|
125
|
+
|
|
126
|
+
build_passes
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "mocks a header by a folder below a search path without naming the mock by it" do
|
|
132
|
+
in_project do
|
|
133
|
+
write( 'src/drivers/foo.h', "int foo_read(void);\n" )
|
|
134
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
135
|
+
"void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
136
|
+
|
|
137
|
+
configure( ['src'], :none, { :cmock => { :mock_name_include_folder => false } } )
|
|
138
|
+
expect(build_passes).to include( "Added search path 'src/drivers'" )
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# A header only :files ↳ :include supplies sits in no search path's directory. The
|
|
143
|
+
# directory a test's #include implies for it joins that test's search paths, last.
|
|
144
|
+
describe "a header only :files supplies" do
|
|
145
|
+
SENSOR_TEST = "void test_reads(void) { sensor_read_ExpectAndReturn(42); TEST_ASSERT_EQUAL_INT(42, sensor_read()); }\n"
|
|
146
|
+
|
|
147
|
+
def sensor_project(include_line, include_paths: ['.'], files: ['+:src/**/*.h'], preprocessor: :none, treat_inlines: :exclude)
|
|
148
|
+
write( 'src/path/to/sensor.h', "int sensor_read(void);\n" )
|
|
149
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + include_line + "\n" + SENSOR_TEST )
|
|
150
|
+
configure( include_paths, preprocessor, { :files => { :include => files }, :cmock => { :treat_inlines => treat_inlines } } )
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
[:none, :mocks, :all].each do |preprocessor|
|
|
154
|
+
[:exclude, :include].each do |treat_inlines|
|
|
155
|
+
context "with :use_test_preprocessor #{preprocessor} and :treat_inlines #{treat_inlines}" do
|
|
156
|
+
it "mocks it through the folder its #include names below a search path" do
|
|
157
|
+
in_project do
|
|
158
|
+
sensor_project( '#include "src/path/to/mock_sensor.h"', preprocessor: preprocessor, treat_inlines: treat_inlines )
|
|
159
|
+
expect(build_passes).to_not include( 'Added search path' )
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "mocks it by its bare name through the directory its #include implies" do
|
|
164
|
+
in_project do
|
|
165
|
+
sensor_project( '#include "mock_sensor.h"', preprocessor: preprocessor, treat_inlines: treat_inlines )
|
|
166
|
+
expect(build_passes).to include(
|
|
167
|
+
"Added search path 'src/path/to' for test/test_c.c after every configured search path, so \"sensor.h\" reaches src/path/to/sensor.h."
|
|
168
|
+
)
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it "mocks it through its folder when no search path reaches that folder, through the directory it is measured from" do
|
|
176
|
+
in_project do
|
|
177
|
+
write( 'inc/other.h', "int other(void);\n" )
|
|
178
|
+
sensor_project( '#include "src/path/to/mock_sensor.h"', include_paths: ['inc'] )
|
|
179
|
+
expect(build_passes).to include( "Added search path '.' for test/test_c.c" )
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "mocks it through a folder that starts at a search path, through the directory that folder is measured from" do
|
|
184
|
+
in_project do
|
|
185
|
+
sensor_project( '#include "src/path/to/mock_sensor.h"', include_paths: ['src'] )
|
|
186
|
+
expect(build_passes).to include( "Added search path '.' for test/test_c.c" )
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
it "includes it in the runner through the directory its #include implies" do
|
|
191
|
+
in_project do
|
|
192
|
+
write( 'src/path/to/sensor_types.h', "typedef int sensor_value_t;\n" )
|
|
193
|
+
sensor_project( "#include \"sensor_types.h\"\n#include \"mock_sensor.h\"\nvoid test_type(void) { sensor_value_t v = 3; TEST_ASSERT_EQUAL_INT(3, v); }",
|
|
194
|
+
files: ['+:src/**/*.h'] )
|
|
195
|
+
|
|
196
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
197
|
+
expect(@c.last_exit_status).to eq(0), output
|
|
198
|
+
expect(output).to match(/PASSED:\s+2/)
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it "never lets the directory it adds shadow a configured header" do
|
|
203
|
+
in_project do
|
|
204
|
+
write( 'inc/config.h', "#define CONFIG_MAGIC 1\n" )
|
|
205
|
+
write( 'src/path/to/config.h', "#define CONFIG_MAGIC 2\n" )
|
|
206
|
+
sensor_project( "#include \"config.h\"\n#include \"mock_sensor.h\"\nvoid test_config(void) { TEST_ASSERT_EQUAL_INT(1, CONFIG_MAGIC); }",
|
|
207
|
+
include_paths: ['inc'], files: ['+:src/path/to/sensor.h'] )
|
|
208
|
+
|
|
209
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
210
|
+
expect(@c.last_exit_status).to eq(0), output
|
|
211
|
+
expect(output).to match(/PASSED:\s+2/)
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
it "can't be mocked once a subtractive entry removes it" do
|
|
216
|
+
in_project do
|
|
217
|
+
sensor_project( '#include "mock_sensor.h"', files: ['+:src/**/*.h', '-:src/path/to/sensor.h'] )
|
|
218
|
+
|
|
219
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
220
|
+
expect(@c.last_exit_status).to_not eq(0)
|
|
221
|
+
expect(output).to include( 'Found no file `sensor.h` in search paths.' )
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# The compiler rejects such an #include, and so does the build
|
|
226
|
+
it "adds no search path for an #include that spells a search path's own directory into it" do
|
|
227
|
+
in_project do
|
|
228
|
+
write( 'src/x.h', "#define X_MAGIC 3\n" )
|
|
229
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"src/x.h\"\nvoid test_x(void) { TEST_ASSERT_EQUAL_INT(3, X_MAGIC); }\n" )
|
|
230
|
+
configure( ['src'], :none )
|
|
231
|
+
|
|
232
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
233
|
+
expect(@c.last_exit_status).to_not eq(0)
|
|
234
|
+
expect(output).to_not include( 'Added search path' )
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# glibc's socket.h sits in a multiarch directory of forwarding headers that GCC searches
|
|
240
|
+
# on its own
|
|
241
|
+
describe "a system header below a multiarch directory" do
|
|
242
|
+
before(:each) do
|
|
243
|
+
multiarch = `gcc -print-multiarch 2>#{File::NULL}`.strip
|
|
244
|
+
@multiarch_dir = "/usr/include/#{multiarch}"
|
|
245
|
+
skip "no glibc sys/socket.h below a multiarch directory" if multiarch.empty? or !File.exist?( File.join( @multiarch_dir, 'sys/socket.h' ) )
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
SOCKET_TEST = "void test_socket(void) { socket_ExpectAndReturn(1, 2, 3, 4); TEST_ASSERT_EQUAL_INT(4, socket(1, 2, 3)); }\n"
|
|
249
|
+
|
|
250
|
+
def socket_project(include_line, include_paths:, files: [], preprocessor: :all, cmock: {})
|
|
251
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include <errno.h>\n" + include_line + "\n" + SOCKET_TEST )
|
|
252
|
+
configure( include_paths, preprocessor, { :files => { :include => files }, :cmock => { :treat_externs => :include }.merge( cmock ) } )
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def socket_header
|
|
256
|
+
return File.join( @multiarch_dir, 'sys/socket.h' )
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "mocks it by its subdirectory below the multiarch directory a search path lists" do
|
|
260
|
+
in_project do
|
|
261
|
+
socket_project( '#include "sys/mock_socket.h"', include_paths: [@multiarch_dir] )
|
|
262
|
+
build_passes
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it "mocks it by its subdirectory through the directory its #include implies, when only :files lists it" do
|
|
267
|
+
in_project do
|
|
268
|
+
socket_project( '#include "sys/mock_socket.h"', include_paths: ['test'], files: [File.join( @multiarch_dir, 'sys/socket.h' )] )
|
|
269
|
+
# Ceedling spells a path outside the project from the working directory
|
|
270
|
+
expect(build_passes).to match( /Added search path '[^']*#{Regexp.escape( @multiarch_dir )}' for test\/test_c\.c/ )
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
# A failed lookup stops the build in stage 2 without test preprocessing, and later with it
|
|
275
|
+
[:none, :all].each do |preprocessor|
|
|
276
|
+
it "adds no search path for its bare name, and its error at :use_test_preprocessor #{preprocessor} names the #include that reaches it" do
|
|
277
|
+
in_project do
|
|
278
|
+
socket_project( '#include "mock_socket.h"', include_paths: ['test'], files: [socket_header], preprocessor: preprocessor )
|
|
279
|
+
|
|
280
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
281
|
+
expect(@c.last_exit_status).to_not eq(0)
|
|
282
|
+
expect(output).to include(
|
|
283
|
+
"Found no file `socket.h` in search paths. `#include \"mock_socket.h\"` in test/test_c.c needs search path '#{@multiarch_dir}/sys'. " \
|
|
284
|
+
"Because this search path is outside the working directory and could cause shadowing of other headers, " \
|
|
285
|
+
"Ceedling won't add the full search path. Instead, reference the parent folder, as in `#include \"sys/mock_socket.h\"`."
|
|
286
|
+
)
|
|
287
|
+
expect(output).to_not include( 'Added search path' )
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
# Captured output loses the option's arrow under a locale without UTF-8
|
|
293
|
+
def naming_option(text)
|
|
294
|
+
return Regexp.new( Regexp.escape( text ).gsub( Regexp.escape( ':cmock ↳ ' ) ) { ':cmock\s*\S*\s*' } )
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "names the option a mock without its folder needs in its error" do
|
|
298
|
+
in_project do
|
|
299
|
+
socket_project( '#include "sys/mock_socket.h"', include_paths: ['test'], files: [socket_header], cmock: { :mock_name_include_folder => false } )
|
|
300
|
+
|
|
301
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
302
|
+
expect(@c.last_exit_status).to_not eq(0)
|
|
303
|
+
expect(output).to match( naming_option(
|
|
304
|
+
"Found no file `sys/socket.h` in search paths. `#include \"sys/mock_socket.h\"` in test/test_c.c needs search path '#{@multiarch_dir}/sys', " \
|
|
305
|
+
"since its mock writes `#include \"socket.h\"` with :cmock ↳ :mock_name_include_folder disabled."
|
|
306
|
+
) )
|
|
307
|
+
expect(output).to match( naming_option( 'Instead, enable :cmock ↳ :mock_name_include_folder and reference the parent folder' ) )
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
# The lookup tries each header extension, and its error names the last
|
|
312
|
+
it "explains a plain #include's bare name in its error with more than one header extension" do
|
|
313
|
+
in_project do
|
|
314
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"socket.h\"\nvoid test_nothing(void) { TEST_ASSERT_EQUAL_INT(1, 1); }\n" )
|
|
315
|
+
configure( ['test'], :none, { :files => { :include => [socket_header] }, :extension => { :header => ['.h', '.hpp'] } } )
|
|
316
|
+
|
|
317
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
318
|
+
expect(@c.last_exit_status).to_not eq(0)
|
|
319
|
+
expect(output).to include(
|
|
320
|
+
"Found no file `socket.hpp` in search paths. `#include \"socket.h\"` in test/test_c.c needs search path '#{@multiarch_dir}/sys'."
|
|
321
|
+
)
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# Stage 2 reads the #include from the file's text, and only a failed lookup reports it
|
|
326
|
+
it "says nothing of a bare name test preprocessing removes" do
|
|
327
|
+
in_project do
|
|
328
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#ifdef NEVER_DEFINED\n#include \"mock_socket.h\"\n#endif\n" \
|
|
329
|
+
"void test_nothing(void) { TEST_ASSERT_EQUAL_INT(1, 1); }\n" )
|
|
330
|
+
configure( ['test'], :all, { :files => { :include => [socket_header] } } )
|
|
331
|
+
|
|
332
|
+
expect(build_passes).to_not include( 'needs search path' )
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
it "can't mock it by its subdirectory through /usr/include alone" do
|
|
337
|
+
skip "this system links sys/socket.h into /usr/include itself" if File.exist?( '/usr/include/sys/socket.h' )
|
|
338
|
+
|
|
339
|
+
in_project do
|
|
340
|
+
socket_project( '#include "sys/mock_socket.h"', include_paths: ['/usr/include'] )
|
|
341
|
+
|
|
342
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
343
|
+
expect(@c.last_exit_status).to_not eq(0)
|
|
344
|
+
expect(output).to include( 'Found no file `sys/socket.h` in search paths.' )
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# A generated file carries a header's #includes. Each names the header as the test's search
|
|
350
|
+
# paths reach it, so a header below a non-recursive search path is found from there too.
|
|
351
|
+
describe "a generated file's #includes" do
|
|
352
|
+
[:none, :mocks, :all].each do |preprocessor|
|
|
353
|
+
it "reach a header below the search path from a Partial under :use_test_preprocessor #{preprocessor}" do
|
|
354
|
+
in_project do
|
|
355
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
356
|
+
write( 'src/sensor.h', "#ifndef SENSOR_H\n#define SENSOR_H\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void);\n#endif\n" )
|
|
357
|
+
write( 'src/sensor.c', "#include \"sensor.h\"\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void) { return 3; }\n" )
|
|
358
|
+
write( 'test/test_sensor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
359
|
+
"#include TEST_PARTIAL_ALL_MODULE(sensor)\nvoid test_get(void) { TEST_ASSERT_EQUAL_INT(3, sensor_get()); }\n" )
|
|
360
|
+
|
|
361
|
+
configure( ['src'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
|
|
362
|
+
build_passes
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
it "reach a header below the search path from a mocked Partial under :use_test_preprocessor #{preprocessor}" do
|
|
367
|
+
in_project do
|
|
368
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
369
|
+
write( 'src/sensor.h', "#ifndef SENSOR_H\n#define SENSOR_H\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void);\n#endif\n" )
|
|
370
|
+
write( 'test/test_sensor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
371
|
+
"#include MOCK_PARTIAL_PUBLIC_MODULE(sensor)\n" \
|
|
372
|
+
"void test_get(void) { sensor_get_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, sensor_get()); }\n" )
|
|
373
|
+
|
|
374
|
+
configure( ['src'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
|
|
375
|
+
build_passes
|
|
376
|
+
end
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
[:mocks, :all].each do |preprocessor|
|
|
381
|
+
it "reach a header below the search path from CMock's copy under :use_test_preprocessor #{preprocessor}" do
|
|
382
|
+
in_project do
|
|
383
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
384
|
+
write( 'src/sensor.h', "#ifndef SENSOR_H\n#define SENSOR_H\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void);\n#endif\n" )
|
|
385
|
+
write( 'test/test_sensor.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_sensor.h\"\n" \
|
|
386
|
+
"void test_get(void) { sensor_get_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, sensor_get()); }\n" )
|
|
387
|
+
|
|
388
|
+
configure( ['src'], preprocessor, { :cmock => { :treat_inlines => :include } } )
|
|
389
|
+
build_passes
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# A Partial's module includes a header beside it, which an earlier search path shadows with a
|
|
395
|
+
# header of the same name. The generated Partial's #include reaches the one beside the module.
|
|
396
|
+
[:mocks, :all].product( [false, true] ).each do |preprocessor, fallback|
|
|
397
|
+
it "reach a header beside a Partial's module that an earlier search path shadows, under :use_test_preprocessor #{preprocessor}#{fallback ? ' with fallback' : ''}" do
|
|
398
|
+
in_project do
|
|
399
|
+
write( 'src/hw/config.h', "#ifndef HW_CONFIG_H\n#define HW_CONFIG_H\ntypedef int hw_t;\n#endif\n" )
|
|
400
|
+
write( 'lib/config.h', "#ifndef LIB_CONFIG_H\n#define LIB_CONFIG_H\n#define LIB_K 1\ntypedef int lib_t;\n#endif\n" )
|
|
401
|
+
write( 'lib/motor.h', "#ifndef MOTOR_H\n#define MOTOR_H\n#include \"config.h\"\nint motor_run(int a);\n#endif\n" )
|
|
402
|
+
write( 'lib/motor.c', "#include \"motor.h\"\nstatic int twice(int a) { return 2 * a + LIB_K; }\nint motor_run(int a) { return twice( a ); }\n" )
|
|
403
|
+
write( 'lib/port.h', "#ifndef PORT_H\n#define PORT_H\n#include \"config.h\"\nlib_t port_read(void);\n#endif\n" )
|
|
404
|
+
write( 'lib/port.c', "#include \"port.h\"\nlib_t port_read(void) { return 0; }\n" )
|
|
405
|
+
write( 'test/test_motor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
406
|
+
"#include TEST_PARTIAL_ALL_MODULE(motor)\nvoid test_twice(void) { TEST_ASSERT_EQUAL_INT(7, twice( 3 )); }\n" )
|
|
407
|
+
write( 'test/test_port.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
408
|
+
"#include MOCK_PARTIAL_PUBLIC_MODULE(port)\n" \
|
|
409
|
+
"void test_read(void) { port_read_ExpectAndReturn( 3 ); TEST_ASSERT_EQUAL_INT(3, port_read()); }\n" )
|
|
410
|
+
|
|
411
|
+
configure( ['src/hw/', 'lib/'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
|
|
412
|
+
@c.merge_project_yml_for_test( { :paths => { :source => ['lib/'] } } )
|
|
413
|
+
@c.merge_project_yml_for_test( { :test_build => { :preprocess_force_fallback => true } } ) if fallback
|
|
414
|
+
|
|
415
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
416
|
+
expect(@c.last_exit_status).to eq(0), output
|
|
417
|
+
expect(output).to match(/PASSED:\s+2/)
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
# A preprocessor names each #include by the path it found the header by. A later search path
|
|
423
|
+
# joined with that path can name another header, which must never take its place.
|
|
424
|
+
it "include the header the compiler found, never one a later search path joins its path to" do
|
|
425
|
+
in_project do
|
|
426
|
+
write( 'include/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define GAIN 3\n#endif\n" )
|
|
427
|
+
write( 'third_party/mylib/include/config.h', "#ifndef MYLIB_CONFIG_H\n#define MYLIB_CONFIG_H\n#define GAIN 99\n#endif\n" )
|
|
428
|
+
write( 'include/motor.h', "#ifndef MOTOR_H\n#define MOTOR_H\n#include \"config.h\"\nint motor_run(void);\n" \
|
|
429
|
+
"static inline int motor_peek(void) { return GAIN; }\n#endif\n" )
|
|
430
|
+
write( 'src/motor.c', "#include \"motor.h\"\nint motor_run(void) { return GAIN; }\n" )
|
|
431
|
+
write( 'test/test_motor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
432
|
+
"#include TEST_PARTIAL_PUBLIC_MODULE(motor)\nvoid test_run(void) { TEST_ASSERT_EQUAL_INT(3, motor_run()); }\n" )
|
|
433
|
+
write( 'test/test_cm.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_motor.h\"\nvoid test_gain(void) { TEST_ASSERT_EQUAL_INT(3, GAIN); }\n" )
|
|
434
|
+
|
|
435
|
+
configure( ['include/**', 'third_party/**'], :all, { :project => { :use_test_preprocessor => :all, :use_partials => true },
|
|
436
|
+
:cmock => { :treat_inlines => :include } } )
|
|
437
|
+
output = @c.ceedling_build_exec( "test:all" )
|
|
438
|
+
|
|
439
|
+
expect(@c.last_exit_status).to eq(0), output
|
|
440
|
+
expect(output).to match(/PASSED:\s+2/)
|
|
441
|
+
end
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
it "include in the runner the header the compiler found, never one a later search path joins its path to" do
|
|
445
|
+
in_project do
|
|
446
|
+
write( 'include/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define GAIN 3\n#endif\n" )
|
|
447
|
+
write( 'third_party/mylib/include/config.h', "#error The library's config.h reached the runner\n" )
|
|
448
|
+
write( 'test/test_gain.c', HEADER_SEARCH_PREAMBLE + "#include \"config.h\"\nvoid test_gain(void) { TEST_ASSERT_EQUAL_INT(3, GAIN); }\n" )
|
|
449
|
+
|
|
450
|
+
configure( ['include/**', 'third_party/**'], :all )
|
|
451
|
+
build_passes
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
# The compiler joins an #include with each search path. A header directly in a search path
|
|
456
|
+
# isn't reached through the directory that path names.
|
|
457
|
+
it "include in the runner by a text the compiler joins, never one only a header's trailing path matches" do
|
|
458
|
+
in_project do
|
|
459
|
+
write( 'test/hw/config.h', "#ifndef HW_CONFIG_H\n#define HW_CONFIG_H\n#define HW_GAIN 3\n#endif\n" )
|
|
460
|
+
write( 'lib/app/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define APP_GAIN 5\n#endif\n" )
|
|
461
|
+
write( 'test/test_gain.c', HEADER_SEARCH_PREAMBLE + "#include \"hw/config.h\"\n#include \"app/config.h\"\n" \
|
|
462
|
+
"void test_gain(void) { TEST_ASSERT_EQUAL_INT(15, HW_GAIN * APP_GAIN); }\n" )
|
|
463
|
+
|
|
464
|
+
configure( ['lib/'], :all )
|
|
465
|
+
build_passes
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
# A quoted #include looks beside the test file first, and the test's own compile finds that
|
|
470
|
+
# header. A header there that no search path reaches is another header than the search paths'
|
|
471
|
+
# of the same name, so the runner includes it by its absolute path.
|
|
472
|
+
it "include in the runner the header beside the test, never one of its name a search path finds" do
|
|
473
|
+
in_project do
|
|
474
|
+
write( 'test/drivers/foo.h', "#ifndef TFOO_H\n#define TFOO_H\n#define WHICH 1\n#endif\n" )
|
|
475
|
+
write( 'src/drivers/foo.h', "#ifndef SFOO_H\n#define SFOO_H\n#define WHICH 2\n#endif\n" )
|
|
476
|
+
write( 'src/other.h', "int other_read(void);\n" )
|
|
477
|
+
write( 'test/test_b.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n#include \"mock_other.h\"\n" \
|
|
478
|
+
"void test_b(void) { TEST_ASSERT_EQUAL_INT(1, WHICH); }\n" )
|
|
479
|
+
|
|
480
|
+
configure( ['src/'], :none )
|
|
481
|
+
@c.remove_project_yml_option_for_test( :paths, :test )
|
|
482
|
+
@c.merge_project_yml_for_test( { :paths => { :test => ['test/'] } } )
|
|
483
|
+
build_passes
|
|
484
|
+
|
|
485
|
+
runner = File.readlines( Dir.glob( 'build/test/runners/**/test_b_runner.c' ).first ).select { |line| line.include?( 'foo.h' ) }
|
|
486
|
+
expect(runner).to eq( ["#include \"#{File.expand_path( 'test/drivers/foo.h' )}\"\n"] )
|
|
487
|
+
end
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
# Ceedling generates a Partial's header into the build root, where the compiler's -I reaches
|
|
491
|
+
# it by its filename. The runner names it so, never by its absolute path.
|
|
492
|
+
[:none, :mocks, :all].each do |preprocessor|
|
|
493
|
+
it "include in the runner a Partial's generated header by its filename under :use_test_preprocessor #{preprocessor}" do
|
|
494
|
+
in_project do
|
|
495
|
+
write( 'src/calc.h', "#ifndef CALC_H\n#define CALC_H\nint calc(int a);\n#endif\n" )
|
|
496
|
+
write( 'src/calc.c', "#include \"calc.h\"\nstatic int twice(int a) { return 2 * a; }\nint calc(int a) { return twice( a ) + 1; }\n" )
|
|
497
|
+
write( 'test/test_calc.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
498
|
+
"#include TEST_PARTIAL_ALL_MODULE(calc)\nvoid test_twice(void) { TEST_ASSERT_EQUAL_INT(6, twice( 3 )); }\n" )
|
|
499
|
+
|
|
500
|
+
configure( ['src'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
|
|
501
|
+
build_passes
|
|
502
|
+
|
|
503
|
+
runner = File.readlines( Dir.glob( 'build/test/runners/**/test_calc_runner.c' ).first ).select { |line| line.include?( 'ceedling_partial_calc_impl.h' ) }
|
|
504
|
+
expect(runner).to eq( ["#include \"ceedling_partial_calc_impl.h\"\n"] )
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
# Reconciliation spells two same-named headers apart. A directory searched ahead of the
|
|
510
|
+
# project's, such as the one holding CMock's copy of one of them, must never capture the other.
|
|
511
|
+
it "keep the paths that tell two same-named headers apart" do
|
|
512
|
+
in_project do
|
|
513
|
+
write( 'src/hw/config.h', "#ifndef HW_CONFIG_H\n#define HW_CONFIG_H\ntypedef int hw_t;\n" \
|
|
514
|
+
"static inline int hw_peek(void) { return -1; }\nint hw_read(void);\n#endif\n" )
|
|
515
|
+
write( 'src/app/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define APP_GAIN 5\ntypedef int app_t;\n#endif\n" )
|
|
516
|
+
write( 'src/motor.h', "#ifndef MOTOR_H\n#define MOTOR_H\n#include \"hw/config.h\"\n#include \"app/config.h\"\nhw_t motor_run(app_t a);\n#endif\n" )
|
|
517
|
+
write( 'src/motor.c', "#include \"motor.h\"\n#include \"hw/config.h\"\n#include \"app/config.h\"\n" \
|
|
518
|
+
"hw_t motor_run(app_t a) { return APP_GAIN * a * hw_read(); }\n" )
|
|
519
|
+
write( 'test/test_motor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
520
|
+
"#include TEST_PARTIAL_PUBLIC_MODULE(motor)\n#include \"hw/mock_config.h\"\n" \
|
|
521
|
+
"void test_run(void) { hw_read_ExpectAndReturn(1); TEST_ASSERT_EQUAL_INT(5, motor_run(1)); }\n" )
|
|
522
|
+
|
|
523
|
+
configure( ['src/**'], :all, { :project => { :use_test_preprocessor => :all, :use_partials => true },
|
|
524
|
+
:cmock => { :treat_inlines => :include } } )
|
|
525
|
+
build_passes
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
# A mock includes its header through the folder the test named it by. A search path listing
|
|
530
|
+
# only the header's own directory joins no such folder.
|
|
531
|
+
[[:none, ['fff']], [:all, ['fff']], [:none, []]].each do |preprocessor, plugins|
|
|
532
|
+
kind = plugins.empty? ? 'a mock' : 'an FFF fake'
|
|
533
|
+
|
|
534
|
+
it "reach a header from #{kind} through its folder where a search path lists only the header's own directory under :use_test_preprocessor #{preprocessor}" do
|
|
535
|
+
in_project do
|
|
536
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
537
|
+
body = plugins.empty? ? 'foo_read_ExpectAndReturn(5);' : 'foo_read_fake.return_val = 5;'
|
|
538
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
539
|
+
"void test_reads(void) { #{body} TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
540
|
+
|
|
541
|
+
configure( ['src/drivers/**'], preprocessor, { :plugins => { :enabled => plugins } } )
|
|
542
|
+
build_passes
|
|
543
|
+
end
|
|
544
|
+
end
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
# A mock includes its header by the text the listed directory reaches it by. A directory
|
|
548
|
+
# added for the folder's parent would hold the project's string.h, shadowing the system's.
|
|
549
|
+
[[:mocks, [], :include], [:all, [], :include], [:none, ['fff'], :exclude]].each do |preprocessor, plugins, treat_inlines|
|
|
550
|
+
kind = plugins.empty? ? "a mock under :treat_inlines #{treat_inlines}" : 'an FFF fake'
|
|
551
|
+
|
|
552
|
+
it "keep a project header named like a system one out of reach of #{kind} through its folder under :use_test_preprocessor #{preprocessor}" do
|
|
553
|
+
in_project do
|
|
554
|
+
write( 'src/drivers/foo.h', "#ifndef FOO_H\n#define FOO_H\ntypedef int foo_t;\n" \
|
|
555
|
+
"static inline foo_t foo_peek(void) { return -1000; }\nfoo_t foo_read(void);\n#endif\n" )
|
|
556
|
+
write( 'src/string.h', "#error \"src/string.h shadowed <string.h>\"\n" )
|
|
557
|
+
body = plugins.empty? ? 'foo_read_ExpectAndReturn(5);' : 'foo_read_fake.return_val = 5;'
|
|
558
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include <string.h>\n#include \"drivers/mock_foo.h\"\n" \
|
|
559
|
+
"void test_reads(void) { #{body} TEST_ASSERT_EQUAL_INT(5, foo_read()); " \
|
|
560
|
+
"TEST_ASSERT_EQUAL_INT(0, (int)strlen(\"\")); }\n" )
|
|
561
|
+
|
|
562
|
+
configure( [plugins.empty? ? 'src/drivers/**' : 'src/drivers/'], preprocessor,
|
|
563
|
+
{ :plugins => { :enabled => plugins }, :cmock => { :treat_inlines => treat_inlines } } )
|
|
564
|
+
build_passes
|
|
565
|
+
end
|
|
566
|
+
end
|
|
567
|
+
end
|
|
568
|
+
|
|
569
|
+
# The compiler includes the header a mock's own #include reaches, even where the mock was
|
|
570
|
+
# located by a same-named header's trailing path
|
|
571
|
+
[:tests, :all].each do |preprocessor|
|
|
572
|
+
it "include in a mock the same-named header its folder reaches under :use_test_preprocessor #{preprocessor}" do
|
|
573
|
+
in_project do
|
|
574
|
+
write( 'src/drivers/foo.h', "#ifndef SDFOO_H\n#define SDFOO_H\ntypedef int foo_t;\n#define FOO_WHICH 1\nfoo_t foo_read(void);\n#endif\n" )
|
|
575
|
+
write( 'src/app/drivers/foo.h', "#ifndef ADFOO_H\n#define ADFOO_H\ntypedef int foo_t;\n#define FOO_WHICH 2\nfoo_t foo_read(void);\n#endif\n" )
|
|
576
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
577
|
+
"void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); " \
|
|
578
|
+
"TEST_ASSERT_EQUAL_INT(1, FOO_WHICH); }\n" )
|
|
579
|
+
|
|
580
|
+
configure( ['src/', 'src/app/drivers/'], preprocessor )
|
|
581
|
+
build_passes
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
end
|
|
585
|
+
|
|
586
|
+
# A format writing more than the text between quotes keeps the text CMock gives it
|
|
587
|
+
it "include in a mock its header through a project's :orig_header_include_fmt around the folder" do
|
|
588
|
+
in_project do
|
|
589
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
590
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
591
|
+
"void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
592
|
+
|
|
593
|
+
configure( ['src/drivers/'], :none, { :cmock => { :orig_header_include_fmt => '#include "../%s"' } } )
|
|
594
|
+
build_passes
|
|
595
|
+
end
|
|
596
|
+
end
|
|
597
|
+
|
|
598
|
+
# A fake writes no format, so the text a format keeps for CMock never reaches it
|
|
599
|
+
[:none, :all].each do |preprocessor|
|
|
600
|
+
it "reach a header through its search path from an FFF fake under a project's :orig_header_include_fmt around the folder, under :use_test_preprocessor #{preprocessor}" do
|
|
601
|
+
in_project do
|
|
602
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
603
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
604
|
+
"void test_reads(void) { foo_read_fake.return_val = 5; TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
605
|
+
|
|
606
|
+
configure( ['src/drivers/'], preprocessor, { :cmock => { :orig_header_include_fmt => '#include "../%s"' }, :plugins => { :enabled => ['fff'] } } )
|
|
607
|
+
build_passes
|
|
608
|
+
end
|
|
609
|
+
end
|
|
610
|
+
end
|
|
611
|
+
|
|
612
|
+
[:none, :all].each do |preprocessor|
|
|
613
|
+
it "reach a header below the search path from an FFF fake under :use_test_preprocessor #{preprocessor}" do
|
|
614
|
+
in_project do
|
|
615
|
+
write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
|
|
616
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
617
|
+
"void test_reads(void) { foo_read_fake.return_val = 5; TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
618
|
+
|
|
619
|
+
configure( ['src'], preprocessor, { :plugins => { :enabled => ['fff'] } } )
|
|
620
|
+
build_passes
|
|
621
|
+
end
|
|
622
|
+
end
|
|
623
|
+
end
|
|
624
|
+
end
|
|
625
|
+
|
|
626
|
+
# CMock writes its copy of a header beside the mock with :treat_inlines :include. The mock
|
|
627
|
+
# directory is a search path, but never one a real header is found through.
|
|
628
|
+
it "mocks a header from the project, never from CMock's copy of it, on later builds" do
|
|
629
|
+
in_project do
|
|
630
|
+
write( 'src/foo.h', "int foo_read(void);\n" )
|
|
631
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_foo.h\"\n" \
|
|
632
|
+
"void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
|
|
633
|
+
|
|
634
|
+
configure( ['src'], :none, { :cmock => { :treat_inlines => :include } } )
|
|
635
|
+
build_passes
|
|
636
|
+
expect(build_passes).to_not include( 'Multiple files matched' )
|
|
637
|
+
|
|
638
|
+
write( 'src/foo.h', "int foo_read(void);\nint foo_more(void);\n" )
|
|
639
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_foo.h\"\n" \
|
|
640
|
+
"void test_reads(void) { foo_more_ExpectAndReturn(6); TEST_ASSERT_EQUAL_INT(6, foo_more()); }\n" )
|
|
641
|
+
build_passes
|
|
642
|
+
end
|
|
643
|
+
end
|
|
644
|
+
|
|
645
|
+
# CMock's copy of a header outlives a switch to :exclude unless it is removed
|
|
646
|
+
it "sees an edit to a mocked header after :treat_inlines changes from :include to :exclude" do
|
|
647
|
+
in_project do
|
|
648
|
+
header = ->(k) { "#ifndef FOO_H\n#define FOO_H\n#define FOO_K #{k}\nstatic inline int foo_peek(void) { return FOO_K; }\nint foo_read(void);\n#endif\n" }
|
|
649
|
+
test = ->(k) { HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\nvoid test_k(void) { TEST_ASSERT_EQUAL_INT(#{k}, FOO_K); }\n" }
|
|
650
|
+
|
|
651
|
+
write( 'src/drivers/foo.h', header.( 1 ) )
|
|
652
|
+
write( 'test/test_c.c', test.( 1 ) )
|
|
653
|
+
configure( ['src/**'], :mocks, { :cmock => { :treat_inlines => :include } } )
|
|
654
|
+
build_passes
|
|
655
|
+
|
|
656
|
+
configure( ['src/**'], :mocks, { :cmock => { :treat_inlines => :exclude } } )
|
|
657
|
+
build_passes
|
|
658
|
+
expect(Dir.glob( 'build/test/mocks/**/foo.h' )).to be_empty
|
|
659
|
+
|
|
660
|
+
write( 'src/drivers/foo.h', header.( 2 ) )
|
|
661
|
+
write( 'test/test_c.c', test.( 2 ) )
|
|
662
|
+
build_passes
|
|
663
|
+
end
|
|
664
|
+
end
|
|
665
|
+
|
|
666
|
+
# A fake of a header's inline function would collide with the header's own definition. Under
|
|
667
|
+
# :treat_inlines :include a fake includes the header's inline-free copy beside it, as a mock does.
|
|
668
|
+
describe "an FFF fake under :treat_inlines :include" do
|
|
669
|
+
header = "#ifndef FOO_H\n#define FOO_H\nstatic inline int foo_peek(void) { return 7; }\nint foo_read(void);\n#endif\n"
|
|
670
|
+
test = HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
|
|
671
|
+
"void test_reads(void) { foo_read_fake.return_val = 3; foo_peek_fake.return_val = 9; " \
|
|
672
|
+
"TEST_ASSERT_EQUAL_INT(3, foo_read()); TEST_ASSERT_EQUAL_INT(9, foo_peek()); }\n"
|
|
673
|
+
|
|
674
|
+
[:none, :mocks].each do |preprocessor|
|
|
675
|
+
it "fakes a header's inline function under :use_test_preprocessor #{preprocessor}" do
|
|
676
|
+
in_project do
|
|
677
|
+
write( 'src/drivers/foo.h', header )
|
|
678
|
+
write( 'test/test_c.c', test )
|
|
679
|
+
|
|
680
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :plugins => { :enabled => ['fff'] } } )
|
|
681
|
+
build_passes
|
|
682
|
+
end
|
|
683
|
+
end
|
|
684
|
+
|
|
685
|
+
# A search path listing only the header's own directory reaches it by its filename alone
|
|
686
|
+
it "fakes the inline function of a header its search path reaches by its filename under :use_test_preprocessor #{preprocessor}" do
|
|
687
|
+
in_project do
|
|
688
|
+
write( 'src/drivers/foo.h', header )
|
|
689
|
+
write( 'test/test_c.c', test )
|
|
690
|
+
|
|
691
|
+
configure( ['src/drivers/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :plugins => { :enabled => ['fff'] } } )
|
|
692
|
+
build_passes
|
|
693
|
+
end
|
|
694
|
+
end
|
|
695
|
+
end
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
# A test's mock root stays on its search path. A copy of a header the test no longer mocks
|
|
699
|
+
# would shadow the header from there.
|
|
700
|
+
describe "a header a test stops mocking under :treat_inlines :include" do
|
|
701
|
+
header = ->(k) { "#ifndef FOO_H\n#define FOO_H\n#define FOO_K #{k}\nint foo_read(void);\n#endif\n" }
|
|
702
|
+
test = ->(k, includes) { HEADER_SEARCH_PREAMBLE + includes.map { |name| "#include \"#{name}\"\n" }.join +
|
|
703
|
+
"void test_k(void) { TEST_ASSERT_EQUAL_INT(#{k}, FOO_K); }\n" }
|
|
704
|
+
|
|
705
|
+
[[:none, [], ['drivers/mock_bar.h']], [:mocks, [], ['drivers/mock_bar.h']], [:tests, [], ['drivers/mock_bar.h']],
|
|
706
|
+
[:all, [], ['drivers/mock_bar.h']], [:none, [], []], [:all, [], []],
|
|
707
|
+
[:none, ['fff'], ['drivers/mock_bar.h']], [:all, ['fff'], ['drivers/mock_bar.h']]].each do |preprocessor, plugins, kept|
|
|
708
|
+
remaining = kept.empty? ? 'no mock' : (plugins.empty? ? 'another mock' : 'another FFF fake')
|
|
709
|
+
|
|
710
|
+
it "sees an edit to the header beside #{remaining} under :use_test_preprocessor #{preprocessor}" do
|
|
711
|
+
in_project do
|
|
712
|
+
write( 'src/drivers/foo.h', header.( 1 ) )
|
|
713
|
+
write( 'src/drivers/bar.h', "int bar_read(void);\n" )
|
|
714
|
+
write( 'test/test_c.c', test.( 1, ['drivers/mock_foo.h', 'drivers/mock_bar.h'] ) )
|
|
715
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :plugins => { :enabled => plugins } } )
|
|
716
|
+
build_passes
|
|
717
|
+
|
|
718
|
+
write( 'src/drivers/foo.h', header.( 2 ) )
|
|
719
|
+
write( 'test/test_c.c', test.( 2, ['drivers/foo.h'] + kept ) )
|
|
720
|
+
build_passes
|
|
721
|
+
end
|
|
722
|
+
end
|
|
723
|
+
end
|
|
724
|
+
|
|
725
|
+
# CMock names a mock and its copy with the header's own extension
|
|
726
|
+
[:none, :all].each do |preprocessor|
|
|
727
|
+
it "sees an edit to a header with another extension under :use_test_preprocessor #{preprocessor}" do
|
|
728
|
+
in_project do
|
|
729
|
+
write( 'src/drivers/foox.hpp', header.( 1 ) )
|
|
730
|
+
write( 'src/drivers/bar.h', "int bar_read(void);\n" )
|
|
731
|
+
write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp', 'drivers/mock_bar.h'] ) )
|
|
732
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :extension => { :header => ['.h', '.hpp'] } } )
|
|
733
|
+
build_passes
|
|
734
|
+
expect(build_passes).to_not include( 'Generating mock for' )
|
|
735
|
+
|
|
736
|
+
write( 'src/drivers/foox.hpp', header.( 2 ) )
|
|
737
|
+
write( 'test/test_c.c', test.( 2, ['drivers/foox.hpp', 'drivers/mock_bar.h'] ) )
|
|
738
|
+
build_passes
|
|
739
|
+
end
|
|
740
|
+
end
|
|
741
|
+
end
|
|
742
|
+
|
|
743
|
+
# An FFF fake names its files as CMock names a mock's, with the header's own extension
|
|
744
|
+
[:none, :all].each do |preprocessor|
|
|
745
|
+
it "sees an edit to a header with another extension beside an FFF fake under :use_test_preprocessor #{preprocessor}" do
|
|
746
|
+
in_project do
|
|
747
|
+
write( 'src/drivers/foox.hpp', header.( 1 ) )
|
|
748
|
+
write( 'src/drivers/bar.h', "int bar_read(void);\n" )
|
|
749
|
+
write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp', 'drivers/mock_bar.h'] ) )
|
|
750
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :extension => { :header => ['.h', '.hpp'] }, :plugins => { :enabled => ['fff'] } } )
|
|
751
|
+
build_passes
|
|
752
|
+
expect(build_passes).to_not include( 'Generating mock for' )
|
|
753
|
+
|
|
754
|
+
write( 'src/drivers/foox.hpp', header.( 2 ) )
|
|
755
|
+
write( 'test/test_c.c', test.( 2, ['drivers/foox.hpp', 'drivers/mock_bar.h'] ) )
|
|
756
|
+
build_passes
|
|
757
|
+
end
|
|
758
|
+
end
|
|
759
|
+
end
|
|
760
|
+
|
|
761
|
+
# A mock of foox.hpp stands in for that header only. The source of foox.h still links.
|
|
762
|
+
[:none, :tests].each do |preprocessor|
|
|
763
|
+
it "links the source of a header the test includes beside a mock of a header with another extension under :use_test_preprocessor #{preprocessor}" do
|
|
764
|
+
in_project do
|
|
765
|
+
write( 'src/drivers/foox.hpp', "#ifndef FOOX_H\n#define FOOX_H\n#define FOOX_K 1\nint foox_read(void);\n#endif\n" )
|
|
766
|
+
write( 'src/drivers/foox.h', "#ifndef FOOX_C_H\n#define FOOX_C_H\nint foox_c_api(void);\n#endif\n" )
|
|
767
|
+
write( 'src/drivers/foox.c', "#include \"foox.h\"\nint foox_c_api(void) { return 5; }\n" )
|
|
768
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foox.h\"\n#include \"drivers/mock_foox.hpp\"\n" \
|
|
769
|
+
"void test_k(void) { TEST_ASSERT_EQUAL_INT(1, FOOX_K); TEST_ASSERT_EQUAL_INT(5, foox_c_api()); }\n" )
|
|
770
|
+
configure( ['src/**'], preprocessor, { :extension => { :header => ['.h', '.hpp'] } } )
|
|
771
|
+
build_passes
|
|
772
|
+
end
|
|
773
|
+
end
|
|
774
|
+
end
|
|
775
|
+
|
|
776
|
+
# A mock of foox.h stands in for the header foox.c implements, though the test includes foox.hpp
|
|
777
|
+
[:none, :tests].each do |preprocessor|
|
|
778
|
+
it "links no source for a mocked header beside a real header with another extension under :use_test_preprocessor #{preprocessor}" do
|
|
779
|
+
in_project do
|
|
780
|
+
write( 'src/drivers/foox.hpp', "#ifndef FOOX_HPP\n#define FOOX_HPP\n#define FOOX_K 1\n#endif\n" )
|
|
781
|
+
write( 'src/drivers/foox.h', "#ifndef FOOX_H\n#define FOOX_H\nint foox_c_api(void);\n#endif\n" )
|
|
782
|
+
write( 'src/drivers/foox.c', "#include \"foox.h\"\nint foox_c_api(void) { return 5; }\n" )
|
|
783
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foox.hpp\"\n#include \"drivers/mock_foox.h\"\n" \
|
|
784
|
+
"void test_k(void) { foox_c_api_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(1, FOOX_K); TEST_ASSERT_EQUAL_INT(3, foox_c_api()); }\n" )
|
|
785
|
+
configure( ['src/**'], preprocessor, { :extension => { :header => ['.h', '.hpp'] } } )
|
|
786
|
+
build_passes
|
|
787
|
+
end
|
|
788
|
+
end
|
|
789
|
+
end
|
|
790
|
+
|
|
791
|
+
# A mock of a header with another extension leaves the same-named source in place, however
|
|
792
|
+
# the test reaches the .h header that source implements
|
|
793
|
+
it "links a named source beside a mock of a header with another extension whose stem another header shares" do
|
|
794
|
+
in_project do
|
|
795
|
+
write( 'src/drivers/foox.hpp', "#ifndef FOOX_HPP\n#define FOOX_HPP\n#define FOOX_K 1\nint foox_read(void);\n#endif\n" )
|
|
796
|
+
write( 'src/drivers/foox.h', "#ifndef FOOX_H\n#define FOOX_H\nint foox_c_api(void);\n#endif\n" )
|
|
797
|
+
write( 'src/drivers/foox.c', "#include \"foox.h\"\nint foox_c_api(void) { return 5; }\n" )
|
|
798
|
+
write( 'src/drivers/bar.h', "#ifndef BAR_H\n#define BAR_H\n#include \"foox.h\"\n#endif\n" )
|
|
799
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/bar.h\"\n#include \"drivers/mock_foox.hpp\"\n" \
|
|
800
|
+
"TEST_SOURCE_FILE(\"src/drivers/foox.c\")\n" \
|
|
801
|
+
"void test_k(void) { TEST_ASSERT_EQUAL_INT(1, FOOX_K); TEST_ASSERT_EQUAL_INT(5, foox_c_api()); }\n" )
|
|
802
|
+
configure( ['src/**'], :none, { :extension => { :header => ['.h', '.hpp'] } } )
|
|
803
|
+
build_passes
|
|
804
|
+
end
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
# The source of a header the test both includes and mocks stays out of the link
|
|
808
|
+
it "links no source for a header the test includes and mocks under :use_test_preprocessor none" do
|
|
809
|
+
in_project do
|
|
810
|
+
write( 'src/drivers/foo.h', "int foo_read(void);\n" )
|
|
811
|
+
write( 'src/drivers/foo.c', "#include \"foo.h\"\nint foo_read(void) { return 5; }\n" )
|
|
812
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n#include \"drivers/mock_foo.h\"\n" \
|
|
813
|
+
"void test_k(void) { foo_read_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, foo_read()); }\n" )
|
|
814
|
+
configure( ['src/**'], :none )
|
|
815
|
+
build_passes
|
|
816
|
+
end
|
|
817
|
+
end
|
|
818
|
+
|
|
819
|
+
# Stage 4 places a stand-in for the mock under the extension the test's #include names
|
|
820
|
+
it "places a stand-in for a mock of a header with another extension that the preprocessor reads under :use_test_preprocessor tests" do
|
|
821
|
+
in_project do
|
|
822
|
+
write( 'src/drivers/foox.hpp', header.( 1 ) )
|
|
823
|
+
write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp'] ) )
|
|
824
|
+
configure( ['src/**'], :tests, { :extension => { :header => ['.h', '.hpp'] } } )
|
|
825
|
+
expect(build_passes).to_not include( 'Failed to generate directive-only' )
|
|
826
|
+
|
|
827
|
+
write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp'] ) + "// edited\n" )
|
|
828
|
+
expect(build_passes).to_not include( 'Failed to generate directive-only' )
|
|
829
|
+
end
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
# Stage 4 sees the test's #includes before any mock is planned. A rebuild generates nothing.
|
|
833
|
+
it "generates no mock again on a rebuild after the test stops mocking a header under :use_test_preprocessor all" do
|
|
834
|
+
in_project do
|
|
835
|
+
write( 'src/drivers/foo.h', header.( 1 ) )
|
|
836
|
+
write( 'src/drivers/bar.h', "int bar_read(void);\n" )
|
|
837
|
+
write( 'test/test_c.c', test.( 1, ['drivers/mock_foo.h', 'drivers/mock_bar.h'] ) )
|
|
838
|
+
configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
|
|
839
|
+
build_passes
|
|
840
|
+
|
|
841
|
+
write( 'test/test_c.c', test.( 1, ['drivers/foo.h', 'drivers/mock_bar.h'] ) )
|
|
842
|
+
build_passes
|
|
843
|
+
expect(build_passes).to_not include( 'Generating mock for' )
|
|
844
|
+
end
|
|
845
|
+
end
|
|
846
|
+
|
|
847
|
+
# Only the preprocessor names a mock whose #include a macro computes
|
|
848
|
+
it "generates no mock again on a rebuild for a mock only the preprocessor names under :use_test_preprocessor all" do
|
|
849
|
+
in_project do
|
|
850
|
+
write( 'src/drivers/widget.h', "#ifndef WIDGET_H\n#define WIDGET_H\nint widget_read(void);\n#endif\n" )
|
|
851
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#define WIDGET_MOCK \"drivers/mock_widget.h\"\n#include WIDGET_MOCK\n" \
|
|
852
|
+
"void test_w(void) { widget_read_ExpectAndReturn(7); TEST_ASSERT_EQUAL_INT(7, widget_read()); }\n" )
|
|
853
|
+
configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
|
|
854
|
+
build_passes
|
|
855
|
+
|
|
856
|
+
expect(build_passes).to_not include( 'Generating mock for' )
|
|
857
|
+
end
|
|
858
|
+
end
|
|
859
|
+
|
|
860
|
+
# A same-named mock in another folder names no copy but its own
|
|
861
|
+
it "sees an edit to a header the test stops mocking beside a same-named mock under :use_test_preprocessor all" do
|
|
862
|
+
in_project do
|
|
863
|
+
write( 'src/a/drivers/foo.h', "#ifndef AFOO_H\n#define AFOO_H\nint fa_read(void);\n#endif\n" )
|
|
864
|
+
write( 'src/b/drivers/foo.h', header.( 1 ) )
|
|
865
|
+
write( 'test/test_c.c', test.( 1, ['a/drivers/mock_foo.h', 'b/drivers/mock_foo.h'] ) )
|
|
866
|
+
configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
|
|
867
|
+
build_passes
|
|
868
|
+
|
|
869
|
+
write( 'src/b/drivers/foo.h', header.( 2 ) )
|
|
870
|
+
write( 'test/test_c.c', test.( 2, ['a/drivers/mock_foo.h', 'b/drivers/foo.h'] ) )
|
|
871
|
+
build_passes
|
|
872
|
+
end
|
|
873
|
+
end
|
|
874
|
+
|
|
875
|
+
# The text names a mock the preprocessor no longer reaches
|
|
876
|
+
it "sees an edit to a header a test's conditional #include stops mocking under :use_test_preprocessor all" do
|
|
877
|
+
in_project do
|
|
878
|
+
write( 'src/cfg.h', "#ifndef CFG_H\n#define CFG_H\n#define USE_MOCK 1\n#endif\n" )
|
|
879
|
+
write( 'src/drivers/foo.h', header.( 1 ) )
|
|
880
|
+
write( 'src/drivers/bar.h', "int bar_read(void);\n" )
|
|
881
|
+
conditional = ->(k) { HEADER_SEARCH_PREAMBLE + "#include \"cfg.h\"\n#include \"drivers/mock_bar.h\"\n#if USE_MOCK\n" \
|
|
882
|
+
"#include \"drivers/mock_foo.h\"\n#else\n#include \"drivers/foo.h\"\n#endif\n" \
|
|
883
|
+
"void test_k(void) { TEST_ASSERT_EQUAL_INT(#{k}, FOO_K); }\n" }
|
|
884
|
+
write( 'test/test_c.c', conditional.( 1 ) )
|
|
885
|
+
configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
|
|
886
|
+
build_passes
|
|
887
|
+
|
|
888
|
+
write( 'src/cfg.h', "#ifndef CFG_H\n#define CFG_H\n#define USE_MOCK 0\n#endif\n" )
|
|
889
|
+
write( 'src/drivers/foo.h', header.( 2 ) )
|
|
890
|
+
write( 'test/test_c.c', conditional.( 2 ) )
|
|
891
|
+
build_passes
|
|
892
|
+
end
|
|
893
|
+
end
|
|
894
|
+
|
|
895
|
+
# CMock's own #include text reaches only its copy where a search path lists only the header's
|
|
896
|
+
# own directory. Stage 4 reads a stand-in for the mock while its copy is set aside.
|
|
897
|
+
[:tests, :all].each do |preprocessor|
|
|
898
|
+
it "collects a rebuilt test's #includes through a mock whose header only its copy reaches by CMock's text under :use_test_preprocessor #{preprocessor}" do
|
|
899
|
+
in_project do
|
|
900
|
+
write( 'src/drivers/foo.h', "#ifndef FOO_H\n#define FOO_H\n#define FOO_K 1\nstatic inline int foo_peek(void) { return 7; }\nint foo_read(void);\n#endif\n" )
|
|
901
|
+
test_file = HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n#if FOO_K == 2\nTEST_SOURCE_FILE(\"nothere.c\")\n#endif\n" \
|
|
902
|
+
"void test_r(void) { foo_read_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, foo_read()); }\n"
|
|
903
|
+
write( 'test/test_c.c', test_file )
|
|
904
|
+
configure( ['src/drivers/**'], preprocessor, { :cmock => { :treat_inlines => :include } } )
|
|
905
|
+
build_passes
|
|
906
|
+
|
|
907
|
+
write( 'test/test_c.c', test_file + "// edited\n" )
|
|
908
|
+
expect(build_passes).to_not include( 'Failed to generate directive-only' )
|
|
909
|
+
end
|
|
910
|
+
end
|
|
911
|
+
end
|
|
912
|
+
|
|
913
|
+
# A mocked header decides which other mocks the test needs, as stage 4 reads it
|
|
914
|
+
it "sees an edit to a mocked header that decides the test's other mocks under :use_test_preprocessor all" do
|
|
915
|
+
in_project do
|
|
916
|
+
cfg = ->(on) { "#ifndef CFG_H\n#define CFG_H\n#{on ? '' : '//'}#define TWO_ON\nint cfg_read(void);\n#endif\n" }
|
|
917
|
+
write( 'src/cfg.h', cfg.( false ) )
|
|
918
|
+
write( 'src/two.h', "int two_read(void);\n" )
|
|
919
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_cfg.h\"\n#ifdef TWO_ON\n#include \"mock_two.h\"\n#endif\n" \
|
|
920
|
+
"void test_t(void) {\n#ifdef TWO_ON\n two_read_ExpectAndReturn(4); TEST_ASSERT_EQUAL_INT(4, two_read());\n#endif\n}\n" )
|
|
921
|
+
configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
|
|
922
|
+
build_passes
|
|
923
|
+
|
|
924
|
+
write( 'src/cfg.h', cfg.( true ) )
|
|
925
|
+
build_passes
|
|
926
|
+
end
|
|
927
|
+
end
|
|
928
|
+
|
|
929
|
+
# A header named with the mock prefix is reached through another header, since the test's
|
|
930
|
+
# own #include of it would name a mock
|
|
931
|
+
it "sees an edit to a header whose name starts with the mock prefix" do
|
|
932
|
+
in_project do
|
|
933
|
+
motor = ->(k) { "#ifndef MOTOR_H\n#define MOTOR_H\n#define MOTOR_K #{k}\nint motor_read(void);\n#endif\n" }
|
|
934
|
+
|
|
935
|
+
write( 'src/drivers/motor.h', motor.( 1 ) )
|
|
936
|
+
write( 'src/drivers/bar.h', "int bar_read(void);\n" )
|
|
937
|
+
write( 'src/app/wrap.h', "#include \"drivers/motor.h\"\n" )
|
|
938
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mmotor.h\"\n#include \"drivers/mbar.h\"\n" \
|
|
939
|
+
"void test_k(void) { TEST_ASSERT_EQUAL_INT(1, MOTOR_K); }\n" )
|
|
940
|
+
configure( ['src/**'], :none, { :cmock => { :mock_prefix => 'm', :treat_inlines => :include } } )
|
|
941
|
+
build_passes
|
|
942
|
+
|
|
943
|
+
write( 'src/drivers/motor.h', motor.( 2 ) )
|
|
944
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"app/wrap.h\"\n#include \"drivers/mbar.h\"\n" \
|
|
945
|
+
"void test_k(void) { TEST_ASSERT_EQUAL_INT(2, MOTOR_K); }\n" )
|
|
946
|
+
build_passes
|
|
947
|
+
end
|
|
948
|
+
end
|
|
949
|
+
|
|
950
|
+
# Mock preprocessing reaches the header through the mock root too
|
|
951
|
+
it "preprocesses a remaining mock's header with the edited header it includes under :use_test_preprocessor mocks" do
|
|
952
|
+
in_project do
|
|
953
|
+
bar = "#ifndef BAR_H\n#define BAR_H\n#include \"drivers/foo.h\"\n#if FOO_K == 1\nint bar_one(void);\n#else\nint bar_two(void);\n#endif\n"
|
|
954
|
+
call = ->(fn, k) { "void test_k(void) { #{fn}_ExpectAndReturn(#{k}); TEST_ASSERT_EQUAL_INT(#{k}, #{fn}()); }\n" }
|
|
955
|
+
|
|
956
|
+
write( 'src/drivers/foo.h', header.( 1 ) )
|
|
957
|
+
write( 'src/drivers/bar.h', bar + "#endif\n" )
|
|
958
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n#include \"drivers/mock_bar.h\"\n" + call.( 'bar_one', 1 ) )
|
|
959
|
+
configure( ['src/**'], :mocks, { :cmock => { :treat_inlines => :include } } )
|
|
960
|
+
build_passes
|
|
961
|
+
|
|
962
|
+
write( 'src/drivers/foo.h', header.( 2 ) )
|
|
963
|
+
write( 'src/drivers/bar.h', bar + "int bar_more(void);\n#endif\n" )
|
|
964
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n#include \"drivers/mock_bar.h\"\n" + call.( 'bar_two', 2 ) )
|
|
965
|
+
build_passes
|
|
966
|
+
end
|
|
967
|
+
end
|
|
968
|
+
end
|
|
969
|
+
|
|
970
|
+
# Mock preprocessing reads a mocked header's own #includes as the compiler does, through the
|
|
971
|
+
# project's headers. An edit to one of those headers alone changes what the mock declares.
|
|
972
|
+
describe "a header a mocked header includes" do
|
|
973
|
+
foo = ->(k) { "#ifndef FOO_H\n#define FOO_H\n#define FOO_K #{k}\nint foo_read(void);\n#endif\n" }
|
|
974
|
+
bar = ->(extra) { "#ifndef BAR_H\n#define BAR_H\n#include \"drivers/foo.h\"\n#if FOO_K == 1\nint bar_one(void);\n#else\nint bar_two(void);\n#endif\n" \
|
|
975
|
+
"#{extra}#endif\n" }
|
|
976
|
+
test = ->(mocks, fn, k) { HEADER_SEARCH_PREAMBLE + mocks.map { |name| "#include \"drivers/#{name}\"\n" }.join +
|
|
977
|
+
"void test_k(void) { #{fn}_ExpectAndReturn(#{k}); TEST_ASSERT_EQUAL_INT(#{k}, #{fn}()); }\n" }
|
|
978
|
+
|
|
979
|
+
# A rebuild with nothing changed preprocesses and generates no mock
|
|
980
|
+
def rebuild_skips_mocks(count)
|
|
981
|
+
output = build_passes
|
|
982
|
+
expect(output).to_not include( 'Generating mock for' )
|
|
983
|
+
expect(output).to include( "Skipping mock preprocessing for #{count} #{count == 1 ? 'mock' : 'mocks'} (nothing changed)" )
|
|
984
|
+
end
|
|
985
|
+
|
|
986
|
+
[:mocks, :all].product( [:include, :exclude] ).each do |preprocessor, treat_inlines|
|
|
987
|
+
it "regenerates a mock after an edit to that header alone under :use_test_preprocessor #{preprocessor} and :treat_inlines #{treat_inlines}" do
|
|
988
|
+
in_project do
|
|
989
|
+
write( 'src/drivers/foo.h', foo.( 1 ) )
|
|
990
|
+
write( 'src/drivers/bar.h', bar.( '' ) )
|
|
991
|
+
write( 'test/test_c.c', test.( ['mock_bar.h'], 'bar_one', 1 ) )
|
|
992
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => treat_inlines } } )
|
|
993
|
+
build_passes
|
|
994
|
+
|
|
995
|
+
write( 'src/drivers/foo.h', foo.( 2 ) )
|
|
996
|
+
write( 'test/test_c.c', test.( ['mock_bar.h'], 'bar_two', 2 ) )
|
|
997
|
+
build_passes
|
|
998
|
+
rebuild_skips_mocks( 1 )
|
|
999
|
+
end
|
|
1000
|
+
end
|
|
1001
|
+
end
|
|
1002
|
+
|
|
1003
|
+
# A build records the headers its mock preprocessing entered, so the build after it finds each mock current
|
|
1004
|
+
[:mocks, :all].each do |preprocessor|
|
|
1005
|
+
it "preprocesses no mock in the first rebuild after a fresh build under :use_test_preprocessor #{preprocessor}" do
|
|
1006
|
+
in_project do
|
|
1007
|
+
write( 'src/drivers/foo.h', foo.( 1 ) )
|
|
1008
|
+
write( 'src/drivers/bar.h', bar.( '' ) )
|
|
1009
|
+
write( 'test/test_c.c', test.( ['mock_bar.h'], 'bar_one', 1 ) )
|
|
1010
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include } } )
|
|
1011
|
+
build_passes
|
|
1012
|
+
|
|
1013
|
+
output = build_passes
|
|
1014
|
+
expect(output).to_not include( 'Preprocessing header file for follow-on mock handling' )
|
|
1015
|
+
expect(output).to include( 'Skipping mock preprocessing for 1 mock (nothing changed)' )
|
|
1016
|
+
end
|
|
1017
|
+
end
|
|
1018
|
+
end
|
|
1019
|
+
|
|
1020
|
+
# CMock writes its copy of a mocked header beside the mock. A mock generated after stage 9
|
|
1021
|
+
# puts its copy in step with the header.
|
|
1022
|
+
[:mocks, :all].each do |preprocessor|
|
|
1023
|
+
it "regenerates a mock from that header, never another mock's copy of it, under :use_test_preprocessor #{preprocessor}" do
|
|
1024
|
+
in_project do
|
|
1025
|
+
write( 'src/drivers/foo.h', foo.( 1 ) )
|
|
1026
|
+
write( 'src/drivers/bar.h', bar.( '' ) )
|
|
1027
|
+
write( 'test/test_c.c', test.( ['mock_foo.h', 'mock_bar.h'], 'bar_one', 1 ) )
|
|
1028
|
+
configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include } } )
|
|
1029
|
+
build_passes
|
|
1030
|
+
|
|
1031
|
+
write( 'src/drivers/foo.h', foo.( 2 ) )
|
|
1032
|
+
write( 'src/drivers/bar.h', bar.( "int bar_extra(void);\n" ) )
|
|
1033
|
+
write( 'test/test_c.c', test.( ['mock_foo.h', 'mock_bar.h'], 'bar_two', 2 ) )
|
|
1034
|
+
build_passes
|
|
1035
|
+
rebuild_skips_mocks( 2 )
|
|
1036
|
+
end
|
|
1037
|
+
end
|
|
1038
|
+
end
|
|
1039
|
+
end
|
|
1040
|
+
|
|
1041
|
+
# Partials are generated before mocks are preprocessed, so a mocked header can include one
|
|
1042
|
+
# as the compiler finds it.
|
|
1043
|
+
describe "a Partial header a mocked header includes" do
|
|
1044
|
+
[:mocks, :all].product( [:include, :exclude] ).each do |preprocessor, treat_inlines|
|
|
1045
|
+
it "is found by mock preprocessing under :use_test_preprocessor #{preprocessor} and :treat_inlines #{treat_inlines}" do
|
|
1046
|
+
in_project do
|
|
1047
|
+
write( 'src/drivers/foo.h', "int foo_read(void);\n" )
|
|
1048
|
+
write( 'src/drivers/foo.c', "#include \"foo.h\"\nint foo_read(void) { return 1; }\n" )
|
|
1049
|
+
write( 'src/drivers/bar.h', "#ifndef BAR_H\n#define BAR_H\n#include \"ceedling_partial_foo_impl.h\"\nint bar_one(void);\n#endif\n" )
|
|
1050
|
+
write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
|
|
1051
|
+
"#include TEST_PARTIAL_PUBLIC_MODULE(foo)\n#include \"drivers/mock_bar.h\"\n" \
|
|
1052
|
+
"void test_a(void) { bar_one_ExpectAndReturn(1); TEST_ASSERT_EQUAL_INT(1, bar_one()); TEST_ASSERT_EQUAL_INT(1, foo_read()); }\n" )
|
|
1053
|
+
|
|
1054
|
+
configure( ['src/**'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true },
|
|
1055
|
+
:cmock => { :treat_inlines => treat_inlines } } )
|
|
1056
|
+
build_passes
|
|
1057
|
+
end
|
|
1058
|
+
end
|
|
1059
|
+
end
|
|
1060
|
+
end
|
|
1061
|
+
|
|
1062
|
+
# FFF replaces CMock, writing a different file from the same configuration
|
|
1063
|
+
it "regenerates a mock when the FFF plugin is turned on or off" do
|
|
1064
|
+
in_project do
|
|
1065
|
+
cmock_test = HEADER_SEARCH_PREAMBLE + "#include \"mock_led.h\"\nvoid test_level(void) { led_level_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, led_level()); }\n"
|
|
1066
|
+
fff_test = HEADER_SEARCH_PREAMBLE + "#include \"mock_led.h\"\nvoid test_level(void) { led_level_fake.return_val = 3; TEST_ASSERT_EQUAL_INT(3, led_level()); }\n"
|
|
1067
|
+
|
|
1068
|
+
write( 'src/led.h', "int led_level(void);\n" )
|
|
1069
|
+
write( 'test/test_c.c', cmock_test )
|
|
1070
|
+
configure( ['src'], :none )
|
|
1071
|
+
build_passes
|
|
1072
|
+
without_fff = File.read( 'project.yml' )
|
|
1073
|
+
|
|
1074
|
+
write( 'test/test_c.c', fff_test )
|
|
1075
|
+
@c.merge_project_yml_for_test( { :plugins => { :enabled => ['fff'] } } )
|
|
1076
|
+
build_passes
|
|
1077
|
+
|
|
1078
|
+
write( 'test/test_c.c', cmock_test )
|
|
1079
|
+
File.write( 'project.yml', without_fff )
|
|
1080
|
+
build_passes
|
|
1081
|
+
end
|
|
1082
|
+
end
|
|
1083
|
+
end
|