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
|
@@ -10,8 +10,10 @@ require 'spec_helper'
|
|
|
10
10
|
require 'ceedling/includes/includes'
|
|
11
11
|
require 'ceedling/partials/partializer'
|
|
12
12
|
require 'ceedling/partials/partials'
|
|
13
|
+
require 'ceedling/partials/partializer_config'
|
|
13
14
|
require 'ceedling/reportinator'
|
|
14
15
|
require 'ceedling/c_extractor/c_extractor_types'
|
|
16
|
+
require 'ceedling/c_extractor/c_extractor_defined_type'
|
|
15
17
|
require 'ostruct'
|
|
16
18
|
|
|
17
19
|
describe Partializer do
|
|
@@ -26,6 +28,7 @@ describe Partializer do
|
|
|
26
28
|
# Guard extraction reads the module's own header text through these two.
|
|
27
29
|
@preprocessinator_reconstructor = double("PreprocessinatorReconstructor")
|
|
28
30
|
@file_wrapper = double("FileWrapper")
|
|
31
|
+
@partializer_reconciler = double("PartializerReconciler")
|
|
29
32
|
|
|
30
33
|
@configurator = double( "Configurator" )
|
|
31
34
|
allow(@configurator).to receive(:paths_test).and_return( ['test'] )
|
|
@@ -35,15 +38,16 @@ describe Partializer do
|
|
|
35
38
|
|
|
36
39
|
@partializer = described_class.new(
|
|
37
40
|
{
|
|
38
|
-
:configurator
|
|
39
|
-
:partializer_helper
|
|
40
|
-
:
|
|
41
|
-
:
|
|
42
|
-
:
|
|
41
|
+
:configurator => @configurator,
|
|
42
|
+
:partializer_helper => @partializer_helper,
|
|
43
|
+
:partializer_reconciler => @partializer_reconciler,
|
|
44
|
+
:file_finder => @file_finder,
|
|
45
|
+
:c_extractor => @c_extractor,
|
|
46
|
+
:file_path_utils => @file_path_utils,
|
|
43
47
|
:preprocessinator_reconstructor => @preprocessinator_reconstructor,
|
|
44
|
-
:file_wrapper
|
|
45
|
-
:reportinator
|
|
46
|
-
:loginator
|
|
48
|
+
:file_wrapper => @file_wrapper,
|
|
49
|
+
:reportinator => @reportinator,
|
|
50
|
+
:loginator => @loginator
|
|
47
51
|
}
|
|
48
52
|
)
|
|
49
53
|
|
|
@@ -58,10 +62,11 @@ describe Partializer do
|
|
|
58
62
|
# A stand-in for another partialized module's config. Only the two visibility types matter to
|
|
59
63
|
# include remapping: a non-nil mocks type means that module has a generated interface header
|
|
60
64
|
# to redirect to.
|
|
61
|
-
def make_partial_config(mocks_type: nil, tests_type: nil)
|
|
65
|
+
def make_partial_config(mocks_type: nil, tests_type: nil, header: nil)
|
|
62
66
|
OpenStruct.new(
|
|
63
67
|
mocks: OpenStruct.new(type: mocks_type),
|
|
64
|
-
tests: OpenStruct.new(type: tests_type)
|
|
68
|
+
tests: OpenStruct.new(type: tests_type),
|
|
69
|
+
header: OpenStruct.new(filepath: header)
|
|
65
70
|
)
|
|
66
71
|
end
|
|
67
72
|
|
|
@@ -276,7 +281,7 @@ describe Partializer do
|
|
|
276
281
|
context "#validate_config" do
|
|
277
282
|
it "delegates to three validation helpers in order" do
|
|
278
283
|
c_module = double("CModule")
|
|
279
|
-
config = double("Config")
|
|
284
|
+
config = double("Config", fallback?: false)
|
|
280
285
|
name = "test_foo"
|
|
281
286
|
|
|
282
287
|
expect(@partializer_helper).to receive(:validate_function_names_exist)
|
|
@@ -286,11 +291,11 @@ describe Partializer do
|
|
|
286
291
|
expect(@partializer_helper).to receive(:validate_additions_subtractions_visibility)
|
|
287
292
|
.with(c_module, config, name).ordered
|
|
288
293
|
|
|
289
|
-
@partializer.validate_config(c_module: c_module, config: config, name: name
|
|
294
|
+
@partializer.validate_config(c_module: c_module, config: config, name: name)
|
|
290
295
|
end
|
|
291
296
|
|
|
292
297
|
# The fourth check only applies where preprocessing resolved less than it could, so the
|
|
293
|
-
# accurate path must not pay for it.
|
|
298
|
+
# accurate path must not pay for it. The Partial's own files say which path ran.
|
|
294
299
|
it "does not check fallback sufficiency when preprocessing was accurate" do
|
|
295
300
|
allow(@partializer_helper).to receive(:validate_function_names_exist)
|
|
296
301
|
allow(@partializer_helper).to receive(:validate_no_additions_subtractions_overlap)
|
|
@@ -299,7 +304,7 @@ describe Partializer do
|
|
|
299
304
|
expect(@partializer_helper).not_to receive(:validate_fallback_sufficiency)
|
|
300
305
|
|
|
301
306
|
@partializer.validate_config(
|
|
302
|
-
c_module: double("CModule"), config: double("Config"), name: 'test_foo'
|
|
307
|
+
c_module: double("CModule"), config: double("Config", fallback?: false), name: 'test_foo'
|
|
303
308
|
)
|
|
304
309
|
end
|
|
305
310
|
|
|
@@ -308,10 +313,10 @@ describe Partializer do
|
|
|
308
313
|
allow(@partializer_helper).to receive(:validate_no_additions_subtractions_overlap)
|
|
309
314
|
allow(@partializer_helper).to receive(:validate_additions_subtractions_visibility)
|
|
310
315
|
|
|
311
|
-
config =
|
|
316
|
+
config = PartializerConfig::Config.new(
|
|
312
317
|
module: 'Foo',
|
|
313
|
-
header: Partials::ConfigFileInfo.new( filepath: 'src/Foo.h' ),
|
|
314
|
-
source: Partials::ConfigFileInfo.new( filepath: 'src/Foo.c' )
|
|
318
|
+
header: Partials::ConfigFileInfo.new( filepath: 'src/Foo.h', assembled_filepath: 'build/Foo.h', fallback: true ),
|
|
319
|
+
source: Partials::ConfigFileInfo.new( filepath: 'src/Foo.c', assembled_filepath: 'build/Foo.c', fallback: true )
|
|
315
320
|
)
|
|
316
321
|
|
|
317
322
|
allow(@file_wrapper).to receive(:read).with('src/Foo.h').and_return('header text')
|
|
@@ -324,7 +329,7 @@ describe Partializer do
|
|
|
324
329
|
)
|
|
325
330
|
|
|
326
331
|
@partializer.validate_config(
|
|
327
|
-
c_module: double("CModule"), config: config, name: 'test_foo'
|
|
332
|
+
c_module: double("CModule"), config: config, name: 'test_foo'
|
|
328
333
|
)
|
|
329
334
|
end
|
|
330
335
|
|
|
@@ -335,9 +340,9 @@ describe Partializer do
|
|
|
335
340
|
allow(@partializer_helper).to receive(:validate_no_additions_subtractions_overlap)
|
|
336
341
|
allow(@partializer_helper).to receive(:validate_additions_subtractions_visibility)
|
|
337
342
|
|
|
338
|
-
config =
|
|
343
|
+
config = PartializerConfig::Config.new(
|
|
339
344
|
module: 'Foo',
|
|
340
|
-
header: Partials::ConfigFileInfo.new( filepath: 'src/Foo.h' ),
|
|
345
|
+
header: Partials::ConfigFileInfo.new( filepath: 'src/Foo.h', assembled_filepath: 'build/Foo.h', fallback: true ),
|
|
341
346
|
source: Partials::ConfigFileInfo.new( filepath: nil )
|
|
342
347
|
)
|
|
343
348
|
|
|
@@ -348,9 +353,32 @@ describe Partializer do
|
|
|
348
353
|
)
|
|
349
354
|
|
|
350
355
|
@partializer.validate_config(
|
|
351
|
-
c_module: double("CModule"), config: config, name: 'test_foo'
|
|
356
|
+
c_module: double("CModule"), config: config, name: 'test_foo'
|
|
352
357
|
)
|
|
353
358
|
end
|
|
359
|
+
|
|
360
|
+
# Fallback's limits belong to the file that fell back, so an accurately preprocessed one is
|
|
361
|
+
# never refused for a computed #include fallback can't resolve
|
|
362
|
+
it "checks only the module files preprocessed in fallback" do
|
|
363
|
+
allow(@partializer_helper).to receive(:validate_function_names_exist)
|
|
364
|
+
allow(@partializer_helper).to receive(:validate_no_additions_subtractions_overlap)
|
|
365
|
+
allow(@partializer_helper).to receive(:validate_additions_subtractions_visibility)
|
|
366
|
+
|
|
367
|
+
config = PartializerConfig::Config.new(
|
|
368
|
+
module: 'Foo',
|
|
369
|
+
header: Partials::ConfigFileInfo.new( filepath: 'src/Foo.h', assembled_filepath: 'build/Foo.h', fallback: true ),
|
|
370
|
+
source: Partials::ConfigFileInfo.new( filepath: 'src/Foo.c', assembled_filepath: 'build/Foo.c', fallback: false )
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
allow(@file_wrapper).to receive(:read).with('src/Foo.h').and_return('header text')
|
|
374
|
+
expect(@file_wrapper).not_to receive(:read).with('src/Foo.c')
|
|
375
|
+
|
|
376
|
+
expect(@partializer_helper).to receive(:validate_fallback_sufficiency).with(
|
|
377
|
+
name: 'test_foo', module_name: 'Foo', files: { 'src/Foo.h' => 'header text' }
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
@partializer.validate_config( c_module: double("CModule"), config: config, name: 'test_foo' )
|
|
381
|
+
end
|
|
354
382
|
end
|
|
355
383
|
|
|
356
384
|
###
|
|
@@ -361,9 +389,9 @@ describe Partializer do
|
|
|
361
389
|
# Read from the original header, not the reconstituted copy: that copy carries a synthetic
|
|
362
390
|
# guard which #sanitize then strips, and fallback preprocessing excludes a guard from the
|
|
363
391
|
# macros it recovers. Neither is a dependable source for the name to spoof.
|
|
364
|
-
it "reads
|
|
392
|
+
it "reads the module's own header and returns the guard found" do
|
|
365
393
|
expect(@file_wrapper).to receive(:read)
|
|
366
|
-
.with('src/Foo.h'
|
|
394
|
+
.with('src/Foo.h')
|
|
367
395
|
.and_return("#ifndef FOO_H\n#define FOO_H\n")
|
|
368
396
|
allow(@preprocessinator_reconstructor).to receive(:extract_include_guard)
|
|
369
397
|
.with("#ifndef FOO_H\n#define FOO_H\n")
|
|
@@ -471,6 +499,30 @@ describe Partializer do
|
|
|
471
499
|
expect(mod.macro_definitions).to eq(lookalikes)
|
|
472
500
|
end
|
|
473
501
|
|
|
502
|
+
# The real header's own guard survives preprocessing too, and every generated file states it
|
|
503
|
+
# deliberately. A carried copy would only repeat it.
|
|
504
|
+
it "removes the real header's own guard when given it" do
|
|
505
|
+
guard = make_macro('#define MY_MODULE_H')
|
|
506
|
+
kept = make_macro('#define MY_DEFINE 1')
|
|
507
|
+
mod = make_module(macros: [guard, kept])
|
|
508
|
+
|
|
509
|
+
@partializer.sanitize(mod, include_guard: 'MY_MODULE_H')
|
|
510
|
+
|
|
511
|
+
expect(mod.macro_definitions).to eq([kept])
|
|
512
|
+
expect(mod.element_sequence).to eq([kept])
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
# A macro whose name merely begins with the guard's, and a guard-named macro carrying a
|
|
516
|
+
# value, are neither of them the guard statement
|
|
517
|
+
it "keeps a macro whose name only resembles the real header's guard" do
|
|
518
|
+
lookalikes = [make_macro('#define MY_MODULE_H_LIMIT 8'), make_macro('#define MY_MODULE_H 2')]
|
|
519
|
+
mod = make_module(macros: lookalikes)
|
|
520
|
+
|
|
521
|
+
@partializer.sanitize(mod, include_guard: 'MY_MODULE_H')
|
|
522
|
+
|
|
523
|
+
expect(mod.macro_definitions).to eq(lookalikes)
|
|
524
|
+
end
|
|
525
|
+
|
|
474
526
|
it "does not remove non-macro elements from element_sequence" do
|
|
475
527
|
generated = make_macro('#ifndef GEN0123ABCD_C_H_CEEDLING')
|
|
476
528
|
other_elem = double('CFunction', text: 'void foo(void){}')
|
|
@@ -497,6 +549,373 @@ describe Partializer do
|
|
|
497
549
|
### validate_extracted_functions()
|
|
498
550
|
###
|
|
499
551
|
|
|
552
|
+
context "#plan_carry" do
|
|
553
|
+
before(:each) do
|
|
554
|
+
allow(@file_wrapper).to receive(:read).with( 'src/engine.h' ).and_return( "int engine_get(void);\n" )
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
it "returns the helper's plan for the module and both selections" do
|
|
558
|
+
c_module = CExtractorTypes::CModule.new
|
|
559
|
+
impl = [Partials.manufacture_function_definition( name: 'get', signature: 'int get(void)', code_block: '' )]
|
|
560
|
+
plan = Partials::CarryPlan.new
|
|
561
|
+
|
|
562
|
+
expect(@partializer_helper).to receive(:plan_carry).with(
|
|
563
|
+
c_module: c_module, impl: impl, interface: nil, fallback: false, header_guarded: true
|
|
564
|
+
).and_return( plan )
|
|
565
|
+
|
|
566
|
+
result = @partializer.plan_carry(
|
|
567
|
+
test: 'test_foo', c_module: c_module, impl: impl, interface: nil, header_guarded: true, config: carry_config( 'Foo' )
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
expect( result ).to equal( plan )
|
|
571
|
+
end
|
|
572
|
+
|
|
573
|
+
# Fallback can keep two copies of one function from a file it read without resolving it
|
|
574
|
+
it "plans for fallback when any file the module is extracted from fell back" do
|
|
575
|
+
config = carry_config( 'Foo' )
|
|
576
|
+
config.source.fallback = true
|
|
577
|
+
|
|
578
|
+
expect(@partializer_helper).to receive(:plan_carry).with( hash_including( fallback: true ) ).and_return( Partials::CarryPlan.new )
|
|
579
|
+
|
|
580
|
+
@partializer.plan_carry( test: 'test_foo', c_module: CExtractorTypes::CModule.new, impl: [], interface: nil, header_guarded: true, config: config )
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
def plan_for(prototypes: [], helpers: [], skipped: [])
|
|
584
|
+
plan = Partials::CarryPlan.new
|
|
585
|
+
prototypes.each { |sig, reason| plan.add_prototype( CExtractorTypes::CFunctionDeclaration.new( name: sig[/(\w+)\(/, 1], signature: sig ), reason ) }
|
|
586
|
+
helpers.each do |name, reason|
|
|
587
|
+
plan.add_helper( Partials.manufacture_function_definition( name: name, signature: "int #{name}(int v)", code_block: '' ), reason )
|
|
588
|
+
end
|
|
589
|
+
skipped.each { |name, kind| plan.skip( name, kind ) }
|
|
590
|
+
plan
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
def carry_with(plan, pragma_once: false)
|
|
594
|
+
allow(@partializer_helper).to receive(:plan_carry).and_return( plan )
|
|
595
|
+
allow(@preprocessinator_reconstructor).to receive(:pragma_once?).and_return( pragma_once )
|
|
596
|
+
@partializer.plan_carry(
|
|
597
|
+
test: 'test_engine', c_module: CExtractorTypes::CModule.new, impl: [], interface: nil, header_guarded: true,
|
|
598
|
+
config: carry_config( 'engine' )
|
|
599
|
+
)
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
# A Partial whose files were preprocessed accurately, as stages 6 and 7 record them
|
|
603
|
+
def carry_config(name, raw: {})
|
|
604
|
+
PartializerConfig::Config.new(
|
|
605
|
+
module: name,
|
|
606
|
+
header: Partials::ConfigFileInfo.new( filepath: "src/#{name}.h", assembled_filepath: "build/#{name}.h", raw_directives_only_filepath: raw[:header] ),
|
|
607
|
+
source: Partials::ConfigFileInfo.new( filepath: "src/#{name}.c", assembled_filepath: "build/#{name}.c", raw_directives_only_filepath: raw[:source] )
|
|
608
|
+
)
|
|
609
|
+
end
|
|
610
|
+
|
|
611
|
+
# A match in the original file can't belong to a header that file includes
|
|
612
|
+
it "locates each carried prototype in the text of the file it came from" do
|
|
613
|
+
header_proto = CExtractorTypes::CFunctionDeclaration.new( name: 'tick', signature: 'int tick(void);', origin: :header )
|
|
614
|
+
source_proto = CExtractorTypes::CFunctionDeclaration.new( name: 'twice', signature: 'extern inline int twice(void);', origin: :source )
|
|
615
|
+
plan = Partials::CarryPlan.new
|
|
616
|
+
plan.add_prototype( header_proto, 'external: no body in module' )
|
|
617
|
+
plan.add_prototype( source_proto, 'external: no body in module' )
|
|
618
|
+
allow(@partializer_helper).to receive(:plan_carry).and_return( plan )
|
|
619
|
+
allow(@file_wrapper).to receive(:read).with('src/engine.h').and_return('header text')
|
|
620
|
+
allow(@file_wrapper).to receive(:read).with('src/engine.c').and_return('source text')
|
|
621
|
+
|
|
622
|
+
expect(@partializer_helper).to receive(:associate_declaration_line_numbers).with(
|
|
623
|
+
decls: [header_proto], filepath: 'src/engine.h', text: 'header text'
|
|
624
|
+
)
|
|
625
|
+
expect(@partializer_helper).to receive(:associate_declaration_line_numbers).with(
|
|
626
|
+
decls: [source_proto], filepath: 'src/engine.c', text: 'source text'
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
carry_with( plan )
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
# A prototype with no known file, or from a file the module lacks, is written without a #line
|
|
633
|
+
it "searches no file for a prototype whose file is unknown" do
|
|
634
|
+
unknown = CExtractorTypes::CFunctionDeclaration.new( name: 'tick', signature: 'int tick(void);', origin: nil )
|
|
635
|
+
source = CExtractorTypes::CFunctionDeclaration.new( name: 'twice', signature: 'int twice(void);', origin: :source )
|
|
636
|
+
plan = Partials::CarryPlan.new
|
|
637
|
+
plan.add_prototype( unknown, 'external: no body in module' )
|
|
638
|
+
plan.add_prototype( source, 'external: no body in module' )
|
|
639
|
+
allow(@partializer_helper).to receive(:plan_carry).and_return( plan )
|
|
640
|
+
|
|
641
|
+
expect(@file_wrapper).not_to receive(:read)
|
|
642
|
+
expect(@partializer_helper).not_to receive(:associate_declaration_line_numbers)
|
|
643
|
+
|
|
644
|
+
config = carry_config( 'engine' )
|
|
645
|
+
config.source = Partials::ConfigFileInfo.new
|
|
646
|
+
@partializer.plan_carry(
|
|
647
|
+
test: 'test_engine', c_module: CExtractorTypes::CModule.new, impl: [], interface: nil, header_guarded: true, config: config
|
|
648
|
+
)
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
it "reads no file when nothing is carried" do
|
|
652
|
+
expect(@file_wrapper).not_to receive(:read)
|
|
653
|
+
|
|
654
|
+
carry_with( Partials::CarryPlan.new )
|
|
655
|
+
end
|
|
656
|
+
|
|
657
|
+
it "lists everything carried, with reasons, at debug verbosity" do
|
|
658
|
+
plan = plan_for(
|
|
659
|
+
prototypes: [['int board_tick(void);', 'external: no body in module'], ['int engine_poll(void);', 'left out: body not selected']],
|
|
660
|
+
helpers: [['clamp', 'helper: referenced by `engine_get`']]
|
|
661
|
+
)
|
|
662
|
+
|
|
663
|
+
expect(@loginator).to receive(:log_list).with(
|
|
664
|
+
['`int board_tick(void);` (external: no body in module)',
|
|
665
|
+
'`int engine_poll(void);` (left out: body not selected)',
|
|
666
|
+
'`clamp()` (helper: referenced by `engine_get`)'],
|
|
667
|
+
'Carried into Partial test_engine::engine implementation:',
|
|
668
|
+
Verbosity::DEBUG
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
carry_with( plan )
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
it "lists nothing when nothing is carried" do
|
|
675
|
+
expect(@loginator).not_to receive(:log_list)
|
|
676
|
+
|
|
677
|
+
carry_with( Partials::CarryPlan.new )
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
it "gives notice of a helper fallback left with more than one definition" do
|
|
681
|
+
plan = plan_for( skipped: [['clamp', :helper_conflict]] )
|
|
682
|
+
|
|
683
|
+
expect(@loginator).to receive(:log).with(
|
|
684
|
+
"Partial test_engine::engine \u23e9\ufe0f Not carrying helper `clamp()`: fallback preprocessing found more than one definition. Add `+clamp` if a selected function needs it",
|
|
685
|
+
Verbosity::COMPLAIN,
|
|
686
|
+
LogLabels::NOTICE
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
carry_with( plan )
|
|
690
|
+
end
|
|
691
|
+
|
|
692
|
+
it "gives one notice naming every helper an unguarded module header kept out" do
|
|
693
|
+
plan = plan_for( skipped: [
|
|
694
|
+
['clamp', :unguarded_helper],
|
|
695
|
+
['counter', :unguarded_helper]
|
|
696
|
+
] )
|
|
697
|
+
|
|
698
|
+
allow(@loginator).to receive(:log)
|
|
699
|
+
|
|
700
|
+
carry_with( plan )
|
|
701
|
+
|
|
702
|
+
expect(@loginator).to have_received(:log).with(
|
|
703
|
+
"Partial test_engine::engine \u23e9\ufe0f Not carrying helpers `clamp()`, `counter()` from src/engine.h.\n" \
|
|
704
|
+
"Selected functions call these helpers, but src/engine.h has no include guard. Without a guard\n" \
|
|
705
|
+
"a Partial cannot stand in for the header everywhere it is included, and a carried copy could\n" \
|
|
706
|
+
"collide with the real one.\n" \
|
|
707
|
+
"\n" \
|
|
708
|
+
"OPTIONS:\n" \
|
|
709
|
+
" 1. Give src/engine.h an include guard so the Partial can stand in for it.\n" \
|
|
710
|
+
" 2. Select the helpers with `+name` (for example `+clamp`). This works only when no other\n" \
|
|
711
|
+
" header this module includes pulls in src/engine.h.\n" \
|
|
712
|
+
"\n" \
|
|
713
|
+
"See the docs on Partials conventions.\n",
|
|
714
|
+
Verbosity::COMPLAIN,
|
|
715
|
+
LogLabels::NOTICE
|
|
716
|
+
)
|
|
717
|
+
expect(@loginator).to have_received(:log).once
|
|
718
|
+
end
|
|
719
|
+
|
|
720
|
+
# Ceedling stands a Partial in for a header only by defining its include guard
|
|
721
|
+
it "explains that a #pragma once module header keeps its helpers out, as the toolchain guidance does" do
|
|
722
|
+
plan = plan_for( skipped: [['clamp', :unguarded_helper], ['counter', :unguarded_helper]] )
|
|
723
|
+
|
|
724
|
+
allow(@loginator).to receive(:log)
|
|
725
|
+
|
|
726
|
+
carry_with( plan, pragma_once: true )
|
|
727
|
+
|
|
728
|
+
expect(@loginator).to have_received(:log).with( <<~NOTICE, Verbosity::COMPLAIN, LogLabels::NOTICE )
|
|
729
|
+
Partial test_engine::engine ⏩️ Not carrying helpers `clamp()`, `counter()` from src/engine.h.
|
|
730
|
+
|
|
731
|
+
HOW THIS HAPPENS:
|
|
732
|
+
• Selected functions call these helpers.
|
|
733
|
+
• src/engine.h uses `#pragma once`, which is not an include guard.
|
|
734
|
+
• A Partial stands in for a header everywhere it's included by defining the header's include guard. Ceedling relies on include guards for this.
|
|
735
|
+
• Without one, a carried copy could collide with the real one.
|
|
736
|
+
|
|
737
|
+
OPTIONS:
|
|
738
|
+
1. Replace `#pragma once` in src/engine.h with an include guard so the Partial can stand in for it.
|
|
739
|
+
2. Select the helpers with `+name` (for example `+clamp`). This works only when no other header this module includes pulls in src/engine.h.
|
|
740
|
+
|
|
741
|
+
See the docs on Partials conventions.
|
|
742
|
+
NOTICE
|
|
743
|
+
end
|
|
744
|
+
|
|
745
|
+
it "words the unguarded-header notice for a single helper" do
|
|
746
|
+
plan = plan_for( skipped: [['clamp', :unguarded_helper]] )
|
|
747
|
+
|
|
748
|
+
expect(@loginator).to receive(:log).with(
|
|
749
|
+
a_string_including( 'Not carrying helper `clamp()` from src/engine.h.', 'call this helper', 'Select the helper with' ),
|
|
750
|
+
Verbosity::COMPLAIN,
|
|
751
|
+
LogLabels::NOTICE
|
|
752
|
+
)
|
|
753
|
+
|
|
754
|
+
carry_with( plan )
|
|
755
|
+
end
|
|
756
|
+
|
|
757
|
+
# Additions can't name a function the module only declares, so no `+name` hint follows
|
|
758
|
+
it "gives notice of a prototype fallback left with conflicting declarations" do
|
|
759
|
+
plan = plan_for( skipped: [['board_tick', :prototype_conflict]] )
|
|
760
|
+
|
|
761
|
+
expect(@loginator).to receive(:log).with(
|
|
762
|
+
"Partial test_engine::engine \u23e9\ufe0f Not carrying `board_tick()`: fallback preprocessing found conflicting declarations",
|
|
763
|
+
Verbosity::COMPLAIN,
|
|
764
|
+
LogLabels::NOTICE
|
|
765
|
+
)
|
|
766
|
+
|
|
767
|
+
carry_with( plan )
|
|
768
|
+
end
|
|
769
|
+
|
|
770
|
+
context "marking extern variables of incomplete types" do
|
|
771
|
+
def extern_var(name, type)
|
|
772
|
+
CExtractorTypes::CVariableDeclaration.new( name: name, type: type, decorators: ['extern'], text: "#{type} #{name};" )
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
# A typedef as the extractor records it, with the tag and the name it reads
|
|
776
|
+
def typedef(text)
|
|
777
|
+
CExtractorTypes::CStatement.new( text: text, kind: :typedef, **CExtractorDefinedType.names( text ) )
|
|
778
|
+
end
|
|
779
|
+
|
|
780
|
+
# Each file's raw directives-only copy, recorded only where `copies` gives its text, keyed by
|
|
781
|
+
# :header or :source. Files and copies are read as bytes, since the search needs nothing more.
|
|
782
|
+
def stub_texts(header:, source:, copies: {})
|
|
783
|
+
allow(@file_wrapper).to receive(:read_binary).with('src/engine.h').and_return( header )
|
|
784
|
+
allow(@file_wrapper).to receive(:read_binary).with('src/engine.c').and_return( source )
|
|
785
|
+
@copies = copies.to_h { |file, _| [file, "raw/src/engine.#{file == :header ? 'h' : 'c'}"] }
|
|
786
|
+
copies.each { |file, copy| allow(@file_wrapper).to receive(:read_binary).with( @copies[file] ).and_return( copy ) }
|
|
787
|
+
end
|
|
788
|
+
|
|
789
|
+
# A file preprocessed in fallback records no raw copy, whatever is on disk
|
|
790
|
+
def incomplete_for(c_module, fallback: false)
|
|
791
|
+
allow(@partializer_helper).to receive(:plan_carry).and_return( Partials::CarryPlan.new )
|
|
792
|
+
config = carry_config( 'engine', raw: fallback ? {} : @copies.to_h )
|
|
793
|
+
[config.header, config.source].each { |file| file.fallback = fallback }
|
|
794
|
+
@partializer.plan_carry(
|
|
795
|
+
test: 'test_engine', c_module: c_module, impl: [], interface: nil, header_guarded: true, config: config
|
|
796
|
+
).incomplete
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
it "marks a struct variable whose struct the module only declares" do
|
|
800
|
+
stub_texts( header: "struct handle_s;\nextern struct handle_s handle;\n", source: "#include \"engine.h\"\n" )
|
|
801
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'handle', 'struct handle_s' )] )
|
|
802
|
+
|
|
803
|
+
expect( incomplete_for( c_module ) ).to eq( Set['handle'] )
|
|
804
|
+
end
|
|
805
|
+
|
|
806
|
+
# Such a keyword changes how the variable is stored or accessed, not which type it holds
|
|
807
|
+
it "marks a thread-local or atomic struct variable whose struct the module only declares" do
|
|
808
|
+
stub_texts( header: "struct handle_s;\ntypedef struct handle_s handle_t;\n", source: '' )
|
|
809
|
+
c_module = CExtractorTypes::CModule.new(
|
|
810
|
+
variable_declarations: [
|
|
811
|
+
extern_var( 'local', '_Thread_local struct handle_s' ),
|
|
812
|
+
extern_var( 'shared', '_Atomic struct handle_s' ),
|
|
813
|
+
extern_var( 'named', '__thread _Atomic handle_t' )
|
|
814
|
+
],
|
|
815
|
+
type_definitions: [typedef( 'typedef struct handle_s handle_t;' )]
|
|
816
|
+
)
|
|
817
|
+
|
|
818
|
+
expect( incomplete_for( c_module ) ).to eq( Set['local', 'shared', 'named'] )
|
|
819
|
+
end
|
|
820
|
+
|
|
821
|
+
# A pointer is complete whatever it points to, so a function pointer can always be defined
|
|
822
|
+
it "leaves alone a function pointer returning a struct the module only declares" do
|
|
823
|
+
stub_texts( header: "struct handle_s;\nextern struct handle_s (*make_handle)(void);\n", source: '' )
|
|
824
|
+
maker = CExtractorTypes::CVariableDeclaration.new(
|
|
825
|
+
name: 'make_handle', type: 'struct handle_s', declarator: '(*make_handle)(void)',
|
|
826
|
+
decorators: ['extern'], text: 'struct handle_s (*make_handle)(void);'
|
|
827
|
+
)
|
|
828
|
+
|
|
829
|
+
expect( incomplete_for( CExtractorTypes::CModule.new( variable_declarations: [maker] ) ) ).to be_empty
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
it "follows a typedef to the struct it names" do
|
|
833
|
+
stub_texts( header: "typedef struct handle_s handle_t;\nextern handle_t handle;\n", source: '' )
|
|
834
|
+
c_module = CExtractorTypes::CModule.new(
|
|
835
|
+
variable_declarations: [extern_var( 'handle', 'handle_t' )],
|
|
836
|
+
type_definitions: [typedef( 'typedef struct handle_s handle_t;' )]
|
|
837
|
+
)
|
|
838
|
+
|
|
839
|
+
expect( incomplete_for( c_module ) ).to eq( Set['handle'] )
|
|
840
|
+
end
|
|
841
|
+
|
|
842
|
+
it "follows a typedef to the union it names" do
|
|
843
|
+
stub_texts( header: "typedef union word_u word_t;\nextern word_t word;\n", source: '' )
|
|
844
|
+
c_module = CExtractorTypes::CModule.new(
|
|
845
|
+
variable_declarations: [extern_var( 'word', 'word_t' )],
|
|
846
|
+
type_definitions: [typedef( 'typedef union word_u word_t;' )]
|
|
847
|
+
)
|
|
848
|
+
|
|
849
|
+
expect( incomplete_for( c_module ) ).to eq( Set['word'] )
|
|
850
|
+
end
|
|
851
|
+
|
|
852
|
+
it "leaves alone a variable whose struct the module defines" do
|
|
853
|
+
stub_texts( header: "extern struct point_s origin;\n", source: "struct point_s { int x; };\n" )
|
|
854
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'origin', 'struct point_s' )] )
|
|
855
|
+
|
|
856
|
+
expect( incomplete_for( c_module ) ).to be_empty
|
|
857
|
+
end
|
|
858
|
+
|
|
859
|
+
# A directives-only copy holds the text of every header its file includes
|
|
860
|
+
it "leaves alone a variable whose struct an included header defines" do
|
|
861
|
+
stub_texts(
|
|
862
|
+
header: "#include \"point.h\"\nextern struct point_s origin;\n", source: '',
|
|
863
|
+
copies: { header: "struct point_s {\n int x;\n};\nextern struct point_s origin;\n" }
|
|
864
|
+
)
|
|
865
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'origin', 'struct point_s' )] )
|
|
866
|
+
|
|
867
|
+
expect( incomplete_for( c_module ) ).to be_empty
|
|
868
|
+
end
|
|
869
|
+
|
|
870
|
+
# An earlier raw copy on disk says nothing about a file preprocessed in fallback
|
|
871
|
+
it "reads no raw copy under fallback preprocessing" do
|
|
872
|
+
stub_texts(
|
|
873
|
+
header: "#include \"point.h\"\nextern struct point_s origin;\n", source: '',
|
|
874
|
+
copies: { header: "struct point_s {\n int x;\n};\n" }
|
|
875
|
+
)
|
|
876
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'origin', 'struct point_s' )] )
|
|
877
|
+
|
|
878
|
+
expect(@file_wrapper).not_to receive(:read_binary).with('raw/src/engine.h')
|
|
879
|
+
expect( incomplete_for( c_module, fallback: true ) ).to eq( Set['origin'] )
|
|
880
|
+
end
|
|
881
|
+
|
|
882
|
+
it "still searches the module's own files under fallback preprocessing" do
|
|
883
|
+
stub_texts( header: "extern struct point_s origin;\n", source: "struct point_s { int x; };\n" )
|
|
884
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'origin', 'struct point_s' )] )
|
|
885
|
+
|
|
886
|
+
expect( incomplete_for( c_module, fallback: true ) ).to be_empty
|
|
887
|
+
end
|
|
888
|
+
|
|
889
|
+
# A file read as bytes may hold CRLF line endings and bytes no encoding accepts
|
|
890
|
+
it "finds the completing definition in text read as bytes" do
|
|
891
|
+
stub_texts( header: "extern struct point_s origin;\n".b, source: "/* \xFF */\r\nstruct point_s\r\n{ int x; };\r\n".b )
|
|
892
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'origin', 'struct point_s' )] )
|
|
893
|
+
|
|
894
|
+
expect( incomplete_for( c_module ) ).to be_empty
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
# A tag that merely ends in the variable's tag completes a different type
|
|
898
|
+
it "does not take a longer tag's definition for the variable's own" do
|
|
899
|
+
stub_texts( header: "extern struct point_s origin;\n", source: "struct my_point_s { int x; };\n" )
|
|
900
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [extern_var( 'origin', 'struct point_s' )] )
|
|
901
|
+
|
|
902
|
+
expect( incomplete_for( c_module ) ).to eq( Set['origin'] )
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
it "reads no file when no extern variable names a struct or union" do
|
|
906
|
+
expect(@file_wrapper).not_to receive(:read)
|
|
907
|
+
expect(@file_wrapper).not_to receive(:read_binary)
|
|
908
|
+
c_module = CExtractorTypes::CModule.new( variable_declarations: [
|
|
909
|
+
extern_var( 'count', 'int' ),
|
|
910
|
+
extern_var( 'next', 'struct node_s*' ),
|
|
911
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'own', type: 'struct node_s', text: 'struct node_s own;' )
|
|
912
|
+
] )
|
|
913
|
+
|
|
914
|
+
expect( incomplete_for( c_module ) ).to be_empty
|
|
915
|
+
end
|
|
916
|
+
end
|
|
917
|
+
end
|
|
918
|
+
|
|
500
919
|
context "#validate_extracted_functions" do
|
|
501
920
|
def make_impl(name)
|
|
502
921
|
Partials.manufacture_function_definition(
|
|
@@ -580,6 +999,245 @@ describe Partializer do
|
|
|
580
999
|
end
|
|
581
1000
|
end
|
|
582
1001
|
|
|
1002
|
+
###
|
|
1003
|
+
### plan_interface_extras()
|
|
1004
|
+
###
|
|
1005
|
+
|
|
1006
|
+
context "#plan_interface_extras" do
|
|
1007
|
+
before(:each) do
|
|
1008
|
+
@config = OpenStruct.new( module: 'sensor', fallback?: false, header: OpenStruct.new( filepath: 'src/sensor.h' ) )
|
|
1009
|
+
allow(@file_wrapper).to receive(:read).with( 'src/sensor.h' ).and_return( "int sensor_read(void);\n" )
|
|
1010
|
+
allow(@preprocessinator_reconstructor).to receive(:pragma_once?).with( "int sensor_read(void);\n" ).and_return( false )
|
|
1011
|
+
end
|
|
1012
|
+
|
|
1013
|
+
def plan_with(extras)
|
|
1014
|
+
allow(@partializer_helper).to receive(:plan_interface_extras)
|
|
1015
|
+
.with( c_module: :module, interface: :interface, fallback: false, header_guarded: true ).and_return( extras )
|
|
1016
|
+
|
|
1017
|
+
return @partializer.plan_interface_extras(
|
|
1018
|
+
test: 'test_sensor', c_module: :module, interface: :interface, header_guarded: true, config: @config
|
|
1019
|
+
)
|
|
1020
|
+
end
|
|
1021
|
+
|
|
1022
|
+
it "lists what the mock keeps at DEBUG" do
|
|
1023
|
+
extras = Partials::InterfaceExtras.new( items: [
|
|
1024
|
+
CExtractorTypes::CFunctionDefinition.new( name: 'twice' ),
|
|
1025
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'table', decorators: ['static'] ),
|
|
1026
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'count', decorators: ['extern'] ),
|
|
1027
|
+
CExtractorTypes::CFunctionDeclaration.new( name: 'init' )
|
|
1028
|
+
] )
|
|
1029
|
+
|
|
1030
|
+
expect(@loginator).to receive(:log_list).with(
|
|
1031
|
+
['`twice()` (helper)', '`table` (static variable)', '`count` (extern declaration)', '`init()` (prototype)'],
|
|
1032
|
+
'Kept in the mock of Partial test_sensor::sensor:', Verbosity::DEBUG
|
|
1033
|
+
)
|
|
1034
|
+
|
|
1035
|
+
expect( plan_with( extras ) ).to equal( extras )
|
|
1036
|
+
end
|
|
1037
|
+
|
|
1038
|
+
it "explains what an unguarded header's mock leaves behind" do
|
|
1039
|
+
extras = Partials::InterfaceExtras.new( withheld: [
|
|
1040
|
+
CExtractorTypes::CFunctionDefinition.new( name: 'twice' ),
|
|
1041
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'table', decorators: ['static'] )
|
|
1042
|
+
] )
|
|
1043
|
+
|
|
1044
|
+
expect(@loginator).to receive(:log).with( <<~NOTICE, Verbosity::COMPLAIN, LogLabels::NOTICE )
|
|
1045
|
+
Partial test_sensor::sensor ⏩️ Its mock leaves helper `twice()` and variable `table` from src/sensor.h behind.
|
|
1046
|
+
src/sensor.h has no include guard. Without a guard the mock can't stand in for the header everywhere
|
|
1047
|
+
it's included, and a copy could collide with the real one. Code that uses these compiles only where
|
|
1048
|
+
another #include brings in the real header.
|
|
1049
|
+
|
|
1050
|
+
Give src/sensor.h an include guard so the mock keeps them.
|
|
1051
|
+
|
|
1052
|
+
See the docs on Partials conventions.
|
|
1053
|
+
NOTICE
|
|
1054
|
+
|
|
1055
|
+
plan_with( extras )
|
|
1056
|
+
end
|
|
1057
|
+
|
|
1058
|
+
# Ceedling stands a mock in for a header only by defining its include guard
|
|
1059
|
+
it "explains that a #pragma once header's mock leaves items behind, since #pragma once is not an include guard" do
|
|
1060
|
+
allow(@preprocessinator_reconstructor).to receive(:pragma_once?).with( "int sensor_read(void);\n" ).and_return( true )
|
|
1061
|
+
extras = Partials::InterfaceExtras.new( withheld: [
|
|
1062
|
+
CExtractorTypes::CFunctionDefinition.new( name: 'twice' ),
|
|
1063
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'table', decorators: ['static'] )
|
|
1064
|
+
] )
|
|
1065
|
+
|
|
1066
|
+
expect(@loginator).to receive(:log).with( <<~NOTICE, Verbosity::COMPLAIN, LogLabels::NOTICE )
|
|
1067
|
+
Partial test_sensor::sensor ⏩️ Its mock leaves helper `twice()` and variable `table` from src/sensor.h behind.
|
|
1068
|
+
|
|
1069
|
+
HOW THIS HAPPENS:
|
|
1070
|
+
• src/sensor.h uses `#pragma once`, which is not an include guard.
|
|
1071
|
+
• A mock stands in for a header everywhere it's included by defining the header's include guard. Ceedling relies on include guards for this.
|
|
1072
|
+
• Without one, a kept copy could collide with the real one, so the mock leaves them out.
|
|
1073
|
+
• Code that uses these compiles only where another #include brings in the real header.
|
|
1074
|
+
|
|
1075
|
+
Replace `#pragma once` in src/sensor.h with an include guard so the mock keeps them.
|
|
1076
|
+
|
|
1077
|
+
See the docs on Partials conventions.
|
|
1078
|
+
NOTICE
|
|
1079
|
+
|
|
1080
|
+
plan_with( extras )
|
|
1081
|
+
end
|
|
1082
|
+
|
|
1083
|
+
it "names one item it leaves behind in the singular" do
|
|
1084
|
+
extras = Partials::InterfaceExtras.new( withheld: [CExtractorTypes::CFunctionDefinition.new( name: 'twice' )] )
|
|
1085
|
+
|
|
1086
|
+
expect(@loginator).to receive(:log) do |notice, *|
|
|
1087
|
+
expect( notice ).to include( 'Its mock leaves helper `twice()` from src/sensor.h behind.' )
|
|
1088
|
+
expect( notice ).to include( 'Code that uses it compiles' )
|
|
1089
|
+
expect( notice ).to include( 'so the mock keeps it.' )
|
|
1090
|
+
end
|
|
1091
|
+
|
|
1092
|
+
plan_with( extras )
|
|
1093
|
+
end
|
|
1094
|
+
|
|
1095
|
+
it "names several helpers and variables in the plural" do
|
|
1096
|
+
extras = Partials::InterfaceExtras.new( withheld: [
|
|
1097
|
+
CExtractorTypes::CFunctionDefinition.new( name: 'twice' ), CExtractorTypes::CFunctionDefinition.new( name: 'half' ),
|
|
1098
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'a' ), CExtractorTypes::CVariableDeclaration.new( name: 'b' )
|
|
1099
|
+
] )
|
|
1100
|
+
|
|
1101
|
+
expect(@loginator).to receive(:log) do |notice, *|
|
|
1102
|
+
expect( notice ).to include( 'Its mock leaves helpers `twice()`, `half()` and variables `a`, `b` from src/sensor.h behind.' )
|
|
1103
|
+
end
|
|
1104
|
+
|
|
1105
|
+
plan_with( extras )
|
|
1106
|
+
end
|
|
1107
|
+
|
|
1108
|
+
it "says nothing when the mock withholds nothing" do
|
|
1109
|
+
expect(@loginator).not_to receive(:log)
|
|
1110
|
+
|
|
1111
|
+
plan_with( Partials::InterfaceExtras.new )
|
|
1112
|
+
end
|
|
1113
|
+
end
|
|
1114
|
+
|
|
1115
|
+
###
|
|
1116
|
+
### explain_tested_mock()
|
|
1117
|
+
###
|
|
1118
|
+
|
|
1119
|
+
context "#explain_tested_mock" do
|
|
1120
|
+
before(:each) do
|
|
1121
|
+
@config = OpenStruct.new( module: 'port', fallback?: false, header: OpenStruct.new( filepath: 'src/port.h', includes: [] ),
|
|
1122
|
+
source: OpenStruct.new( includes: [UserInclude.new( 'port.h' )] ) )
|
|
1123
|
+
@engine = OpenStruct.new( module: 'engine', header: OpenStruct.new( includes: [] ),
|
|
1124
|
+
source: OpenStruct.new( includes: [UserInclude.new( 'engine.h' ), UserInclude.new( 'port.h' )],
|
|
1125
|
+
assembled_filepath: 'pp/engine.c' ) )
|
|
1126
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.c').and_return( 'int engine_get(void) { return port_twice(port_read()) + port_k; }' )
|
|
1127
|
+
@extras = Partials::InterfaceExtras.new( items: [
|
|
1128
|
+
CExtractorTypes::CFunctionDefinition.new( name: 'port_twice' ),
|
|
1129
|
+
CExtractorTypes::CVariableDeclaration.new( name: 'port_k', decorators: ['static'] )
|
|
1130
|
+
] )
|
|
1131
|
+
allow(@partializer_helper).to receive(:plan_interface_extras)
|
|
1132
|
+
.with( c_module: :module, interface: :interface, fallback: false, header_guarded: true ).and_return( @extras )
|
|
1133
|
+
allow(@partializer_helper).to receive(:names_in) { |text| Set.new( text.scan( /[A-Za-z_]\w*/ ) ) }
|
|
1134
|
+
end
|
|
1135
|
+
|
|
1136
|
+
def explain(partials)
|
|
1137
|
+
@partializer.explain_tested_mock(
|
|
1138
|
+
test: 'test_engine', c_module: :module, interface: :interface, header_guarded: true, config: @config, partials: partials
|
|
1139
|
+
)
|
|
1140
|
+
end
|
|
1141
|
+
|
|
1142
|
+
# A module tested and mocked in one test keeps its header's content in its own implementation
|
|
1143
|
+
it "explains what other Partials including a tested and mocked module's header go without" do
|
|
1144
|
+
expect(@loginator).to receive(:log).with( <<~NOTICE, Verbosity::COMPLAIN, LogLabels::NOTICE )
|
|
1145
|
+
Partial test_engine::port ⏩️ Other Partials in this test include src/port.h's mock, which leaves helper `port_twice()` and variable `port_k` out.
|
|
1146
|
+
|
|
1147
|
+
HOW THIS HAPPENS:
|
|
1148
|
+
• A module both tested and mocked in one test keeps its header's helpers and static variables in its own implementation.
|
|
1149
|
+
• Every other Partial that includes src/port.h gets the mock's interface in its place, which declares only the mocked functions.
|
|
1150
|
+
• Code in those Partials that uses them fails to compile or link.
|
|
1151
|
+
|
|
1152
|
+
OPTIONS:
|
|
1153
|
+
1. Test port in a test file of its own, and only mock it in this one.
|
|
1154
|
+
2. Move what the other Partials use into a header that src/port.h includes, which the mock keeps.
|
|
1155
|
+
|
|
1156
|
+
See the docs on Partials conventions.
|
|
1157
|
+
NOTICE
|
|
1158
|
+
|
|
1159
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1160
|
+
end
|
|
1161
|
+
|
|
1162
|
+
it "lists helpers, variables and prototypes as one list" do
|
|
1163
|
+
@extras.items << CExtractorTypes::CFunctionDeclaration.new( name: 'port_scaled' )
|
|
1164
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.c').and_return( 'int g(void) { return port_twice(port_k) + port_scaled(); }' )
|
|
1165
|
+
|
|
1166
|
+
expect(@loginator).to receive(:log) do |notice, *|
|
|
1167
|
+
expect( notice ).to include( 'which leaves helper `port_twice()`, variable `port_k` and prototype `port_scaled()` out.' )
|
|
1168
|
+
end
|
|
1169
|
+
|
|
1170
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1171
|
+
end
|
|
1172
|
+
|
|
1173
|
+
# Only what another Partial's code uses can fail there
|
|
1174
|
+
it "names only what the other Partials use, in the singular for one" do
|
|
1175
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.c').and_return( 'int engine_get(void) { return port_twice(port_read()); }' )
|
|
1176
|
+
|
|
1177
|
+
expect(@loginator).to receive(:log) do |notice, *|
|
|
1178
|
+
expect( notice ).to include( 'which leaves helper `port_twice()` out.' )
|
|
1179
|
+
expect( notice ).to include( 'Code in those Partials that uses it fails to compile or link.' )
|
|
1180
|
+
end
|
|
1181
|
+
|
|
1182
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1183
|
+
end
|
|
1184
|
+
|
|
1185
|
+
it "says nothing when the other Partials use none of it" do
|
|
1186
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.c').and_return( 'int engine_get(void) { return port_read(); }' )
|
|
1187
|
+
expect(@loginator).not_to receive(:log)
|
|
1188
|
+
|
|
1189
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1190
|
+
end
|
|
1191
|
+
|
|
1192
|
+
it "reads a Partial that includes the header from its own header" do
|
|
1193
|
+
@engine.source.includes = [UserInclude.new( 'engine.h' )]
|
|
1194
|
+
@engine.header = OpenStruct.new( includes: [UserInclude.new( 'port.h' )], assembled_filepath: 'pp/engine.h' )
|
|
1195
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.c').and_return( '' )
|
|
1196
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.h').and_return( 'static inline int e(void) { return port_k; }' )
|
|
1197
|
+
|
|
1198
|
+
expect(@loginator).to receive(:log) do |notice, *|
|
|
1199
|
+
expect( notice ).to include( 'which leaves variable `port_k` out.' )
|
|
1200
|
+
end
|
|
1201
|
+
|
|
1202
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1203
|
+
end
|
|
1204
|
+
|
|
1205
|
+
# A use through a macro shows only in the expansion
|
|
1206
|
+
it "reads another Partial's expansion where it has one" do
|
|
1207
|
+
@engine.source.expansion_filepath = 'pp/engine.expanded.c'
|
|
1208
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.c').and_return( 'int engine_get(void) { return PORT_TWICE(1); }' )
|
|
1209
|
+
allow(@file_wrapper).to receive(:read).with('pp/engine.expanded.c').and_return( 'int engine_get(void) { return port_twice(1); }' )
|
|
1210
|
+
|
|
1211
|
+
expect(@loginator).to receive(:log) do |notice, *|
|
|
1212
|
+
expect( notice ).to include( 'which leaves helper `port_twice()` out.' )
|
|
1213
|
+
end
|
|
1214
|
+
|
|
1215
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1216
|
+
end
|
|
1217
|
+
|
|
1218
|
+
it "never counts the module itself among the Partials including its header" do
|
|
1219
|
+
@config.source.assembled_filepath = 'pp/port.c'
|
|
1220
|
+
allow(@file_wrapper).to receive(:read).with('pp/port.c').and_return( 'int port_scaled(void) { return port_twice(port_k); }' )
|
|
1221
|
+
expect(@loginator).not_to receive(:log)
|
|
1222
|
+
|
|
1223
|
+
explain( { 'port' => @config } )
|
|
1224
|
+
end
|
|
1225
|
+
|
|
1226
|
+
it "says nothing when no other Partial includes the module's header" do
|
|
1227
|
+
@engine.source.includes = [UserInclude.new( 'engine.h' )]
|
|
1228
|
+
expect(@loginator).not_to receive(:log)
|
|
1229
|
+
|
|
1230
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1231
|
+
end
|
|
1232
|
+
|
|
1233
|
+
it "says nothing when the mock would leave nothing out" do
|
|
1234
|
+
allow(@partializer_helper).to receive(:plan_interface_extras).and_return( Partials::InterfaceExtras.new )
|
|
1235
|
+
expect(@loginator).not_to receive(:log)
|
|
1236
|
+
|
|
1237
|
+
explain( { 'engine' => @engine, 'port' => @config } )
|
|
1238
|
+
end
|
|
1239
|
+
end
|
|
1240
|
+
|
|
583
1241
|
###
|
|
584
1242
|
### remap_implementation_header_includes()
|
|
585
1243
|
###
|
|
@@ -590,9 +1248,9 @@ describe Partializer do
|
|
|
590
1248
|
partials = {}
|
|
591
1249
|
result = @partializer.remap_implementation_header_includes(
|
|
592
1250
|
name: 'module',
|
|
593
|
-
|
|
1251
|
+
source_includes: includes,
|
|
594
1252
|
partials: partials
|
|
595
|
-
)
|
|
1253
|
+
).to_a
|
|
596
1254
|
|
|
597
1255
|
expect(result).to eq([])
|
|
598
1256
|
end
|
|
@@ -602,9 +1260,9 @@ describe Partializer do
|
|
|
602
1260
|
partials = {}
|
|
603
1261
|
result = @partializer.remap_implementation_header_includes(
|
|
604
1262
|
name: 'module',
|
|
605
|
-
|
|
1263
|
+
source_includes: includes,
|
|
606
1264
|
partials: partials
|
|
607
|
-
)
|
|
1265
|
+
).to_a
|
|
608
1266
|
|
|
609
1267
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
610
1268
|
expect(result).not_to include(UserInclude.new('module.h'))
|
|
@@ -619,9 +1277,9 @@ describe Partializer do
|
|
|
619
1277
|
|
|
620
1278
|
result = @partializer.remap_implementation_header_includes(
|
|
621
1279
|
name: 'drivers/uart/config',
|
|
622
|
-
|
|
1280
|
+
source_includes: includes,
|
|
623
1281
|
partials: {}
|
|
624
|
-
)
|
|
1282
|
+
).to_a
|
|
625
1283
|
|
|
626
1284
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
627
1285
|
end
|
|
@@ -631,10 +1289,10 @@ describe Partializer do
|
|
|
631
1289
|
|
|
632
1290
|
result = @partializer.remap_implementation_header_includes(
|
|
633
1291
|
name: 'drivers/uart/config',
|
|
634
|
-
|
|
1292
|
+
source_includes: includes,
|
|
635
1293
|
partials: {},
|
|
636
1294
|
types_header: 'drivers/uart/ceedling_partial_config_types.h'
|
|
637
|
-
)
|
|
1295
|
+
).to_a
|
|
638
1296
|
|
|
639
1297
|
expect(result.map(&:filepath)).to eq(
|
|
640
1298
|
['header1.h', 'drivers/uart/ceedling_partial_config_types.h', 'header2.h']
|
|
@@ -646,9 +1304,9 @@ describe Partializer do
|
|
|
646
1304
|
|
|
647
1305
|
result = @partializer.remap_implementation_header_includes(
|
|
648
1306
|
name: 'drivers/uart/config',
|
|
649
|
-
|
|
1307
|
+
source_includes: includes,
|
|
650
1308
|
partials: { 'drivers/spi/other' => nil }
|
|
651
|
-
)
|
|
1309
|
+
).to_a
|
|
652
1310
|
|
|
653
1311
|
expect(result).to match_array([UserInclude.new('header1.h')])
|
|
654
1312
|
end
|
|
@@ -656,13 +1314,13 @@ describe Partializer do
|
|
|
656
1314
|
it "removes partialized module headers from includes" do
|
|
657
1315
|
includes = [UserInclude.new('header1.h'), UserInclude.new('partial_module.h'), UserInclude.new('header2.h')]
|
|
658
1316
|
partials = {
|
|
659
|
-
'partial_module' =>
|
|
1317
|
+
'partial_module' => make_partial_config(tests_type: :public)
|
|
660
1318
|
}
|
|
661
1319
|
result = @partializer.remap_implementation_header_includes(
|
|
662
1320
|
name: 'module',
|
|
663
|
-
|
|
1321
|
+
source_includes: includes,
|
|
664
1322
|
partials: partials
|
|
665
|
-
)
|
|
1323
|
+
).to_a
|
|
666
1324
|
|
|
667
1325
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
668
1326
|
expect(result).not_to include(UserInclude.new('partial_module.h'))
|
|
@@ -681,9 +1339,9 @@ describe Partializer do
|
|
|
681
1339
|
}
|
|
682
1340
|
result = @partializer.remap_implementation_header_includes(
|
|
683
1341
|
name: 'module',
|
|
684
|
-
|
|
1342
|
+
source_includes: includes,
|
|
685
1343
|
partials: partials
|
|
686
|
-
)
|
|
1344
|
+
).to_a
|
|
687
1345
|
|
|
688
1346
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
689
1347
|
expect(result).not_to include(UserInclude.new('partial1.h'))
|
|
@@ -702,9 +1360,9 @@ describe Partializer do
|
|
|
702
1360
|
}
|
|
703
1361
|
result = @partializer.remap_implementation_header_includes(
|
|
704
1362
|
name: 'module',
|
|
705
|
-
|
|
1363
|
+
source_includes: includes,
|
|
706
1364
|
partials: partials
|
|
707
|
-
)
|
|
1365
|
+
).to_a
|
|
708
1366
|
|
|
709
1367
|
expect(result).to match_array(
|
|
710
1368
|
[
|
|
@@ -727,9 +1385,9 @@ describe Partializer do
|
|
|
727
1385
|
}
|
|
728
1386
|
result = @partializer.remap_implementation_header_includes(
|
|
729
1387
|
name: 'module',
|
|
730
|
-
|
|
1388
|
+
source_includes: includes,
|
|
731
1389
|
partials: partials
|
|
732
|
-
)
|
|
1390
|
+
).to_a
|
|
733
1391
|
|
|
734
1392
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
735
1393
|
end
|
|
@@ -744,9 +1402,9 @@ describe Partializer do
|
|
|
744
1402
|
partials = {}
|
|
745
1403
|
result = @partializer.remap_implementation_header_includes(
|
|
746
1404
|
name: 'module',
|
|
747
|
-
|
|
1405
|
+
source_includes: includes,
|
|
748
1406
|
partials: partials
|
|
749
|
-
)
|
|
1407
|
+
).to_a
|
|
750
1408
|
|
|
751
1409
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
752
1410
|
expect(result).not_to include(UserInclude.new('module.h'))
|
|
@@ -767,9 +1425,9 @@ describe Partializer do
|
|
|
767
1425
|
}
|
|
768
1426
|
result = @partializer.remap_implementation_header_includes(
|
|
769
1427
|
name: 'module',
|
|
770
|
-
|
|
1428
|
+
source_includes: includes,
|
|
771
1429
|
partials: partials
|
|
772
|
-
)
|
|
1430
|
+
).to_a
|
|
773
1431
|
|
|
774
1432
|
expect(result).to match_array([UserInclude.new('header1.h')])
|
|
775
1433
|
end
|
|
@@ -779,9 +1437,9 @@ describe Partializer do
|
|
|
779
1437
|
partials = {}
|
|
780
1438
|
result = @partializer.remap_implementation_header_includes(
|
|
781
1439
|
name: 'module',
|
|
782
|
-
|
|
1440
|
+
source_includes: includes,
|
|
783
1441
|
partials: partials
|
|
784
|
-
)
|
|
1442
|
+
).to_a
|
|
785
1443
|
|
|
786
1444
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
787
1445
|
end
|
|
@@ -802,9 +1460,9 @@ describe Partializer do
|
|
|
802
1460
|
}
|
|
803
1461
|
result = @partializer.remap_implementation_header_includes(
|
|
804
1462
|
name: 'module',
|
|
805
|
-
|
|
1463
|
+
source_includes: includes,
|
|
806
1464
|
partials: partials
|
|
807
|
-
)
|
|
1465
|
+
).to_a
|
|
808
1466
|
|
|
809
1467
|
expect(result).to match_array(
|
|
810
1468
|
[
|
|
@@ -823,10 +1481,10 @@ describe Partializer do
|
|
|
823
1481
|
partials = {}
|
|
824
1482
|
result = @partializer.remap_implementation_header_includes(
|
|
825
1483
|
name: 'module',
|
|
826
|
-
|
|
1484
|
+
source_includes: includes,
|
|
827
1485
|
partials: partials,
|
|
828
1486
|
types_header: 'ceedling_partial_module_types.h'
|
|
829
|
-
)
|
|
1487
|
+
).to_a
|
|
830
1488
|
|
|
831
1489
|
expect(result).to include(UserInclude.new('ceedling_partial_module_types.h'))
|
|
832
1490
|
end
|
|
@@ -836,9 +1494,9 @@ describe Partializer do
|
|
|
836
1494
|
partials = {}
|
|
837
1495
|
result = @partializer.remap_implementation_header_includes(
|
|
838
1496
|
name: 'module',
|
|
839
|
-
|
|
1497
|
+
source_includes: includes,
|
|
840
1498
|
partials: partials
|
|
841
|
-
)
|
|
1499
|
+
).to_a
|
|
842
1500
|
|
|
843
1501
|
expect(result).to match_array([UserInclude.new('header1.h')])
|
|
844
1502
|
end
|
|
@@ -856,10 +1514,10 @@ describe Partializer do
|
|
|
856
1514
|
]
|
|
857
1515
|
result = @partializer.remap_implementation_header_includes(
|
|
858
1516
|
name: 'module',
|
|
859
|
-
|
|
1517
|
+
source_includes: includes,
|
|
860
1518
|
partials: {},
|
|
861
1519
|
types_header: 'ceedling_partial_module_types.h'
|
|
862
|
-
)
|
|
1520
|
+
).to_a
|
|
863
1521
|
|
|
864
1522
|
expect(result).to eq([
|
|
865
1523
|
UserInclude.new('header1.h'),
|
|
@@ -868,19 +1526,27 @@ describe Partializer do
|
|
|
868
1526
|
])
|
|
869
1527
|
end
|
|
870
1528
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1529
|
+
# A source that never includes its own header leaves the header's place after its last
|
|
1530
|
+
# include. The types header stands there, ahead of the declarations that use its types.
|
|
1531
|
+
it "puts the types header after the source's includes when the source never includes the module's header" do
|
|
1532
|
+
groups = @partializer.remap_implementation_header_includes(
|
|
874
1533
|
name: 'module',
|
|
875
|
-
|
|
876
|
-
partials: {},
|
|
877
|
-
types_header: 'ceedling_partial_module_types.h'
|
|
1534
|
+
source_includes: [UserInclude.new( 'a.h' ), UserInclude.new( 'b.h' )],
|
|
1535
|
+
header_includes: [UserInclude.new( 'c.h' )], partials: {}, types_header: 'module_types.h'
|
|
878
1536
|
)
|
|
879
1537
|
|
|
880
|
-
expect(
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1538
|
+
expect( groups.leading.map( &:filename ) ).to eq( ['a.h', 'b.h', 'module_types.h', 'c.h'] )
|
|
1539
|
+
expect( groups.following ).to eq( [] )
|
|
1540
|
+
end
|
|
1541
|
+
|
|
1542
|
+
it "puts a header-only module's types header ahead of its declarations" do
|
|
1543
|
+
groups = @partializer.remap_implementation_header_includes(
|
|
1544
|
+
name: 'module', source_includes: [], header_includes: [UserInclude.new( 'base.h' )], partials: {},
|
|
1545
|
+
types_header: 'module_types.h'
|
|
1546
|
+
)
|
|
1547
|
+
|
|
1548
|
+
expect( groups.leading.map( &:filename ) ).to eq( ['module_types.h', 'base.h'] )
|
|
1549
|
+
expect( groups.following ).to eq( [] )
|
|
884
1550
|
end
|
|
885
1551
|
end
|
|
886
1552
|
|
|
@@ -889,12 +1555,69 @@ describe Partializer do
|
|
|
889
1555
|
###
|
|
890
1556
|
|
|
891
1557
|
context "#remap_interface_header_includes" do
|
|
1558
|
+
# The types header carries the header's own content, so it stands where the header was
|
|
1559
|
+
it "puts the types header where the module's header was, ahead of the following group" do
|
|
1560
|
+
groups = @partializer.remap_interface_header_includes(
|
|
1561
|
+
name: 'module',
|
|
1562
|
+
source_includes: [UserInclude.new( 'config.h' ), UserInclude.new( 'module.h' ), UserInclude.new( 'log.h' )],
|
|
1563
|
+
header_includes: [UserInclude.new( 'base.h' )], partials: {}, types_header: 'module_types.h'
|
|
1564
|
+
)
|
|
1565
|
+
|
|
1566
|
+
expect( groups.leading.map( &:filename ) ).to eq( ['config.h', 'module_types.h', 'base.h'] )
|
|
1567
|
+
expect( groups.following.map( &:filename ) ).to eq( ['log.h'] )
|
|
1568
|
+
end
|
|
1569
|
+
|
|
1570
|
+
# The split comes at the module's own header, not at an unrelated header sharing its basename
|
|
1571
|
+
it "splits the groups at a directory-named module's own header" do
|
|
1572
|
+
groups = @partializer.remap_interface_header_includes(
|
|
1573
|
+
name: 'drivers/uart/config',
|
|
1574
|
+
source_includes: [UserInclude.new( 'src/config.h' ), UserInclude.new( 'a.h' ), UserInclude.new( 'include/drivers/uart/config.h' ), UserInclude.new( 'b.h' )],
|
|
1575
|
+
header_includes: [UserInclude.new( 'h.h' )], types_header: 'module_types.h',
|
|
1576
|
+
partials: { 'drivers/uart/config' => make_partial_config(mocks_type: :public, header: 'include/drivers/uart/config.h') }
|
|
1577
|
+
)
|
|
1578
|
+
|
|
1579
|
+
expect( groups.leading.map( &:filepath ) ).to eq( ['src/config.h', 'a.h', 'module_types.h', 'h.h'] )
|
|
1580
|
+
expect( groups.following.map( &:filepath ) ).to eq( ['b.h'] )
|
|
1581
|
+
end
|
|
1582
|
+
|
|
1583
|
+
# A tested Partial's header is dropped from another module's interface, and only its header
|
|
1584
|
+
it "keeps an unpartialized header sharing a tested Partial's basename" do
|
|
1585
|
+
groups = @partializer.remap_interface_header_includes(
|
|
1586
|
+
name: 'motor', source_includes: [UserInclude.new( 'src/motor.h' )],
|
|
1587
|
+
header_includes: [UserInclude.new( 'src/config.h' ), UserInclude.new( 'include/drivers/uart/config.h' )],
|
|
1588
|
+
partials: { 'drivers/uart/config' => make_partial_config(tests_type: :public, header: 'include/drivers/uart/config.h') }
|
|
1589
|
+
)
|
|
1590
|
+
|
|
1591
|
+
expect( groups.leading.map( &:filepath ) ).to eq( ['src/config.h'] )
|
|
1592
|
+
end
|
|
1593
|
+
|
|
1594
|
+
it "puts a header-only module's types header ahead of its declarations" do
|
|
1595
|
+
groups = @partializer.remap_interface_header_includes(
|
|
1596
|
+
name: 'module', source_includes: [], header_includes: [UserInclude.new( 'base.h' )], partials: {},
|
|
1597
|
+
types_header: 'module_types.h'
|
|
1598
|
+
)
|
|
1599
|
+
|
|
1600
|
+
expect( groups.leading.map( &:filename ) ).to eq( ['module_types.h', 'base.h'] )
|
|
1601
|
+
expect( groups.following ).to eq( [] )
|
|
1602
|
+
end
|
|
1603
|
+
|
|
1604
|
+
it "puts the types header after the source's includes when the source never includes the module's header" do
|
|
1605
|
+
groups = @partializer.remap_interface_header_includes(
|
|
1606
|
+
name: 'module',
|
|
1607
|
+
source_includes: [UserInclude.new( 'a.h' ), UserInclude.new( 'b.h' )],
|
|
1608
|
+
header_includes: [UserInclude.new( 'c.h' )], partials: {}, types_header: 'module_types.h'
|
|
1609
|
+
)
|
|
1610
|
+
|
|
1611
|
+
expect( groups.leading.map( &:filename ) ).to eq( ['a.h', 'b.h', 'module_types.h', 'c.h'] )
|
|
1612
|
+
expect( groups.following ).to eq( [] )
|
|
1613
|
+
end
|
|
1614
|
+
|
|
892
1615
|
it "returns empty array when input is empty and no partials" do
|
|
893
1616
|
result = @partializer.remap_interface_header_includes(
|
|
894
1617
|
name: 'module',
|
|
895
|
-
|
|
1618
|
+
source_includes: [],
|
|
896
1619
|
partials: {}
|
|
897
|
-
)
|
|
1620
|
+
).to_a
|
|
898
1621
|
expect(result).to eq([])
|
|
899
1622
|
end
|
|
900
1623
|
|
|
@@ -902,9 +1625,9 @@ describe Partializer do
|
|
|
902
1625
|
includes = [UserInclude.new('header1.h'), UserInclude.new('module.h'), UserInclude.new('header2.h')]
|
|
903
1626
|
result = @partializer.remap_interface_header_includes(
|
|
904
1627
|
name: 'module',
|
|
905
|
-
|
|
1628
|
+
source_includes: includes,
|
|
906
1629
|
partials: {}
|
|
907
|
-
)
|
|
1630
|
+
).to_a
|
|
908
1631
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
909
1632
|
expect(result).not_to include(UserInclude.new('module.h'))
|
|
910
1633
|
end
|
|
@@ -914,9 +1637,9 @@ describe Partializer do
|
|
|
914
1637
|
partials = { 'partial_module' => nil }
|
|
915
1638
|
result = @partializer.remap_interface_header_includes(
|
|
916
1639
|
name: 'module',
|
|
917
|
-
|
|
1640
|
+
source_includes: includes,
|
|
918
1641
|
partials: partials
|
|
919
|
-
)
|
|
1642
|
+
).to_a
|
|
920
1643
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
921
1644
|
expect(result).not_to include(UserInclude.new('partial_module.h'))
|
|
922
1645
|
end
|
|
@@ -931,9 +1654,9 @@ describe Partializer do
|
|
|
931
1654
|
partials = { 'partial1' => nil, 'partial2' => nil }
|
|
932
1655
|
result = @partializer.remap_interface_header_includes(
|
|
933
1656
|
name: 'module',
|
|
934
|
-
|
|
1657
|
+
source_includes: includes,
|
|
935
1658
|
partials: partials
|
|
936
|
-
)
|
|
1659
|
+
).to_a
|
|
937
1660
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
938
1661
|
expect(result).not_to include(UserInclude.new('partial1.h'))
|
|
939
1662
|
expect(result).not_to include(UserInclude.new('partial2.h'))
|
|
@@ -949,9 +1672,9 @@ describe Partializer do
|
|
|
949
1672
|
partials = { 'partial_module' => nil }
|
|
950
1673
|
result = @partializer.remap_interface_header_includes(
|
|
951
1674
|
name: 'module',
|
|
952
|
-
|
|
1675
|
+
source_includes: includes,
|
|
953
1676
|
partials: partials
|
|
954
|
-
)
|
|
1677
|
+
).to_a
|
|
955
1678
|
expect(result).to match_array([
|
|
956
1679
|
UserInclude.new('header1.h'),
|
|
957
1680
|
UserInclude.new('header2.h'),
|
|
@@ -969,9 +1692,9 @@ describe Partializer do
|
|
|
969
1692
|
partials = { 'partial_module' => nil }
|
|
970
1693
|
result = @partializer.remap_interface_header_includes(
|
|
971
1694
|
name: 'module',
|
|
972
|
-
|
|
1695
|
+
source_includes: includes,
|
|
973
1696
|
partials: partials
|
|
974
|
-
)
|
|
1697
|
+
).to_a
|
|
975
1698
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
976
1699
|
end
|
|
977
1700
|
|
|
@@ -984,9 +1707,9 @@ describe Partializer do
|
|
|
984
1707
|
]
|
|
985
1708
|
result = @partializer.remap_interface_header_includes(
|
|
986
1709
|
name: 'module',
|
|
987
|
-
|
|
1710
|
+
source_includes: includes,
|
|
988
1711
|
partials: {}
|
|
989
|
-
)
|
|
1712
|
+
).to_a
|
|
990
1713
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
991
1714
|
expect(result).not_to include(UserInclude.new('module.h'))
|
|
992
1715
|
expect(result).not_to include(UserInclude.new('MODULE.H'))
|
|
@@ -1002,9 +1725,9 @@ describe Partializer do
|
|
|
1002
1725
|
partials = { 'partial1' => nil, 'partial2' => nil, 'partial3' => nil }
|
|
1003
1726
|
result = @partializer.remap_interface_header_includes(
|
|
1004
1727
|
name: 'module',
|
|
1005
|
-
|
|
1728
|
+
source_includes: includes,
|
|
1006
1729
|
partials: partials
|
|
1007
|
-
)
|
|
1730
|
+
).to_a
|
|
1008
1731
|
expect(result).to match_array([UserInclude.new('header1.h')])
|
|
1009
1732
|
end
|
|
1010
1733
|
|
|
@@ -1012,9 +1735,9 @@ describe Partializer do
|
|
|
1012
1735
|
includes = [UserInclude.new('header1.h'), UserInclude.new('header2.h'), UserInclude.new('module.h')]
|
|
1013
1736
|
result = @partializer.remap_interface_header_includes(
|
|
1014
1737
|
name: 'module',
|
|
1015
|
-
|
|
1738
|
+
source_includes: includes,
|
|
1016
1739
|
partials: {}
|
|
1017
|
-
)
|
|
1740
|
+
).to_a
|
|
1018
1741
|
expect(result).to match_array([UserInclude.new('header1.h'), UserInclude.new('header2.h')])
|
|
1019
1742
|
end
|
|
1020
1743
|
|
|
@@ -1031,9 +1754,9 @@ describe Partializer do
|
|
|
1031
1754
|
partials = { 'partial1' => nil, 'partial2' => nil }
|
|
1032
1755
|
result = @partializer.remap_interface_header_includes(
|
|
1033
1756
|
name: 'module',
|
|
1034
|
-
|
|
1757
|
+
source_includes: includes,
|
|
1035
1758
|
partials: partials
|
|
1036
|
-
)
|
|
1759
|
+
).to_a
|
|
1037
1760
|
expect(result).to match_array([
|
|
1038
1761
|
UserInclude.new('header1.h'),
|
|
1039
1762
|
UserInclude.new('header2.h'),
|
|
@@ -1049,75 +1772,347 @@ describe Partializer do
|
|
|
1049
1772
|
partials = {}
|
|
1050
1773
|
result = @partializer.remap_interface_header_includes(
|
|
1051
1774
|
name: 'module',
|
|
1052
|
-
|
|
1775
|
+
source_includes: includes,
|
|
1053
1776
|
partials: partials,
|
|
1054
1777
|
types_header: 'ceedling_partial_module_types.h'
|
|
1778
|
+
).to_a
|
|
1779
|
+
|
|
1780
|
+
expect(result).to include(UserInclude.new('ceedling_partial_module_types.h'))
|
|
1781
|
+
end
|
|
1782
|
+
|
|
1783
|
+
it "does not append a types header when the module has none" do
|
|
1784
|
+
includes = [UserInclude.new('header1.h')]
|
|
1785
|
+
partials = {}
|
|
1786
|
+
result = @partializer.remap_interface_header_includes(
|
|
1787
|
+
name: 'module',
|
|
1788
|
+
source_includes: includes,
|
|
1789
|
+
partials: partials
|
|
1790
|
+
).to_a
|
|
1791
|
+
|
|
1792
|
+
expect(result).to match_array([UserInclude.new('header1.h')])
|
|
1793
|
+
end
|
|
1794
|
+
|
|
1795
|
+
# See the matching example in #remap_implementation_header_includes for the full
|
|
1796
|
+
# rationale; the mockable interface header needs the identical ordering guarantee.
|
|
1797
|
+
it "splices the shared types header in at the module's own original list position, not at the end" do
|
|
1798
|
+
includes = [
|
|
1799
|
+
UserInclude.new('header1.h'),
|
|
1800
|
+
UserInclude.new('module.h'),
|
|
1801
|
+
UserInclude.new('header2.h')
|
|
1802
|
+
]
|
|
1803
|
+
result = @partializer.remap_interface_header_includes(
|
|
1804
|
+
name: 'module',
|
|
1805
|
+
source_includes: includes,
|
|
1806
|
+
partials: {},
|
|
1807
|
+
types_header: 'ceedling_partial_module_types.h'
|
|
1808
|
+
).to_a
|
|
1809
|
+
|
|
1810
|
+
expect(result).to eq([
|
|
1811
|
+
UserInclude.new('header1.h'),
|
|
1812
|
+
UserInclude.new('ceedling_partial_module_types.h'),
|
|
1813
|
+
UserInclude.new('header2.h')
|
|
1814
|
+
])
|
|
1815
|
+
end
|
|
1816
|
+
end
|
|
1817
|
+
|
|
1818
|
+
###
|
|
1819
|
+
### remap_implementation_source_includes()
|
|
1820
|
+
###
|
|
1821
|
+
|
|
1822
|
+
context "#remap_implementation_source_includes" do
|
|
1823
|
+
# Fallback holds an #include as written beside the header it resolved to elsewhere, and
|
|
1824
|
+
# the two are one header
|
|
1825
|
+
it "drops an unresolved #include beside the resolved header of the same name" do
|
|
1826
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1827
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
1828
|
+
|
|
1829
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1830
|
+
name: 'module',
|
|
1831
|
+
includes: [UserInclude.new('module.h'), UserInclude.new('config.h'), UserInclude.new('include/drivers/config.h')],
|
|
1832
|
+
partials: { 'module' => make_partial_config(tests_type: :public) }
|
|
1055
1833
|
)
|
|
1056
1834
|
|
|
1057
|
-
expect(result).to
|
|
1835
|
+
expect( result.map( &:filepath ) ).to eq( ['ceedling_partial_module_impl.h', 'include/drivers/config.h'] )
|
|
1836
|
+
end
|
|
1837
|
+
|
|
1838
|
+
# A module tested and mocked in one test file splits its own content across two generated
|
|
1839
|
+
# headers: the implementation carries the public bodies and the interface declares the
|
|
1840
|
+
# private functions those bodies call. The generated source needs both, so this module's own
|
|
1841
|
+
# interface header belongs in its own include list. wondrous_forest's ForestMonitor is
|
|
1842
|
+
# exactly this shape, and dropping the entry leaves its private transition function
|
|
1843
|
+
# undeclared at compile time.
|
|
1844
|
+
it "carries this module's own interface header when it is also mocked" do
|
|
1845
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1846
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
1847
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1848
|
+
.with('module').and_return('ceedling_partial_module_interface.h')
|
|
1849
|
+
|
|
1850
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1851
|
+
name: 'module',
|
|
1852
|
+
includes: [UserInclude.new('module.h')],
|
|
1853
|
+
partials: { 'module' => make_partial_config(tests_type: :public, mocks_type: :private) }
|
|
1854
|
+
)
|
|
1855
|
+
|
|
1856
|
+
expect( result.map( &:filename ) ).to eq(
|
|
1857
|
+
['ceedling_partial_module_impl.h', 'ceedling_partial_module_interface.h']
|
|
1858
|
+
)
|
|
1859
|
+
end
|
|
1860
|
+
|
|
1861
|
+
# The implementation header already stands where this module's header was, so the
|
|
1862
|
+
# interface header follows it rather than everything else.
|
|
1863
|
+
it "puts this module's own interface header right after its implementation header" do
|
|
1864
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1865
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
1866
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1867
|
+
.with('module').and_return('ceedling_partial_module_interface.h')
|
|
1868
|
+
|
|
1869
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1870
|
+
name: 'module',
|
|
1871
|
+
includes: [UserInclude.new('module.h'), UserInclude.new('last.h')],
|
|
1872
|
+
partials: { 'module' => make_partial_config(tests_type: :public, mocks_type: :private) }
|
|
1873
|
+
)
|
|
1874
|
+
|
|
1875
|
+
expect( result.map( &:filename ) ).to eq(
|
|
1876
|
+
['ceedling_partial_module_impl.h', 'ceedling_partial_module_interface.h', 'last.h']
|
|
1877
|
+
)
|
|
1878
|
+
end
|
|
1879
|
+
|
|
1880
|
+
it "puts a mocked dependency's interface header where its real header was" do
|
|
1881
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1882
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
1883
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1884
|
+
.with('other').and_return('ceedling_partial_other_interface.h')
|
|
1885
|
+
|
|
1886
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1887
|
+
name: 'module',
|
|
1888
|
+
includes: [UserInclude.new('first.h'), UserInclude.new('other.h'), UserInclude.new('module.h'), UserInclude.new('last.h')],
|
|
1889
|
+
partials: { 'other' => make_partial_config(mocks_type: :public) }
|
|
1890
|
+
)
|
|
1891
|
+
|
|
1892
|
+
expect( result.map( &:filename ) ).to eq(
|
|
1893
|
+
['first.h', 'ceedling_partial_other_interface.h', 'ceedling_partial_module_impl.h', 'last.h']
|
|
1894
|
+
)
|
|
1895
|
+
end
|
|
1896
|
+
|
|
1897
|
+
# A source that never includes its own header is read as including it last, so the
|
|
1898
|
+
# interface header still follows the implementation header
|
|
1899
|
+
it "carries this module's own interface header when its source never includes its header" do
|
|
1900
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1901
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
1902
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1903
|
+
.with('module').and_return('ceedling_partial_module_interface.h')
|
|
1904
|
+
|
|
1905
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1906
|
+
name: 'module',
|
|
1907
|
+
includes: [UserInclude.new('first.h')],
|
|
1908
|
+
partials: { 'module' => make_partial_config(tests_type: :public, mocks_type: :private) }
|
|
1909
|
+
)
|
|
1910
|
+
|
|
1911
|
+
expect( result.map( &:filename ) ).to eq(
|
|
1912
|
+
['first.h', 'ceedling_partial_module_impl.h', 'ceedling_partial_module_interface.h']
|
|
1913
|
+
)
|
|
1914
|
+
end
|
|
1915
|
+
|
|
1916
|
+
# A module named by directory is keyed by that directory, but its header is included by name
|
|
1917
|
+
it "puts the interface header of a mocked dependency named by directory where its real header was" do
|
|
1918
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1919
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
1920
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1921
|
+
.with('hw/port').and_return('hw/ceedling_partial_port_interface.h')
|
|
1922
|
+
|
|
1923
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1924
|
+
name: 'module',
|
|
1925
|
+
includes: [UserInclude.new('module.h'), UserInclude.new('port.h')],
|
|
1926
|
+
partials: { 'hw/port' => make_partial_config(mocks_type: :private, header: 'src/hw/port.h') }
|
|
1927
|
+
)
|
|
1928
|
+
|
|
1929
|
+
expect( result.map( &:filepath ) ).to eq( ['ceedling_partial_module_impl.h', 'hw/ceedling_partial_port_interface.h'] )
|
|
1930
|
+
end
|
|
1931
|
+
|
|
1932
|
+
# Two modules sharing a basename are told apart by where each header lives
|
|
1933
|
+
context "with a mocked module sharing this module's basename" do
|
|
1934
|
+
before do
|
|
1935
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1936
|
+
.with('drivers/uart/config').and_return('drivers/uart/ceedling_partial_config_impl.h')
|
|
1937
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1938
|
+
.with('drivers/spi/config').and_return('drivers/spi/ceedling_partial_config_interface.h')
|
|
1939
|
+
@partials = {
|
|
1940
|
+
'drivers/uart/config' => make_partial_config(tests_type: :public, header: 'src/drivers/uart/config.h'),
|
|
1941
|
+
'drivers/spi/config' => make_partial_config(mocks_type: :private, header: 'src/drivers/spi/config.h')
|
|
1942
|
+
}
|
|
1943
|
+
end
|
|
1944
|
+
|
|
1945
|
+
it "puts the mocked module's interface header where its real header was" do
|
|
1946
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1947
|
+
name: 'drivers/uart/config', partials: @partials,
|
|
1948
|
+
includes: [UserInclude.new('src/drivers/uart/config.h'), UserInclude.new('src/drivers/spi/config.h')]
|
|
1949
|
+
)
|
|
1950
|
+
|
|
1951
|
+
expect( result.map( &:filepath ) ).to eq(
|
|
1952
|
+
['drivers/uart/ceedling_partial_config_impl.h', 'drivers/spi/ceedling_partial_config_interface.h']
|
|
1953
|
+
)
|
|
1954
|
+
end
|
|
1955
|
+
|
|
1956
|
+
it "replaces the mocked module's header in place when it comes first" do
|
|
1957
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1958
|
+
name: 'drivers/uart/config', partials: @partials,
|
|
1959
|
+
includes: [UserInclude.new('src/drivers/spi/config.h'), UserInclude.new('src/drivers/uart/config.h'), UserInclude.new('last.h')]
|
|
1960
|
+
)
|
|
1961
|
+
|
|
1962
|
+
expect( result.map( &:filepath ) ).to eq(
|
|
1963
|
+
['drivers/spi/ceedling_partial_config_interface.h', 'drivers/uart/ceedling_partial_config_impl.h', 'last.h']
|
|
1964
|
+
)
|
|
1965
|
+
end
|
|
1966
|
+
|
|
1967
|
+
# A case-insensitive filesystem reaches the module's header by any case of its path
|
|
1968
|
+
it "takes a case variant of this module's own header path for its header" do
|
|
1969
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1970
|
+
name: 'drivers/uart/config', partials: @partials, includes: [UserInclude.new('src/drivers/uart/Config.h')]
|
|
1971
|
+
)
|
|
1972
|
+
|
|
1973
|
+
expect( result.map( &:filepath ) ).to eq( ['drivers/uart/ceedling_partial_config_impl.h'] )
|
|
1974
|
+
end
|
|
1975
|
+
|
|
1976
|
+
it "never takes this module's own header for the mocked module's" do
|
|
1977
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1978
|
+
name: 'drivers/uart/config', partials: @partials, includes: [UserInclude.new('src/drivers/uart/config.h')]
|
|
1979
|
+
)
|
|
1980
|
+
|
|
1981
|
+
expect( result.map( &:filepath ) ).to eq( ['drivers/uart/ceedling_partial_config_impl.h'] )
|
|
1982
|
+
end
|
|
1058
1983
|
end
|
|
1059
1984
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1985
|
+
# A module named by directory claims only its own header, even with no other Partial
|
|
1986
|
+
# sharing its basename
|
|
1987
|
+
context "with an unpartialized header sharing a Partial's basename" do
|
|
1988
|
+
before do
|
|
1989
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1990
|
+
.with('motor').and_return('ceedling_partial_motor_impl.h')
|
|
1991
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
1992
|
+
.with('drivers/uart/config').and_return('drivers/uart/ceedling_partial_config_interface.h')
|
|
1993
|
+
end
|
|
1068
1994
|
|
|
1069
|
-
|
|
1995
|
+
it "keeps that header where a mocked Partial would take it" do
|
|
1996
|
+
result = @partializer.remap_implementation_source_includes(
|
|
1997
|
+
name: 'motor', includes: [UserInclude.new('src/motor.h'), UserInclude.new('src/config.h')],
|
|
1998
|
+
partials: { 'drivers/uart/config' => make_partial_config(mocks_type: :public, header: 'include/drivers/uart/config.h') }
|
|
1999
|
+
)
|
|
2000
|
+
|
|
2001
|
+
expect( result.map( &:filepath ) ).to eq( ['ceedling_partial_motor_impl.h', 'src/config.h'] )
|
|
2002
|
+
end
|
|
2003
|
+
|
|
2004
|
+
it "places a mocked Partial's interface header at its own header, not at that header" do
|
|
2005
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2006
|
+
name: 'motor',
|
|
2007
|
+
includes: [UserInclude.new('src/config.h'), UserInclude.new('include/drivers/uart/config.h'), UserInclude.new('src/motor.h')],
|
|
2008
|
+
partials: { 'drivers/uart/config' => make_partial_config(mocks_type: :public, header: 'include/drivers/uart/config.h') }
|
|
2009
|
+
)
|
|
2010
|
+
|
|
2011
|
+
expect( result.map( &:filepath ) ).to eq(
|
|
2012
|
+
['src/config.h', 'drivers/uart/ceedling_partial_config_interface.h', 'ceedling_partial_motor_impl.h']
|
|
2013
|
+
)
|
|
2014
|
+
end
|
|
2015
|
+
|
|
2016
|
+
it "keeps that header where a tested Partial's header would be dropped" do
|
|
2017
|
+
groups = @partializer.remap_types_header_includes(
|
|
2018
|
+
name: 'motor', source_includes: [UserInclude.new('src/motor.h')], header_includes: [UserInclude.new('src/config.h')],
|
|
2019
|
+
partials: { 'drivers/uart/config' => make_partial_config(tests_type: :public, header: 'include/drivers/uart/config.h') }
|
|
2020
|
+
)
|
|
2021
|
+
|
|
2022
|
+
expect( groups.leading.map( &:filepath ) ).to eq( ['src/config.h'] )
|
|
2023
|
+
end
|
|
1070
2024
|
end
|
|
1071
2025
|
|
|
1072
|
-
#
|
|
1073
|
-
#
|
|
1074
|
-
it "
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
includes: includes,
|
|
1083
|
-
partials: {},
|
|
1084
|
-
types_header: 'ceedling_partial_module_types.h'
|
|
2026
|
+
# Fallback anchors a `..` #include to its file's own directory. One that names no file there
|
|
2027
|
+
# was found elsewhere through a search path, so its path says nothing and its filename decides.
|
|
2028
|
+
it "takes an anchored #include naming no file for a directory-named module's own header" do
|
|
2029
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
2030
|
+
.with('hw/port').and_return('hw/ceedling_partial_port_impl.h')
|
|
2031
|
+
allow(@file_wrapper).to receive(:exist?).with('src/port.h').and_return( false )
|
|
2032
|
+
|
|
2033
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2034
|
+
name: 'hw/port', includes: [UserInclude.new( 'src/port.h', directory_relative: true )],
|
|
2035
|
+
partials: { 'hw/port' => make_partial_config(tests_type: :public, header: 'include/hw/port.h') }
|
|
1085
2036
|
)
|
|
1086
2037
|
|
|
1087
|
-
expect(result).to eq([
|
|
1088
|
-
UserInclude.new('header1.h'),
|
|
1089
|
-
UserInclude.new('ceedling_partial_module_types.h'),
|
|
1090
|
-
UserInclude.new('header2.h')
|
|
1091
|
-
])
|
|
2038
|
+
expect( result.map( &:filepath ) ).to eq( ['hw/ceedling_partial_port_impl.h'] )
|
|
1092
2039
|
end
|
|
1093
|
-
end
|
|
1094
|
-
|
|
1095
|
-
###
|
|
1096
|
-
### remap_implementation_source_includes()
|
|
1097
|
-
###
|
|
1098
2040
|
|
|
1099
|
-
|
|
1100
|
-
# A module tested and mocked in one test file splits its own content across two generated
|
|
1101
|
-
# headers: the implementation carries the public bodies and the interface declares the
|
|
1102
|
-
# private functions those bodies call. The generated source needs both, so this module's own
|
|
1103
|
-
# interface header belongs in its own include list. wondrous_forest's ForestMonitor is
|
|
1104
|
-
# exactly this shape, and dropping the entry leaves its private transition function
|
|
1105
|
-
# undeclared at compile time.
|
|
1106
|
-
it "carries this module's own interface header when it is also mocked" do
|
|
2041
|
+
it "matches an anchored #include naming a file by its path" do
|
|
1107
2042
|
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
1108
|
-
.with('
|
|
1109
|
-
allow(@
|
|
1110
|
-
.with('module').and_return('ceedling_partial_module_interface.h')
|
|
2043
|
+
.with('hw/port').and_return('hw/ceedling_partial_port_impl.h')
|
|
2044
|
+
allow(@file_wrapper).to receive(:exist?).with('src/port.h').and_return( true )
|
|
1111
2045
|
|
|
1112
2046
|
result = @partializer.remap_implementation_source_includes(
|
|
1113
|
-
name: '
|
|
1114
|
-
|
|
1115
|
-
partials: { 'module' => make_partial_config(tests_type: :public, mocks_type: :private) }
|
|
2047
|
+
name: 'hw/port', includes: [UserInclude.new( 'src/port.h', directory_relative: true )],
|
|
2048
|
+
partials: { 'hw/port' => make_partial_config(tests_type: :public, header: 'include/hw/port.h') }
|
|
1116
2049
|
)
|
|
1117
2050
|
|
|
1118
|
-
expect( result.map( &:
|
|
1119
|
-
|
|
1120
|
-
|
|
2051
|
+
expect( result.map( &:filepath ) ).to eq( ['src/port.h', 'hw/ceedling_partial_port_impl.h'] )
|
|
2052
|
+
end
|
|
2053
|
+
|
|
2054
|
+
# A module named without a directory is named by its basename, however an #include spells
|
|
2055
|
+
# the path to its header
|
|
2056
|
+
context "with this module's own header spelled another way" do
|
|
2057
|
+
before do
|
|
2058
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
2059
|
+
.with('module').and_return('ceedling_partial_module_impl.h')
|
|
2060
|
+
allow(@file_path_utils).to receive(:form_partial_implementation_header_filename)
|
|
2061
|
+
.with('shared/module').and_return('shared/ceedling_partial_module_impl.h')
|
|
2062
|
+
end
|
|
2063
|
+
|
|
2064
|
+
it "takes an absolute #include of a header outside the project for its own header" do
|
|
2065
|
+
header = '../shared/module.h'
|
|
2066
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2067
|
+
name: 'module', includes: [UserInclude.new( ProjectPaths.absolute( header ) )],
|
|
2068
|
+
partials: { 'module' => make_partial_config(tests_type: :public, header: header) }
|
|
2069
|
+
)
|
|
2070
|
+
|
|
2071
|
+
expect( result.map( &:filepath ) ).to eq( ['ceedling_partial_module_impl.h'] )
|
|
2072
|
+
end
|
|
2073
|
+
|
|
2074
|
+
# A module named by directory is matched by path, so both sides are compared absolutely
|
|
2075
|
+
it "takes an absolute #include of a directory-named module's header outside the project for its own" do
|
|
2076
|
+
header = '../shared/module.h'
|
|
2077
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2078
|
+
name: 'shared/module', includes: [UserInclude.new( ProjectPaths.absolute( header ) )],
|
|
2079
|
+
partials: { 'shared/module' => make_partial_config(tests_type: :public, header: header) }
|
|
2080
|
+
)
|
|
2081
|
+
|
|
2082
|
+
expect( result.map( &:filepath ) ).to eq( ['shared/ceedling_partial_module_impl.h'] )
|
|
2083
|
+
end
|
|
2084
|
+
|
|
2085
|
+
it "takes a relative #include of a directory-named module's header the project names absolutely" do
|
|
2086
|
+
header = ProjectPaths.absolute( '../shared/module.h' )
|
|
2087
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2088
|
+
name: 'shared/module', includes: [UserInclude.new( '../shared/module.h' )],
|
|
2089
|
+
partials: { 'shared/module' => make_partial_config(tests_type: :public, header: header) }
|
|
2090
|
+
)
|
|
2091
|
+
|
|
2092
|
+
expect( result.map( &:filepath ) ).to eq( ['shared/ceedling_partial_module_impl.h'] )
|
|
2093
|
+
end
|
|
2094
|
+
|
|
2095
|
+
# A case-insensitive filesystem reaches the header by either case of its absolute path
|
|
2096
|
+
it "takes a case variant of a directory-named module's absolute header path for its own" do
|
|
2097
|
+
header = '../shared/module.h'
|
|
2098
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2099
|
+
name: 'shared/module', includes: [UserInclude.new( ProjectPaths.absolute( header ).sub( 'shared', 'SHARED' ) )],
|
|
2100
|
+
partials: { 'shared/module' => make_partial_config(tests_type: :public, header: header) }
|
|
2101
|
+
)
|
|
2102
|
+
|
|
2103
|
+
expect( result.map( &:filepath ) ).to eq( ['shared/ceedling_partial_module_impl.h'] )
|
|
2104
|
+
end
|
|
2105
|
+
|
|
2106
|
+
# Fallback preprocessing anchors a `..` #include to the file's own directory, which need
|
|
2107
|
+
# not be where the compiler finds the header
|
|
2108
|
+
it "takes a fallback-anchored #include for its own header" do
|
|
2109
|
+
result = @partializer.remap_implementation_source_includes(
|
|
2110
|
+
name: 'module', includes: [UserInclude.new( 'src/module.h', directory_relative: true )],
|
|
2111
|
+
partials: { 'module' => make_partial_config(tests_type: :public, header: 'include/module.h') }
|
|
2112
|
+
)
|
|
2113
|
+
|
|
2114
|
+
expect( result.map( &:filepath ) ).to eq( ['ceedling_partial_module_impl.h'] )
|
|
2115
|
+
end
|
|
1121
2116
|
end
|
|
1122
2117
|
|
|
1123
2118
|
it "carries no interface header for a module that is tested but not mocked" do
|
|
@@ -1539,14 +2534,110 @@ describe Partializer do
|
|
|
1539
2534
|
###
|
|
1540
2535
|
|
|
1541
2536
|
context "#remap_types_header_includes" do
|
|
2537
|
+
# The source meets its later includes only after the module header, so they follow
|
|
2538
|
+
# whatever the header supplies
|
|
2539
|
+
context "grouping includes where the source includes the module's header" do
|
|
2540
|
+
def types_groups(source, header = [], partials: {})
|
|
2541
|
+
@partializer.remap_types_header_includes(
|
|
2542
|
+
name: 'module', source_includes: source.map { |name| UserInclude.new( name ) },
|
|
2543
|
+
header_includes: header.map { |name| UserInclude.new( name ) }, partials: partials
|
|
2544
|
+
)
|
|
2545
|
+
end
|
|
2546
|
+
|
|
2547
|
+
def filenames(groups)
|
|
2548
|
+
[groups.leading.map( &:filename ), groups.following.map( &:filename )]
|
|
2549
|
+
end
|
|
2550
|
+
|
|
2551
|
+
it "puts the header's includes after the source's earlier ones, and the rest after them" do
|
|
2552
|
+
groups = types_groups( ['config.h', 'module.h', 'log.h'], ['base.h'] )
|
|
2553
|
+
|
|
2554
|
+
expect( filenames( groups ) ).to eq( [['config.h', 'base.h'], ['log.h']] )
|
|
2555
|
+
end
|
|
2556
|
+
|
|
2557
|
+
it "keeps an include named in both groups in its earlier place" do
|
|
2558
|
+
groups = types_groups( ['module.h', 'base.h'], ['base.h'] )
|
|
2559
|
+
|
|
2560
|
+
expect( filenames( groups ) ).to eq( [['base.h'], []] )
|
|
2561
|
+
end
|
|
2562
|
+
|
|
2563
|
+
# The place a missing own header holds is no header, so it can't name another module
|
|
2564
|
+
it "names no mocked module through the place a missing own header holds" do
|
|
2565
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
2566
|
+
.with('calibration').and_return('ceedling_partial_calibration_interface.h')
|
|
2567
|
+
|
|
2568
|
+
groups = @partializer.remap_types_header_includes(
|
|
2569
|
+
name: 'sensors/Calibration', source_includes: [], header_includes: [UserInclude.new( 'base.h' )],
|
|
2570
|
+
partials: {
|
|
2571
|
+
'sensors/Calibration' => make_partial_config(mocks_type: :private, header: 'src/sensors/Calibration.h'),
|
|
2572
|
+
'calibration' => make_partial_config(mocks_type: :private, header: 'src/calibration.h')
|
|
2573
|
+
}
|
|
2574
|
+
)
|
|
2575
|
+
|
|
2576
|
+
expect( filenames( groups ) ).to eq( [['base.h'], []] )
|
|
2577
|
+
end
|
|
2578
|
+
|
|
2579
|
+
# A bare name claims its basename, but not a header that a same-named module named by
|
|
2580
|
+
# directory claims by its path
|
|
2581
|
+
it "leaves a same-named module named by directory its own header" do
|
|
2582
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
2583
|
+
.with('drivers/zspi/config').and_return('drivers/zspi/ceedling_partial_config_interface.h')
|
|
2584
|
+
|
|
2585
|
+
groups = @partializer.remap_types_header_includes(
|
|
2586
|
+
name: 'config', source_includes: [], header_includes: [UserInclude.new( 'include/drivers/zspi/config.h' )],
|
|
2587
|
+
partials: {
|
|
2588
|
+
'config' => make_partial_config(tests_type: :public, header: 'include/drivers/uart/config.h'),
|
|
2589
|
+
'drivers/zspi/config' => make_partial_config(mocks_type: :private, header: 'include/drivers/zspi/config.h')
|
|
2590
|
+
}
|
|
2591
|
+
)
|
|
2592
|
+
|
|
2593
|
+
expect( groups.leading.map( &:filepath ) ).to eq( ['drivers/zspi/ceedling_partial_config_interface.h'] )
|
|
2594
|
+
expect( groups.following ).to eq( [] )
|
|
2595
|
+
end
|
|
2596
|
+
|
|
2597
|
+
it "leaves nothing to follow when the source never includes the module's header" do
|
|
2598
|
+
groups = types_groups( ['a.h', 'b.h'], ['c.h'] )
|
|
2599
|
+
|
|
2600
|
+
expect( filenames( groups ) ).to eq( [['a.h', 'b.h', 'c.h'], []] )
|
|
2601
|
+
end
|
|
2602
|
+
|
|
2603
|
+
it "keeps a system include ahead of everything" do
|
|
2604
|
+
groups = @partializer.remap_types_header_includes(
|
|
2605
|
+
name: 'module', source_includes: [UserInclude.new( 'module.h' ), SystemInclude.new( 'stdint.h' )],
|
|
2606
|
+
header_includes: [], partials: {}
|
|
2607
|
+
)
|
|
2608
|
+
|
|
2609
|
+
expect( filenames( groups ) ).to eq( [['stdint.h'], []] )
|
|
2610
|
+
end
|
|
2611
|
+
|
|
2612
|
+
it "redirects a mocked dependency within the following group" do
|
|
2613
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
2614
|
+
.with('other').and_return('ceedling_partial_other_interface.h')
|
|
2615
|
+
|
|
2616
|
+
groups = types_groups( ['module.h', 'other.h'], partials: { 'other' => make_partial_config(mocks_type: :public) } )
|
|
2617
|
+
|
|
2618
|
+
expect( filenames( groups ) ).to eq( [[], ['ceedling_partial_other_interface.h']] )
|
|
2619
|
+
end
|
|
2620
|
+
|
|
2621
|
+
it "logs every include and no boundary" do
|
|
2622
|
+
expect(@loginator).to receive(:log_list).with(
|
|
2623
|
+
[UserInclude.new( 'config.h' ), UserInclude.new( 'log.h' )], anything, Verbosity::OBNOXIOUS
|
|
2624
|
+
)
|
|
2625
|
+
|
|
2626
|
+
@partializer.remap_types_header_includes(
|
|
2627
|
+
name: 'module', source_includes: [UserInclude.new( 'config.h' ), UserInclude.new( 'module.h' ), UserInclude.new( 'log.h' )],
|
|
2628
|
+
partials: {}, test: 'a_test'
|
|
2629
|
+
)
|
|
2630
|
+
end
|
|
2631
|
+
end
|
|
2632
|
+
|
|
1542
2633
|
# Nothing replaces this module's own header here. The types header cannot include itself, so
|
|
1543
2634
|
# its own entry is simply dropped.
|
|
1544
2635
|
it "drops the module's own header without substituting anything" do
|
|
1545
2636
|
result = @partializer.remap_types_header_includes(
|
|
1546
2637
|
name: 'module',
|
|
1547
|
-
|
|
2638
|
+
source_includes: [UserInclude.new('module.h'), UserInclude.new('foundation.h')],
|
|
1548
2639
|
partials: {}
|
|
1549
|
-
)
|
|
2640
|
+
).to_a
|
|
1550
2641
|
|
|
1551
2642
|
expect( result ).to eq([UserInclude.new('foundation.h')])
|
|
1552
2643
|
end
|
|
@@ -1554,9 +2645,9 @@ describe Partializer do
|
|
|
1554
2645
|
it "keeps every other include in its original relative order" do
|
|
1555
2646
|
result = @partializer.remap_types_header_includes(
|
|
1556
2647
|
name: 'module',
|
|
1557
|
-
|
|
2648
|
+
source_includes: [UserInclude.new('first.h'), UserInclude.new('module.h'), UserInclude.new('last.h')],
|
|
1558
2649
|
partials: {}
|
|
1559
|
-
)
|
|
2650
|
+
).to_a
|
|
1560
2651
|
|
|
1561
2652
|
expect( result.map( &:filename ) ).to eq(['first.h', 'last.h'])
|
|
1562
2653
|
end
|
|
@@ -1571,19 +2662,35 @@ describe Partializer do
|
|
|
1571
2662
|
|
|
1572
2663
|
result = @partializer.remap_types_header_includes(
|
|
1573
2664
|
name: 'module',
|
|
1574
|
-
|
|
2665
|
+
source_includes: [UserInclude.new('module.h'), UserInclude.new('other.h')],
|
|
1575
2666
|
partials: { 'other' => make_partial_config(mocks_type: :public) }
|
|
1576
|
-
)
|
|
2667
|
+
).to_a
|
|
1577
2668
|
|
|
1578
2669
|
expect( result.map( &:filename ) ).to eq(['ceedling_partial_other_interface.h'])
|
|
1579
2670
|
end
|
|
1580
2671
|
|
|
2672
|
+
# Whatever the real header declared, the includes after it could rely on. Its interface
|
|
2673
|
+
# header declares the same names, so it belongs at the same place.
|
|
2674
|
+
it "puts a mocked dependency's interface header where its real header was" do
|
|
2675
|
+
allow(@file_path_utils).to receive(:form_partial_interface_header_filename)
|
|
2676
|
+
.with('other')
|
|
2677
|
+
.and_return('ceedling_partial_other_interface.h')
|
|
2678
|
+
|
|
2679
|
+
result = @partializer.remap_types_header_includes(
|
|
2680
|
+
name: 'module',
|
|
2681
|
+
source_includes: [UserInclude.new('first.h'), UserInclude.new('other.h'), UserInclude.new('last.h'), UserInclude.new('module.h')],
|
|
2682
|
+
partials: { 'other' => make_partial_config(mocks_type: :public) }
|
|
2683
|
+
).to_a
|
|
2684
|
+
|
|
2685
|
+
expect( result.map( &:filename ) ).to eq(['first.h', 'ceedling_partial_other_interface.h', 'last.h'])
|
|
2686
|
+
end
|
|
2687
|
+
|
|
1581
2688
|
it "drops a partialized dependency that is not mocked" do
|
|
1582
2689
|
result = @partializer.remap_types_header_includes(
|
|
1583
2690
|
name: 'module',
|
|
1584
|
-
|
|
2691
|
+
source_includes: [UserInclude.new('module.h'), UserInclude.new('other.h')],
|
|
1585
2692
|
partials: { 'other' => make_partial_config(tests_type: :public) }
|
|
1586
|
-
)
|
|
2693
|
+
).to_a
|
|
1587
2694
|
|
|
1588
2695
|
expect( result ).to be_empty
|
|
1589
2696
|
end
|
|
@@ -1593,9 +2700,9 @@ describe Partializer do
|
|
|
1593
2700
|
it "leaves a header whose name only extends a partialized module's name" do
|
|
1594
2701
|
result = @partializer.remap_types_header_includes(
|
|
1595
2702
|
name: 'module',
|
|
1596
|
-
|
|
2703
|
+
source_includes: [UserInclude.new('module.h'), UserInclude.new('other_extra.h'), UserInclude.new('other.h')],
|
|
1597
2704
|
partials: { 'other' => make_partial_config(tests_type: :public) }
|
|
1598
|
-
)
|
|
2705
|
+
).to_a
|
|
1599
2706
|
|
|
1600
2707
|
expect( result.map( &:filename ) ).to eq(['other_extra.h'])
|
|
1601
2708
|
end
|
|
@@ -1609,9 +2716,9 @@ describe Partializer do
|
|
|
1609
2716
|
|
|
1610
2717
|
result = @partializer.remap_types_header_includes(
|
|
1611
2718
|
name: 'module',
|
|
1612
|
-
|
|
2719
|
+
source_includes: [UserInclude.new('module.h'), UserInclude.new('foundation.h')],
|
|
1613
2720
|
partials: { 'module' => make_partial_config(tests_type: :public, mocks_type: :private) }
|
|
1614
|
-
)
|
|
2721
|
+
).to_a
|
|
1615
2722
|
|
|
1616
2723
|
expect( result.map( &:filename ) ).to eq(['foundation.h'])
|
|
1617
2724
|
end
|
|
@@ -1625,10 +2732,10 @@ describe Partializer do
|
|
|
1625
2732
|
|
|
1626
2733
|
@partializer.remap_types_header_includes(
|
|
1627
2734
|
name: 'module',
|
|
1628
|
-
|
|
2735
|
+
source_includes: [UserInclude.new('foundation.h')],
|
|
1629
2736
|
partials: {},
|
|
1630
2737
|
test: 'a_test'
|
|
1631
|
-
)
|
|
2738
|
+
).to_a
|
|
1632
2739
|
end
|
|
1633
2740
|
end
|
|
1634
2741
|
|
|
@@ -1643,21 +2750,43 @@ describe Partializer do
|
|
|
1643
2750
|
# associate_function_line_numbers is called for every file processed; stub by default
|
|
1644
2751
|
allow(@partializer_helper).to receive(:associate_function_line_numbers)
|
|
1645
2752
|
# static var extraction/promotion called for every file processed; stub by default
|
|
1646
|
-
allow(@partializer_helper).to receive(:
|
|
2753
|
+
allow(@partializer_helper).to receive(:promote_function_scope_statics)
|
|
2754
|
+
allow(@partializer_helper).to receive(:validate_function_names_readable)
|
|
2755
|
+
end
|
|
2756
|
+
|
|
2757
|
+
# Every later step finds a definition by its name
|
|
2758
|
+
it "stops on a definition it can't name before anything reads the name" do
|
|
2759
|
+
unnamed = CExtractorTypes::CFunctionDefinition.new(name: nil, signature: 'int __count__(void)')
|
|
2760
|
+
source_contents = CExtractorTypes::CModule.new(function_definitions: [unnamed])
|
|
2761
|
+
|
|
2762
|
+
config = PartializerConfig::Config.new(
|
|
2763
|
+
module: 'module1',
|
|
2764
|
+
header: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil),
|
|
2765
|
+
source: Partials::ConfigFileInfo.new(filepath: '/src/module1.c', assembled_filepath: '/build/preproc/module1.i')
|
|
2766
|
+
)
|
|
2767
|
+
|
|
2768
|
+
allow(@c_extractor).to receive(:from_file).and_return(source_contents)
|
|
2769
|
+
expect(@partializer_helper).to receive(:validate_function_names_readable)
|
|
2770
|
+
.with(source_contents, @name, 'module1').and_raise(CeedlingException, 'unreadable')
|
|
2771
|
+
expect(@partializer_helper).not_to receive(:associate_function_line_numbers)
|
|
2772
|
+
expect(@partializer_helper).not_to receive(:promote_function_scope_statics)
|
|
2773
|
+
|
|
2774
|
+
expect { @partializer.extract_module_contents(@name, config) }
|
|
2775
|
+
.to raise_error(CeedlingException, 'unreadable')
|
|
1647
2776
|
end
|
|
1648
2777
|
|
|
1649
|
-
it "returns empty CModule when both
|
|
1650
|
-
config =
|
|
2778
|
+
it "returns empty CModule when both assembled_filepaths are nil" do
|
|
2779
|
+
config = PartializerConfig::Config.new(
|
|
1651
2780
|
module: 'module1',
|
|
1652
|
-
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h',
|
|
1653
|
-
source: Partials::ConfigFileInfo.new(filepath: '/path/to/source.c',
|
|
2781
|
+
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h', assembled_filepath: nil),
|
|
2782
|
+
source: Partials::ConfigFileInfo.new(filepath: '/path/to/source.c', assembled_filepath: nil)
|
|
1654
2783
|
)
|
|
1655
2784
|
|
|
1656
2785
|
expect(@c_extractor).not_to receive(:from_file)
|
|
1657
2786
|
expect(@partializer_helper).not_to receive(:associate_function_line_numbers)
|
|
1658
|
-
expect(@partializer_helper).not_to receive(:
|
|
2787
|
+
expect(@partializer_helper).not_to receive(:promote_function_scope_statics)
|
|
1659
2788
|
|
|
1660
|
-
result = @partializer.extract_module_contents(@name, config
|
|
2789
|
+
result = @partializer.extract_module_contents(@name, config)
|
|
1661
2790
|
|
|
1662
2791
|
expect(result.function_definitions).to eq([])
|
|
1663
2792
|
expect(result.variable_declarations).to eq([])
|
|
@@ -1665,23 +2794,23 @@ describe Partializer do
|
|
|
1665
2794
|
|
|
1666
2795
|
it "extracts contents from header preprocessed file only" do
|
|
1667
2796
|
header_funcs = [
|
|
1668
|
-
|
|
1669
|
-
|
|
2797
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func1', signature: 'void func1(void)'),
|
|
2798
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func2', signature: 'int func2(int x)')
|
|
1670
2799
|
]
|
|
1671
2800
|
header_contents = CExtractorTypes::CModule.new(function_definitions: header_funcs, variable_declarations: [])
|
|
1672
2801
|
|
|
1673
|
-
config =
|
|
2802
|
+
config = PartializerConfig::Config.new(
|
|
1674
2803
|
module: 'module1',
|
|
1675
|
-
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h',
|
|
1676
|
-
source: Partials::ConfigFileInfo.new(filepath: nil,
|
|
2804
|
+
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h', assembled_filepath: '/build/preproc/header.i'),
|
|
2805
|
+
source: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil)
|
|
1677
2806
|
)
|
|
1678
2807
|
|
|
1679
2808
|
expect(@c_extractor).to receive(:from_file).with('/build/preproc/header.i').and_return(header_contents)
|
|
1680
2809
|
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1681
|
-
|
|
2810
|
+
funcs: header_funcs, filepath: '/path/to/header.h', raw_filepath: nil
|
|
1682
2811
|
)
|
|
1683
2812
|
|
|
1684
|
-
result = @partializer.extract_module_contents(@name, config
|
|
2813
|
+
result = @partializer.extract_module_contents(@name, config)
|
|
1685
2814
|
|
|
1686
2815
|
expect(result.function_definitions).to eq(header_funcs)
|
|
1687
2816
|
expect(result.variable_declarations).to eq([])
|
|
@@ -1689,23 +2818,23 @@ describe Partializer do
|
|
|
1689
2818
|
|
|
1690
2819
|
it "extracts contents from source preprocessed file only" do
|
|
1691
2820
|
source_funcs = [
|
|
1692
|
-
|
|
1693
|
-
|
|
2821
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func1', signature: 'static void func1(void)'),
|
|
2822
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func2', signature: 'static int func2(int x)')
|
|
1694
2823
|
]
|
|
1695
2824
|
source_contents = CExtractorTypes::CModule.new(function_definitions: source_funcs, variable_declarations: [])
|
|
1696
2825
|
|
|
1697
|
-
config =
|
|
2826
|
+
config = PartializerConfig::Config.new(
|
|
1698
2827
|
module: 'module1',
|
|
1699
|
-
header: Partials::ConfigFileInfo.new(filepath: nil,
|
|
1700
|
-
source: Partials::ConfigFileInfo.new(filepath: '/path/to/source.c',
|
|
2828
|
+
header: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil),
|
|
2829
|
+
source: Partials::ConfigFileInfo.new(filepath: '/path/to/source.c', assembled_filepath: '/build/preproc/source.i')
|
|
1701
2830
|
)
|
|
1702
2831
|
|
|
1703
2832
|
expect(@c_extractor).to receive(:from_file).with('/build/preproc/source.i').and_return(source_contents)
|
|
1704
2833
|
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1705
|
-
|
|
2834
|
+
funcs: source_funcs, filepath: '/path/to/source.c', raw_filepath: nil
|
|
1706
2835
|
)
|
|
1707
2836
|
|
|
1708
|
-
result = @partializer.extract_module_contents(@name, config
|
|
2837
|
+
result = @partializer.extract_module_contents(@name, config)
|
|
1709
2838
|
|
|
1710
2839
|
expect(result.function_definitions).to eq(source_funcs)
|
|
1711
2840
|
expect(result.variable_declarations).to eq([])
|
|
@@ -1713,194 +2842,316 @@ describe Partializer do
|
|
|
1713
2842
|
|
|
1714
2843
|
it "extracts and merges contents from both source and header preprocessed files" do
|
|
1715
2844
|
source_funcs = [
|
|
1716
|
-
|
|
1717
|
-
|
|
2845
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func1', signature: 'static void func1(void)'),
|
|
2846
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func2', signature: 'static int func2(int x)')
|
|
1718
2847
|
]
|
|
1719
2848
|
header_funcs = [
|
|
1720
|
-
|
|
1721
|
-
|
|
2849
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func3', signature: 'void func3(void)'),
|
|
2850
|
+
CExtractorTypes::CFunctionDefinition.new(name: 'func4', signature: 'int func4(int x)')
|
|
1722
2851
|
]
|
|
1723
|
-
source_contents = CExtractorTypes::CModule.new(function_definitions: source_funcs, variable_declarations: [
|
|
1724
|
-
header_contents = CExtractorTypes::CModule.new(function_definitions: header_funcs, variable_declarations: [
|
|
2852
|
+
source_contents = CExtractorTypes::CModule.new(function_definitions: source_funcs, variable_declarations: [CExtractorTypes::CVariableDeclaration.new(name: 'var1')])
|
|
2853
|
+
header_contents = CExtractorTypes::CModule.new(function_definitions: header_funcs, variable_declarations: [CExtractorTypes::CVariableDeclaration.new(name: 'var2')])
|
|
1725
2854
|
|
|
1726
|
-
config =
|
|
2855
|
+
config = PartializerConfig::Config.new(
|
|
1727
2856
|
module: 'module1',
|
|
1728
|
-
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h',
|
|
1729
|
-
source: Partials::ConfigFileInfo.new(filepath: '/path/to/source.c',
|
|
2857
|
+
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h', assembled_filepath: '/build/preproc/header.i'),
|
|
2858
|
+
source: Partials::ConfigFileInfo.new(filepath: '/path/to/source.c', assembled_filepath: '/build/preproc/source.i')
|
|
1730
2859
|
)
|
|
1731
2860
|
|
|
1732
2861
|
allow(@c_extractor).to receive(:from_file).with('/build/preproc/source.i').and_return(source_contents)
|
|
1733
2862
|
allow(@c_extractor).to receive(:from_file).with('/build/preproc/header.i').and_return(header_contents)
|
|
1734
2863
|
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1735
|
-
|
|
2864
|
+
funcs: source_funcs, filepath: '/path/to/source.c', raw_filepath: nil
|
|
1736
2865
|
)
|
|
1737
2866
|
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1738
|
-
|
|
2867
|
+
funcs: header_funcs, filepath: '/path/to/header.h', raw_filepath: nil
|
|
1739
2868
|
)
|
|
1740
2869
|
|
|
1741
|
-
result = @partializer.extract_module_contents(@name, config
|
|
2870
|
+
result = @partializer.extract_module_contents(@name, config)
|
|
1742
2871
|
|
|
1743
2872
|
expect(result.function_definitions).to eq(header_funcs + source_funcs)
|
|
1744
2873
|
expect(result.variable_declarations).to eq(header_contents.variable_declarations + source_contents.variable_declarations)
|
|
1745
2874
|
end
|
|
1746
2875
|
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
config = Partials::Config.new(
|
|
1752
|
-
module: 'module1',
|
|
1753
|
-
header: Partials::ConfigFileInfo.new(filepath: nil, directives_only_filepath: nil),
|
|
1754
|
-
source: Partials::ConfigFileInfo.new(filepath: '/src/module1.c', directives_only_filepath: '/build/preproc/module1.i')
|
|
1755
|
-
)
|
|
1756
|
-
|
|
1757
|
-
allow(@c_extractor).to receive(:from_file).and_return(source_contents)
|
|
1758
|
-
|
|
1759
|
-
# associate_function_line_numbers must receive the original filepath, not the preprocessed one
|
|
1760
|
-
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1761
|
-
name: @name, funcs: source_funcs, filepath: '/src/module1.c', fallback: false
|
|
1762
|
-
)
|
|
1763
|
-
|
|
1764
|
-
@partializer.extract_module_contents(@name, config, fallback: false)
|
|
1765
|
-
end
|
|
1766
|
-
|
|
1767
|
-
it "passes extraction name through to associate_function_line_numbers" do
|
|
1768
|
-
source_funcs = [double('func1', name: 'func1')]
|
|
2876
|
+
# The original filepath names each function, and the raw copy locates it
|
|
2877
|
+
it "locates each file's functions in the raw copy its record names, under the original filepath" do
|
|
2878
|
+
source_funcs = [CExtractorTypes::CFunctionDefinition.new(name: 'func1')]
|
|
1769
2879
|
source_contents = CExtractorTypes::CModule.new(function_definitions: source_funcs, variable_declarations: [])
|
|
1770
2880
|
|
|
1771
|
-
config =
|
|
2881
|
+
config = PartializerConfig::Config.new(
|
|
1772
2882
|
module: 'module1',
|
|
1773
|
-
header: Partials::ConfigFileInfo.new(filepath: nil,
|
|
1774
|
-
source: Partials::ConfigFileInfo.new(
|
|
2883
|
+
header: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil),
|
|
2884
|
+
source: Partials::ConfigFileInfo.new(
|
|
2885
|
+
filepath: '/src/module1.c', assembled_filepath: '/build/preproc/module1.i', raw_directives_only_filepath: '/build/raw/module1.c'
|
|
2886
|
+
)
|
|
1775
2887
|
)
|
|
1776
2888
|
|
|
1777
2889
|
allow(@c_extractor).to receive(:from_file).and_return(source_contents)
|
|
1778
2890
|
|
|
1779
2891
|
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1780
|
-
|
|
2892
|
+
funcs: source_funcs, filepath: '/src/module1.c', raw_filepath: '/build/raw/module1.c'
|
|
1781
2893
|
)
|
|
1782
2894
|
|
|
1783
|
-
@partializer.extract_module_contents(
|
|
2895
|
+
@partializer.extract_module_contents(@name, config)
|
|
1784
2896
|
end
|
|
1785
2897
|
|
|
1786
2898
|
it "returns empty CModule when a preprocessed file has no contents" do
|
|
1787
2899
|
empty_contents = CExtractorTypes::CModule.new(function_definitions: [], variable_declarations: [])
|
|
1788
2900
|
|
|
1789
|
-
config =
|
|
2901
|
+
config = PartializerConfig::Config.new(
|
|
1790
2902
|
module: 'module1',
|
|
1791
|
-
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h',
|
|
1792
|
-
source: Partials::ConfigFileInfo.new(filepath: nil,
|
|
2903
|
+
header: Partials::ConfigFileInfo.new(filepath: '/path/to/header.h', assembled_filepath: '/build/preproc/header.i'),
|
|
2904
|
+
source: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil)
|
|
1793
2905
|
)
|
|
1794
2906
|
|
|
1795
2907
|
expect(@c_extractor).to receive(:from_file).and_return(empty_contents)
|
|
1796
2908
|
expect(@partializer_helper).to receive(:associate_function_line_numbers).with(
|
|
1797
|
-
|
|
2909
|
+
funcs: [], filepath: '/path/to/header.h', raw_filepath: nil
|
|
1798
2910
|
)
|
|
1799
2911
|
|
|
1800
|
-
result = @partializer.extract_module_contents(@name, config
|
|
2912
|
+
result = @partializer.extract_module_contents(@name, config)
|
|
1801
2913
|
|
|
1802
2914
|
expect(result.function_definitions).to eq([])
|
|
1803
2915
|
expect(result.variable_declarations).to eq([])
|
|
1804
2916
|
end
|
|
1805
2917
|
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
promoted_var2 = CExtractorTypes::CVariableDeclaration.new(text: 'static bool flag = false;', type: 'bool', name: 'flag')
|
|
1809
|
-
|
|
2918
|
+
# Promotion adds to the file's own module, ahead of each function, before the module merges
|
|
2919
|
+
it "promotes function-scope statics in each file's module" do
|
|
1810
2920
|
source_contents = CExtractorTypes::CModule.new(function_definitions: [], variable_declarations: [])
|
|
1811
2921
|
|
|
1812
|
-
config =
|
|
2922
|
+
config = PartializerConfig::Config.new(
|
|
1813
2923
|
module: 'module1',
|
|
1814
|
-
header: Partials::ConfigFileInfo.new(filepath: nil,
|
|
1815
|
-
source: Partials::ConfigFileInfo.new(filepath: '/src/module1.c',
|
|
2924
|
+
header: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil),
|
|
2925
|
+
source: Partials::ConfigFileInfo.new(filepath: '/src/module1.c', assembled_filepath: '/build/preproc/module1.i')
|
|
1816
2926
|
)
|
|
1817
2927
|
|
|
1818
2928
|
allow(@c_extractor).to receive(:from_file).and_return(source_contents)
|
|
1819
|
-
|
|
2929
|
+
expect(@partializer_helper).to receive(:promote_function_scope_statics)
|
|
2930
|
+
.with(source_contents, name: @name, module_name: 'module1', file_type: 'source')
|
|
1820
2931
|
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
expect(result.element_sequence).to eq([promoted_var1, promoted_var2])
|
|
1824
|
-
expect(result.element_sequence[0]).to equal(promoted_var1)
|
|
1825
|
-
expect(result.element_sequence[1]).to equal(promoted_var2)
|
|
2932
|
+
@partializer.extract_module_contents(@name, config)
|
|
1826
2933
|
end
|
|
1827
2934
|
|
|
1828
|
-
it "
|
|
1829
|
-
source_funcs = [
|
|
2935
|
+
it "reconciles the source's module with its expanded code when the record names one" do
|
|
2936
|
+
source_funcs = [CExtractorTypes::CFunctionDefinition.new(name: 'func1')]
|
|
1830
2937
|
source_contents = CExtractorTypes::CModule.new(function_definitions: source_funcs, variable_declarations: [])
|
|
1831
2938
|
|
|
1832
|
-
config =
|
|
2939
|
+
config = PartializerConfig::Config.new(
|
|
1833
2940
|
module: 'module1',
|
|
1834
|
-
header: Partials::ConfigFileInfo.new(filepath: nil,
|
|
2941
|
+
header: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil),
|
|
1835
2942
|
source: Partials::ConfigFileInfo.new(
|
|
1836
|
-
filepath:
|
|
1837
|
-
|
|
1838
|
-
|
|
2943
|
+
filepath: '/src/module1.c',
|
|
2944
|
+
assembled_filepath: '/build/preproc/module1.i',
|
|
2945
|
+
expansion_filepath: '/build/preproc/full_expansion/module1.c'
|
|
1839
2946
|
)
|
|
1840
2947
|
)
|
|
1841
2948
|
|
|
1842
2949
|
allow(@c_extractor).to receive(:from_file).with('/build/preproc/module1.i').and_return(source_contents)
|
|
1843
2950
|
allow(@partializer_helper).to receive(:associate_function_line_numbers)
|
|
1844
2951
|
|
|
1845
|
-
expect(@
|
|
1846
|
-
|
|
1847
|
-
full_expansion_filepath: '/build/preproc/full_expansion/module1.c',
|
|
1848
|
-
name: @name,
|
|
1849
|
-
module_name: 'module1',
|
|
1850
|
-
file_type: 'source'
|
|
2952
|
+
expect(@partializer_reconciler).to receive(:reconcile).with(
|
|
2953
|
+
c_module: source_contents, expansion_filepath: '/build/preproc/full_expansion/module1.c', name: @name, module_name: 'module1', file_type: 'source'
|
|
1851
2954
|
)
|
|
1852
2955
|
|
|
1853
|
-
@partializer.extract_module_contents(@name, config
|
|
2956
|
+
@partializer.extract_module_contents(@name, config)
|
|
1854
2957
|
end
|
|
1855
2958
|
|
|
1856
|
-
it "
|
|
1857
|
-
header_funcs = [
|
|
2959
|
+
it "reconciles the header's module with its expanded code when the record names one" do
|
|
2960
|
+
header_funcs = [CExtractorTypes::CFunctionDefinition.new(name: 'func1')]
|
|
1858
2961
|
header_contents = CExtractorTypes::CModule.new(function_definitions: header_funcs, variable_declarations: [])
|
|
1859
2962
|
|
|
1860
|
-
config =
|
|
2963
|
+
config = PartializerConfig::Config.new(
|
|
1861
2964
|
module: 'module1',
|
|
1862
2965
|
header: Partials::ConfigFileInfo.new(
|
|
1863
|
-
filepath:
|
|
1864
|
-
|
|
1865
|
-
|
|
2966
|
+
filepath: '/path/to/header.h',
|
|
2967
|
+
assembled_filepath: '/build/preproc/header.h',
|
|
2968
|
+
expansion_filepath: '/build/preproc/full_expansion/header.h'
|
|
1866
2969
|
),
|
|
1867
|
-
source: Partials::ConfigFileInfo.new(filepath: nil,
|
|
2970
|
+
source: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil)
|
|
1868
2971
|
)
|
|
1869
2972
|
|
|
1870
2973
|
allow(@c_extractor).to receive(:from_file).with('/build/preproc/header.h').and_return(header_contents)
|
|
1871
2974
|
allow(@partializer_helper).to receive(:associate_function_line_numbers)
|
|
1872
2975
|
|
|
1873
|
-
expect(@
|
|
1874
|
-
|
|
1875
|
-
full_expansion_filepath: '/build/preproc/full_expansion/header.h',
|
|
1876
|
-
name: @name,
|
|
1877
|
-
module_name: 'module1',
|
|
1878
|
-
file_type: 'header'
|
|
2976
|
+
expect(@partializer_reconciler).to receive(:reconcile).with(
|
|
2977
|
+
c_module: header_contents, expansion_filepath: '/build/preproc/full_expansion/header.h', name: @name, module_name: 'module1', file_type: 'header'
|
|
1879
2978
|
)
|
|
1880
2979
|
|
|
1881
|
-
@partializer.extract_module_contents(@name, config
|
|
2980
|
+
@partializer.extract_module_contents(@name, config)
|
|
1882
2981
|
end
|
|
1883
2982
|
|
|
1884
|
-
it "
|
|
1885
|
-
source_funcs = [
|
|
2983
|
+
it "reconciles nothing when the record names no expanded code" do
|
|
2984
|
+
source_funcs = [CExtractorTypes::CFunctionDefinition.new(name: 'func1')]
|
|
1886
2985
|
source_contents = CExtractorTypes::CModule.new(function_definitions: source_funcs, variable_declarations: [])
|
|
1887
2986
|
|
|
1888
|
-
config =
|
|
2987
|
+
config = PartializerConfig::Config.new(
|
|
1889
2988
|
module: 'module1',
|
|
1890
|
-
header: Partials::ConfigFileInfo.new(filepath: nil,
|
|
2989
|
+
header: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil),
|
|
1891
2990
|
source: Partials::ConfigFileInfo.new(
|
|
1892
|
-
filepath:
|
|
1893
|
-
|
|
1894
|
-
|
|
2991
|
+
filepath: '/src/module1.c',
|
|
2992
|
+
assembled_filepath: '/build/preproc/module1.i',
|
|
2993
|
+
expansion_filepath: nil
|
|
1895
2994
|
)
|
|
1896
2995
|
)
|
|
1897
2996
|
|
|
1898
2997
|
allow(@c_extractor).to receive(:from_file).with('/build/preproc/module1.i').and_return(source_contents)
|
|
1899
2998
|
allow(@partializer_helper).to receive(:associate_function_line_numbers)
|
|
1900
2999
|
|
|
1901
|
-
expect(@
|
|
3000
|
+
expect(@partializer_reconciler).not_to receive(:reconcile)
|
|
3001
|
+
|
|
3002
|
+
@partializer.extract_module_contents(@name, config)
|
|
3003
|
+
end
|
|
3004
|
+
|
|
3005
|
+
# Locating declarations costs a search of the file's text each, so only carried ones are located
|
|
3006
|
+
it "leaves declarations unlocated during extraction" do
|
|
3007
|
+
config = PartializerConfig::Config.new(
|
|
3008
|
+
module: 'module1',
|
|
3009
|
+
header: Partials::ConfigFileInfo.new(filepath: '/src/module1.h', assembled_filepath: '/build/preproc/module1.h'),
|
|
3010
|
+
source: Partials::ConfigFileInfo.new(filepath: nil, assembled_filepath: nil)
|
|
3011
|
+
)
|
|
3012
|
+
decls = [CExtractorTypes::CFunctionDeclaration.new(name: 'tick', signature: 'int tick(void);')]
|
|
3013
|
+
allow(@c_extractor).to receive(:from_file).and_return(CExtractorTypes::CModule.new(function_declarations: decls))
|
|
3014
|
+
|
|
3015
|
+
expect(@partializer_helper).not_to receive(:associate_declaration_line_numbers)
|
|
3016
|
+
expect(@file_wrapper).not_to receive(:read)
|
|
3017
|
+
|
|
3018
|
+
@partializer.extract_module_contents(@name, config)
|
|
3019
|
+
end
|
|
3020
|
+
|
|
3021
|
+
context "marking functions an included header defines inline" do
|
|
3022
|
+
# Each file's record names the raw copy its preprocessing kept
|
|
3023
|
+
def file(filepath, raw: nil)
|
|
3024
|
+
Partials::ConfigFileInfo.new(
|
|
3025
|
+
filepath: filepath, assembled_filepath: filepath && "/build/preproc/#{File.basename( filepath )}", raw_directives_only_filepath: raw
|
|
3026
|
+
)
|
|
3027
|
+
end
|
|
3028
|
+
|
|
3029
|
+
let(:config) do
|
|
3030
|
+
PartializerConfig::Config.new( module: 'engine', header: file( nil ), source: file( 'src/engine.c', raw: 'raw/src/engine.c' ) )
|
|
3031
|
+
end
|
|
3032
|
+
let(:twice) { CExtractorTypes::CFunctionDeclaration.new( name: 'engine_get_twice', signature: 'int engine_get_twice(void);' ) }
|
|
3033
|
+
let(:both_files) do
|
|
3034
|
+
PartializerConfig::Config.new(
|
|
3035
|
+
module: 'engine', header: file( 'src/engine.h', raw: 'raw/src/engine.h' ), source: file( 'src/engine.c', raw: 'raw/src/engine.c' )
|
|
3036
|
+
)
|
|
3037
|
+
end
|
|
3038
|
+
|
|
3039
|
+
# The raw copy holds every header the file includes, so the inline body is found there.
|
|
3040
|
+
# The scan needs only bytes, so the copy is never transcoded.
|
|
3041
|
+
it "marks a source declaration against the source's raw copy, read as bytes" do
|
|
3042
|
+
allow(@c_extractor).to receive(:from_file).and_return(CExtractorTypes::CModule.new(function_declarations: [twice]))
|
|
3043
|
+
allow(@file_wrapper).to receive(:read_binary).with('raw/src/engine.c').and_return('raw bytes')
|
|
3044
|
+
|
|
3045
|
+
expect(@partializer_helper).to receive(:mark_inline_elsewhere).with( decls: [twice], text: 'raw bytes' )
|
|
3046
|
+
expect(@file_wrapper).not_to receive(:read)
|
|
3047
|
+
|
|
3048
|
+
@partializer.extract_module_contents(@name, config)
|
|
3049
|
+
end
|
|
3050
|
+
|
|
3051
|
+
# A module mocked from its header alone has no source, and every declaration is the header's
|
|
3052
|
+
it "marks a header-only Partial's declarations against the header's raw copy" do
|
|
3053
|
+
header_only = PartializerConfig::Config.new( module: 'engine', header: file( 'src/engine.h', raw: 'raw/src/engine.h' ), source: file( nil ) )
|
|
3054
|
+
allow(@c_extractor).to receive(:from_file).and_return(CExtractorTypes::CModule.new(function_declarations: [twice]))
|
|
3055
|
+
allow(@file_wrapper).to receive(:read_binary).with('raw/src/engine.h').and_return('header bytes')
|
|
3056
|
+
|
|
3057
|
+
expect(@partializer_helper).to receive(:mark_inline_elsewhere).with( decls: [twice], text: 'header bytes' )
|
|
3058
|
+
|
|
3059
|
+
@partializer.extract_module_contents(@name, header_only)
|
|
3060
|
+
end
|
|
3061
|
+
|
|
3062
|
+
# Each file's raw copy holds the headers that file includes, so each is searched for its own
|
|
3063
|
+
it "marks each file's declarations against that file's own raw copy" do
|
|
3064
|
+
tick = CExtractorTypes::CFunctionDeclaration.new( name: 'board_tick', signature: 'int board_tick(void);' )
|
|
3065
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/engine.h').and_return(
|
|
3066
|
+
CExtractorTypes::CModule.new(function_declarations: [tick])
|
|
3067
|
+
)
|
|
3068
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/engine.c').and_return(
|
|
3069
|
+
CExtractorTypes::CModule.new(function_declarations: [twice])
|
|
3070
|
+
)
|
|
3071
|
+
allow(@file_wrapper).to receive(:read_binary).with('raw/src/engine.h').and_return('header bytes')
|
|
3072
|
+
allow(@file_wrapper).to receive(:read_binary).with('raw/src/engine.c').and_return('source bytes')
|
|
3073
|
+
|
|
3074
|
+
expect(@partializer_helper).to receive(:mark_inline_elsewhere).with( decls: [tick], text: 'header bytes' )
|
|
3075
|
+
expect(@partializer_helper).to receive(:mark_inline_elsewhere).with( decls: [twice], text: 'source bytes' )
|
|
3076
|
+
|
|
3077
|
+
@partializer.extract_module_contents(@name, both_files)
|
|
3078
|
+
end
|
|
3079
|
+
|
|
3080
|
+
# Only a function the module has no body for can be defined inline elsewhere
|
|
3081
|
+
it "marks only the header declarations whose function has no body in the module" do
|
|
3082
|
+
get = CExtractorTypes::CFunctionDeclaration.new( name: 'engine_get', signature: 'int engine_get(void);' )
|
|
3083
|
+
tick = CExtractorTypes::CFunctionDeclaration.new( name: 'board_tick', signature: 'int board_tick(void);' )
|
|
3084
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/engine.h').and_return(
|
|
3085
|
+
CExtractorTypes::CModule.new(function_declarations: [get, tick])
|
|
3086
|
+
)
|
|
3087
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/engine.c').and_return(
|
|
3088
|
+
CExtractorTypes::CModule.new(function_definitions: [CExtractorTypes::CFunctionDefinition.new(name: 'engine_get')])
|
|
3089
|
+
)
|
|
3090
|
+
allow(@file_wrapper).to receive(:read_binary).with('raw/src/engine.h').and_return('header bytes')
|
|
3091
|
+
|
|
3092
|
+
expect(@partializer_helper).to receive(:mark_inline_elsewhere).with( decls: [tick], text: 'header bytes' ).once
|
|
3093
|
+
|
|
3094
|
+
@partializer.extract_module_contents(@name, both_files)
|
|
3095
|
+
end
|
|
3096
|
+
|
|
3097
|
+
it "reads no file when every declaration's function has a body in the module" do
|
|
3098
|
+
get = CExtractorTypes::CFunctionDeclaration.new( name: 'engine_get', signature: 'int engine_get(void);' )
|
|
3099
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/engine.h').and_return(
|
|
3100
|
+
CExtractorTypes::CModule.new(function_declarations: [get])
|
|
3101
|
+
)
|
|
3102
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/engine.c').and_return(
|
|
3103
|
+
CExtractorTypes::CModule.new(function_definitions: [CExtractorTypes::CFunctionDefinition.new(name: 'engine_get')])
|
|
3104
|
+
)
|
|
3105
|
+
|
|
3106
|
+
expect(@file_wrapper).not_to receive(:read_binary)
|
|
3107
|
+
expect(@partializer_helper).not_to receive(:mark_inline_elsewhere)
|
|
3108
|
+
|
|
3109
|
+
@partializer.extract_module_contents(@name, both_files)
|
|
3110
|
+
end
|
|
3111
|
+
|
|
3112
|
+
# A file preprocessed in fallback records no raw copy, whatever an earlier build left on disk
|
|
3113
|
+
it "reads no file and marks nothing for a file whose record names no raw copy" do
|
|
3114
|
+
config.source.raw_directives_only_filepath = nil
|
|
3115
|
+
allow(@c_extractor).to receive(:from_file).and_return(CExtractorTypes::CModule.new(function_declarations: [twice]))
|
|
3116
|
+
|
|
3117
|
+
expect(@file_wrapper).not_to receive(:read_binary)
|
|
3118
|
+
expect(@partializer_helper).not_to receive(:mark_inline_elsewhere)
|
|
3119
|
+
|
|
3120
|
+
@partializer.extract_module_contents(@name, config)
|
|
3121
|
+
end
|
|
3122
|
+
|
|
3123
|
+
it "reads no file when the file declares no function" do
|
|
3124
|
+
allow(@c_extractor).to receive(:from_file).and_return(CExtractorTypes::CModule.new)
|
|
3125
|
+
|
|
3126
|
+
expect(@file_wrapper).not_to receive(:read_binary)
|
|
3127
|
+
|
|
3128
|
+
@partializer.extract_module_contents(@name, config)
|
|
3129
|
+
end
|
|
3130
|
+
end
|
|
1902
3131
|
|
|
1903
|
-
|
|
3132
|
+
it "stamps every function with the role of the file it came from" do
|
|
3133
|
+
header_def = CExtractorTypes::CFunctionDefinition.new(name: 'clamp')
|
|
3134
|
+
header_decl = CExtractorTypes::CFunctionDeclaration.new(name: 'tick')
|
|
3135
|
+
source_def = CExtractorTypes::CFunctionDefinition.new(name: 'get')
|
|
3136
|
+
source_decl = CExtractorTypes::CFunctionDeclaration.new(name: 'twice')
|
|
3137
|
+
|
|
3138
|
+
config = PartializerConfig::Config.new(
|
|
3139
|
+
module: 'module1',
|
|
3140
|
+
header: Partials::ConfigFileInfo.new(filepath: '/src/module1.h', assembled_filepath: '/build/preproc/module1.h'),
|
|
3141
|
+
source: Partials::ConfigFileInfo.new(filepath: '/src/module1.c', assembled_filepath: '/build/preproc/module1.c')
|
|
3142
|
+
)
|
|
3143
|
+
|
|
3144
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/module1.h').and_return(
|
|
3145
|
+
CExtractorTypes::CModule.new(function_definitions: [header_def], function_declarations: [header_decl])
|
|
3146
|
+
)
|
|
3147
|
+
allow(@c_extractor).to receive(:from_file).with('/build/preproc/module1.c').and_return(
|
|
3148
|
+
CExtractorTypes::CModule.new(function_definitions: [source_def], function_declarations: [source_decl])
|
|
3149
|
+
)
|
|
3150
|
+
|
|
3151
|
+
@partializer.extract_module_contents(@name, config)
|
|
3152
|
+
|
|
3153
|
+
expect([header_def, header_decl].map(&:origin)).to all(eq(:header))
|
|
3154
|
+
expect([source_def, source_decl].map(&:origin)).to all(eq(:source))
|
|
1904
3155
|
end
|
|
1905
3156
|
end
|
|
1906
3157
|
|
|
@@ -2126,7 +3377,7 @@ describe Partializer do
|
|
|
2126
3377
|
|
|
2127
3378
|
it "merges declaration-only functions into the DEDUCT candidate pool" do
|
|
2128
3379
|
defn = double('inline_func', name: 'inline_fn')
|
|
2129
|
-
decl = double('proto_func', name: 'proto_fn')
|
|
3380
|
+
decl = double('proto_func', name: 'proto_fn', decorators: [], inline_elsewhere: false)
|
|
2130
3381
|
defs = [defn]
|
|
2131
3382
|
decls = [decl]
|
|
2132
3383
|
filtered = [double('iface_inline'), double('iface_proto')]
|
|
@@ -2146,7 +3397,7 @@ describe Partializer do
|
|
|
2146
3397
|
|
|
2147
3398
|
it "merges declaration-only functions into the PUBLIC candidate pool too" do
|
|
2148
3399
|
defn = double('def_func', name: 'pub_def')
|
|
2149
|
-
decl = double('decl_func', name: 'pub_decl')
|
|
3400
|
+
decl = double('decl_func', name: 'pub_decl', decorators: [], inline_elsewhere: false)
|
|
2150
3401
|
defs = [defn]
|
|
2151
3402
|
decls = [decl]
|
|
2152
3403
|
filtered = [double('iface_func')]
|
|
@@ -2164,9 +3415,66 @@ describe Partializer do
|
|
|
2164
3415
|
expect(result).to eq(filtered)
|
|
2165
3416
|
end
|
|
2166
3417
|
|
|
3418
|
+
# Its body lives in a header the module includes, so a mock could never replace it. Mocking
|
|
3419
|
+
# it would only define the function twice.
|
|
3420
|
+
[Partials::DEDUCT, Partials::PRIVATE].each do |type|
|
|
3421
|
+
it "keeps a declaration-only inline function out of the #{type} candidate pool" do
|
|
3422
|
+
defn = double('def_func', name: 'engine_get')
|
|
3423
|
+
foreign = double('extern_inline', name: 'engine_get_twice', decorators: ['extern', 'inline'])
|
|
3424
|
+
filtered = [double('iface_func')]
|
|
3425
|
+
pf = make_pf(type: type)
|
|
3426
|
+
|
|
3427
|
+
expect(@partializer_helper).to receive(:filter_and_transform_funcs)
|
|
3428
|
+
.with([defn], type, :interface).and_return(filtered)
|
|
3429
|
+
allow(@partializer_helper).to receive(:subtract_funcs).and_return(filtered)
|
|
3430
|
+
|
|
3431
|
+
@partializer.extract_interface_functions(
|
|
3432
|
+
test: 'test_mod', partial: 'mod',
|
|
3433
|
+
definitions: [defn], declarations: [foreign], config: make_config(mocks: pf)
|
|
3434
|
+
)
|
|
3435
|
+
end
|
|
3436
|
+
end
|
|
3437
|
+
|
|
3438
|
+
# Declared without `inline`, it is still a function whose body another header holds
|
|
3439
|
+
it "keeps a declaration of a function another header defines inline out of the PUBLIC candidate pool" do
|
|
3440
|
+
defn = double('def_func', name: 'engine_get')
|
|
3441
|
+
foreign = CExtractorTypes::CFunctionDeclaration.new(
|
|
3442
|
+
name: 'engine_get_twice', signature: 'int engine_get_twice(void);', inline_elsewhere: true
|
|
3443
|
+
)
|
|
3444
|
+
filtered = [double('iface_func')]
|
|
3445
|
+
pf = make_pf(type: Partials::PUBLIC)
|
|
3446
|
+
|
|
3447
|
+
expect(@partializer_helper).to receive(:filter_and_transform_funcs)
|
|
3448
|
+
.with([defn], Partials::PUBLIC, :interface).and_return(filtered)
|
|
3449
|
+
allow(@partializer_helper).to receive(:subtract_funcs).and_return(filtered)
|
|
3450
|
+
|
|
3451
|
+
@partializer.extract_interface_functions(
|
|
3452
|
+
test: 'test_mod', partial: 'mod',
|
|
3453
|
+
definitions: [defn], declarations: [foreign], config: make_config(mocks: pf)
|
|
3454
|
+
)
|
|
3455
|
+
end
|
|
3456
|
+
|
|
3457
|
+
it "lists a declaration-only inline function it keeps out, at debug verbosity" do
|
|
3458
|
+
foreign = double('extern_inline', name: 'engine_get_twice', decorators: ['extern', 'inline'])
|
|
3459
|
+
pf = make_pf(type: Partials::DEDUCT)
|
|
3460
|
+
allow(@partializer_helper).to receive(:filter_and_transform_funcs).and_return([])
|
|
3461
|
+
allow(@partializer_helper).to receive(:subtract_funcs).and_return([])
|
|
3462
|
+
|
|
3463
|
+
expect(@loginator).to receive(:log_list).with(
|
|
3464
|
+
['`engine_get_twice`'],
|
|
3465
|
+
'Not mockable for Partial test_mod::mod (inline, body outside module):',
|
|
3466
|
+
Verbosity::DEBUG
|
|
3467
|
+
)
|
|
3468
|
+
|
|
3469
|
+
@partializer.extract_interface_functions(
|
|
3470
|
+
test: 'test_mod', partial: 'mod',
|
|
3471
|
+
definitions: [], declarations: [foreign], config: make_config(mocks: pf)
|
|
3472
|
+
)
|
|
3473
|
+
end
|
|
3474
|
+
|
|
2167
3475
|
it "excludes a declaration already present as a definition with the same name (dedup)" do
|
|
2168
3476
|
defn = double('def_func', name: 'shared')
|
|
2169
|
-
decl = double('decl_func', name: 'shared') # e.g. header prototype for the same function
|
|
3477
|
+
decl = double('decl_func', name: 'shared', decorators: [], inline_elsewhere: false) # e.g. header prototype for the same function
|
|
2170
3478
|
defs = [defn]
|
|
2171
3479
|
decls = [decl]
|
|
2172
3480
|
filtered = [double('iface_func')]
|
|
@@ -2207,7 +3515,7 @@ describe Partializer do
|
|
|
2207
3515
|
|
|
2208
3516
|
it "searches definitions then declarations for additions" do
|
|
2209
3517
|
defs = []
|
|
2210
|
-
decls = [double('decl', name: 'decl_only')]
|
|
3518
|
+
decls = [double('decl', name: 'decl_only', decorators: [], inline_elsewhere: false)]
|
|
2211
3519
|
found = double('iface_func', name: 'decl_only')
|
|
2212
3520
|
pf = make_pf(type: Partials::ACCUMULATE, additions: ['decl_only'])
|
|
2213
3521
|
|