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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
require 'set'
|
|
10
10
|
require 'spec_helper'
|
|
11
|
+
require 'timeout'
|
|
11
12
|
require 'ceedling/partials/partializer_helper'
|
|
12
13
|
require 'ceedling/partials/partializer_utils'
|
|
13
14
|
require 'ceedling/partials/partials'
|
|
@@ -18,18 +19,14 @@ require 'ostruct'
|
|
|
18
19
|
describe PartializerHelper do
|
|
19
20
|
before(:each) do
|
|
20
21
|
@partializer_utils = double("PartializerUtils")
|
|
21
|
-
@c_extractor = double("CExtractor")
|
|
22
22
|
@c_extractor_declarations = double("CExtractorDeclarations")
|
|
23
|
-
@file_path_utils = double("FilePathUtils")
|
|
24
23
|
@parsing_parcels = ParsingParcels.new
|
|
25
24
|
@loginator = double("Loginator").as_null_object
|
|
26
25
|
|
|
27
26
|
@helper = described_class.new(
|
|
28
27
|
{
|
|
29
28
|
:partializer_utils => @partializer_utils,
|
|
30
|
-
:c_extractor => @c_extractor,
|
|
31
29
|
:c_extractor_declarations => @c_extractor_declarations,
|
|
32
|
-
:file_path_utils => @file_path_utils,
|
|
33
30
|
:parsing_parcels => @parsing_parcels,
|
|
34
31
|
:loginator => @loginator
|
|
35
32
|
}
|
|
@@ -276,130 +273,89 @@ describe PartializerHelper do
|
|
|
276
273
|
|
|
277
274
|
context "#associate_function_line_numbers" do
|
|
278
275
|
before(:each) do
|
|
279
|
-
@
|
|
280
|
-
@
|
|
281
|
-
@preprocessed_filepath = '/build/preproc/module_TestModule.i'
|
|
282
|
-
|
|
283
|
-
allow(@file_path_utils).to receive(:form_preprocessed_file_raw_directives_only_filepath)
|
|
284
|
-
.with(@filepath, @name)
|
|
285
|
-
.and_return(@preprocessed_filepath)
|
|
276
|
+
@filepath = '/path/to/module.c'
|
|
277
|
+
@raw_filepath = '/build/preproc/directives_only/raw/module.c'
|
|
286
278
|
|
|
287
279
|
allow(@partializer_utils).to receive(:stamp_source_filepaths)
|
|
288
280
|
allow(@partializer_utils).to receive(:format_line_number_list).and_return([])
|
|
281
|
+
allow(@partializer_utils).to receive(:locate_functions_in_source).and_return([])
|
|
282
|
+
allow(@partializer_utils).to receive(:locate_functions_via_preprocessed).and_return([])
|
|
289
283
|
end
|
|
290
284
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
@helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: false)
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it "calls stamp_source_filepaths for empty funcs with fallback: true" do
|
|
298
|
-
expect(@partializer_utils).to receive(:stamp_source_filepaths).with([], @filepath)
|
|
299
|
-
|
|
300
|
-
@helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: true)
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
it "makes no locate calls when funcs is empty" do
|
|
304
|
-
expect(@partializer_utils).not_to receive(:locate_function_in_source)
|
|
305
|
-
expect(@partializer_utils).not_to receive(:locate_function_via_preprocessed)
|
|
306
|
-
|
|
307
|
-
@helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: false)
|
|
285
|
+
def locate(funcs, raw_filepath: @raw_filepath)
|
|
286
|
+
@helper.associate_function_line_numbers( funcs: funcs, filepath: @filepath, raw_filepath: raw_filepath )
|
|
308
287
|
end
|
|
309
288
|
|
|
310
|
-
it "
|
|
311
|
-
expect(@
|
|
312
|
-
.with(@filepath, @name)
|
|
313
|
-
.and_return(@preprocessed_filepath)
|
|
289
|
+
it "stamps source filepaths with or without a raw copy" do
|
|
290
|
+
expect(@partializer_utils).to receive(:stamp_source_filepaths).with([], @filepath).twice
|
|
314
291
|
|
|
315
|
-
|
|
292
|
+
locate( [] )
|
|
293
|
+
locate( [], raw_filepath: nil )
|
|
316
294
|
end
|
|
317
295
|
|
|
318
|
-
|
|
296
|
+
# The file is read once for all of its functions
|
|
297
|
+
it "locates every function in the source with one call when there is no raw copy" do
|
|
319
298
|
func1 = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
|
|
320
299
|
func2 = OpenStruct.new(code_block: 'int bar(int x) {}', line_num: nil)
|
|
321
300
|
|
|
322
|
-
expect(@partializer_utils).to receive(:
|
|
323
|
-
.with(
|
|
324
|
-
.and_return(10)
|
|
325
|
-
expect(@partializer_utils).
|
|
326
|
-
.with(code_block: func2.code_block, filepath: @filepath)
|
|
327
|
-
.and_return(25)
|
|
301
|
+
expect(@partializer_utils).to receive(:locate_functions_in_source)
|
|
302
|
+
.with(code_blocks: [func1.code_block, func2.code_block], filepath: @filepath).once
|
|
303
|
+
.and_return([10, 25])
|
|
304
|
+
expect(@partializer_utils).not_to receive(:locate_functions_via_preprocessed)
|
|
328
305
|
|
|
329
|
-
|
|
306
|
+
locate( [func1, func2], raw_filepath: nil )
|
|
330
307
|
|
|
331
308
|
expect(func1.line_num).to eq(10)
|
|
332
309
|
expect(func2.line_num).to eq(25)
|
|
333
310
|
end
|
|
334
311
|
|
|
335
|
-
it "
|
|
312
|
+
it "locates every function in the raw copy it is given with one call" do
|
|
336
313
|
func1 = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
|
|
337
314
|
func2 = OpenStruct.new(code_block: 'int bar(int x) {}', line_num: nil)
|
|
338
315
|
|
|
339
|
-
expect(@partializer_utils).to receive(:
|
|
340
|
-
.with(
|
|
341
|
-
.and_return(10)
|
|
342
|
-
expect(@partializer_utils).
|
|
343
|
-
.with(code_block: func2.code_block, filepath: @filepath, preprocessed_filepath: @preprocessed_filepath)
|
|
344
|
-
.and_return(25)
|
|
316
|
+
expect(@partializer_utils).to receive(:locate_functions_via_preprocessed)
|
|
317
|
+
.with(code_blocks: [func1.code_block, func2.code_block], filepath: @filepath, preprocessed_filepath: @raw_filepath).once
|
|
318
|
+
.and_return([10, 25])
|
|
319
|
+
expect(@partializer_utils).not_to receive(:locate_functions_in_source)
|
|
345
320
|
|
|
346
|
-
|
|
321
|
+
locate( [func1, func2] )
|
|
347
322
|
|
|
348
323
|
expect(func1.line_num).to eq(10)
|
|
349
324
|
expect(func2.line_num).to eq(25)
|
|
350
325
|
end
|
|
351
326
|
|
|
352
|
-
it "sets line_num to nil
|
|
327
|
+
it "sets line_num to nil for a function that isn't found" do
|
|
353
328
|
func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
|
|
354
329
|
|
|
355
|
-
allow(@partializer_utils).to receive(:
|
|
330
|
+
allow(@partializer_utils).to receive(:locate_functions_via_preprocessed).and_return([nil])
|
|
356
331
|
|
|
357
|
-
|
|
332
|
+
locate( [func] )
|
|
358
333
|
|
|
359
334
|
expect(func.line_num).to be_nil
|
|
360
335
|
end
|
|
361
336
|
|
|
362
|
-
it "does not call locate_function_via_preprocessed when fallback: true" do
|
|
363
|
-
func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
|
|
364
|
-
|
|
365
|
-
expect(@partializer_utils).not_to receive(:locate_function_via_preprocessed)
|
|
366
|
-
allow(@partializer_utils).to receive(:locate_function_in_source).and_return(1)
|
|
367
|
-
|
|
368
|
-
@helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: true)
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
it "does not call locate_function_in_source when fallback: false" do
|
|
372
|
-
func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
|
|
373
|
-
|
|
374
|
-
expect(@partializer_utils).not_to receive(:locate_function_in_source)
|
|
375
|
-
allow(@partializer_utils).to receive(:locate_function_via_preprocessed).and_return(1)
|
|
376
|
-
|
|
377
|
-
@helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: false)
|
|
378
|
-
end
|
|
379
|
-
|
|
380
337
|
it "calls format_line_number_list with funcs and passes result to loginator" do
|
|
381
338
|
func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil, name: 'foo')
|
|
382
339
|
|
|
383
|
-
allow(@partializer_utils).to receive(:
|
|
340
|
+
allow(@partializer_utils).to receive(:locate_functions_via_preprocessed).and_return([5])
|
|
384
341
|
|
|
385
342
|
expect(@partializer_utils).to receive(:format_line_number_list).with([func]).and_return(["foo(): 5"])
|
|
386
343
|
|
|
387
|
-
|
|
344
|
+
locate( [func] )
|
|
388
345
|
end
|
|
346
|
+
end
|
|
389
347
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
.and_return(custom_preproc)
|
|
397
|
-
|
|
398
|
-
expect(@partializer_utils).to receive(:locate_function_via_preprocessed)
|
|
399
|
-
.with(hash_including(preprocessed_filepath: custom_preproc))
|
|
400
|
-
.and_return(nil)
|
|
348
|
+
# Carrying reads the names kept code uses. GCC and Clang accept '$' in one.
|
|
349
|
+
context "#_statement_references" do
|
|
350
|
+
it "reads names holding '$', past members and tags" do
|
|
351
|
+
expect( @helper._statement_references( "x$1 = h$2( s.m$3, (struct t$4 *)p$5 );" ).to_a ).to contain_exactly( 'x$1', 'h$2', 's', 'p$5' )
|
|
352
|
+
end
|
|
353
|
+
end
|
|
401
354
|
|
|
402
|
-
|
|
355
|
+
# A body's own locals shadow a helper of the same name, so they don't count as uses
|
|
356
|
+
context "#_locals" do
|
|
357
|
+
it "reads locals whose names hold '$'" do
|
|
358
|
+
expect( @helper._locals( "{ int h$ = 1; int *q$; struct s$t v; int k; }" ) ).to include( 'h$', 'q$', 'v', 'k' )
|
|
403
359
|
end
|
|
404
360
|
end
|
|
405
361
|
|
|
@@ -422,11 +378,9 @@ describe PartializerHelper do
|
|
|
422
378
|
allow(@c_extractor_declarations).to receive(:try_extract_variable)
|
|
423
379
|
.and_return([false, nil])
|
|
424
380
|
|
|
425
|
-
expect(@partializer_utils).not_to receive(:replace_declaration_with_noop)
|
|
426
|
-
expect(@partializer_utils).not_to receive(:rename_c_identifier)
|
|
427
|
-
|
|
428
381
|
result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
429
382
|
expect(result).to eq([])
|
|
383
|
+
expect(func.code_block).to eq('void simple(void) { return; }')
|
|
430
384
|
end
|
|
431
385
|
|
|
432
386
|
it "returns empty array when variable is found but is non-static" do
|
|
@@ -446,86 +400,11 @@ describe PartializerHelper do
|
|
|
446
400
|
allow(@c_extractor_declarations).to receive(:try_extract_variable)
|
|
447
401
|
.and_return([true, [non_static_var]], [false, nil])
|
|
448
402
|
|
|
449
|
-
expect(@partializer_utils).not_to receive(:replace_declaration_with_noop)
|
|
450
|
-
expect(@partializer_utils).not_to receive(:rename_c_identifier)
|
|
451
|
-
|
|
452
403
|
result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
453
404
|
expect(result).to eq([])
|
|
405
|
+
expect(func.code_block).to eq('void simple(void) { int x; return x; }')
|
|
454
406
|
end
|
|
455
407
|
|
|
456
|
-
it "delegates noop and rename calls to utils for a static variable" do
|
|
457
|
-
func = OpenStruct.new(
|
|
458
|
-
name: 'process',
|
|
459
|
-
code_block: 'void process(void) { static int count; count = 0; }',
|
|
460
|
-
body: '{ static int count; count = 0; }'
|
|
461
|
-
)
|
|
462
|
-
|
|
463
|
-
var = OpenStruct.new(
|
|
464
|
-
original: 'static int count',
|
|
465
|
-
name: 'count',
|
|
466
|
-
decorators: ['static'],
|
|
467
|
-
text: 'int count;'
|
|
468
|
-
)
|
|
469
|
-
|
|
470
|
-
allow(@c_extractor_declarations).to receive(:try_extract_variable)
|
|
471
|
-
.and_return([true, [var]], [false, nil])
|
|
472
|
-
|
|
473
|
-
placeholder = '__CEEDLING_NOOP_PROCESS_COUNT__'
|
|
474
|
-
noop_text = "(void)0; /* `#{placeholder}` ... */"
|
|
475
|
-
|
|
476
|
-
allow(@partializer_utils).to receive(:replace_declaration_with_noop)
|
|
477
|
-
.and_return(noop_text)
|
|
478
|
-
allow(@partializer_utils).to receive(:rename_c_identifier)
|
|
479
|
-
.and_return('')
|
|
480
|
-
|
|
481
|
-
result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
482
|
-
|
|
483
|
-
expect(@partializer_utils).to have_received(:replace_declaration_with_noop).exactly(2).times
|
|
484
|
-
expect(@partializer_utils).to have_received(:rename_c_identifier).exactly(3).times
|
|
485
|
-
expect(result.first.name).to eq('partial_process_count')
|
|
486
|
-
end
|
|
487
|
-
|
|
488
|
-
it "delegates compound noop and rename calls to utils for a compound static declaration" do
|
|
489
|
-
func = OpenStruct.new(
|
|
490
|
-
name: 'calc',
|
|
491
|
-
code_block: 'void calc(void) { static int a, b; a = 0; b = 1; }',
|
|
492
|
-
body: '{ static int a, b; a = 0; b = 1; }'
|
|
493
|
-
)
|
|
494
|
-
|
|
495
|
-
shared_original = 'static int a, b;'
|
|
496
|
-
var_a = OpenStruct.new(
|
|
497
|
-
original: shared_original,
|
|
498
|
-
name: 'a',
|
|
499
|
-
decorators: ['static'],
|
|
500
|
-
text: 'int a;'
|
|
501
|
-
)
|
|
502
|
-
var_b = OpenStruct.new(
|
|
503
|
-
original: shared_original,
|
|
504
|
-
name: 'b',
|
|
505
|
-
decorators: ['static'],
|
|
506
|
-
text: 'int b;'
|
|
507
|
-
)
|
|
508
|
-
|
|
509
|
-
# Scanner returns both vars in one call, then fails
|
|
510
|
-
allow(@c_extractor_declarations).to receive(:try_extract_variable)
|
|
511
|
-
.and_return([true, [var_a, var_b]], [false, nil])
|
|
512
|
-
|
|
513
|
-
placeholder = '__CEEDLING_NOOP_CALC_A__'
|
|
514
|
-
noops = "(void)0; (void)0; /* `#{placeholder}` ... */"
|
|
515
|
-
|
|
516
|
-
allow(@partializer_utils).to receive(:replace_compound_declaration_with_noops)
|
|
517
|
-
.and_return(noops)
|
|
518
|
-
allow(@partializer_utils).to receive(:rename_c_identifier)
|
|
519
|
-
.and_return('')
|
|
520
|
-
|
|
521
|
-
result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
522
|
-
|
|
523
|
-
expect(@partializer_utils).to have_received(:replace_compound_declaration_with_noops)
|
|
524
|
-
.with(anything, shared_original, placeholder, 2)
|
|
525
|
-
.exactly(2).times
|
|
526
|
-
expect(@partializer_utils).to have_received(:rename_c_identifier).exactly(6).times
|
|
527
|
-
expect(result.map(&:name)).to contain_exactly('partial_calc_a', 'partial_calc_b')
|
|
528
|
-
end
|
|
529
408
|
end
|
|
530
409
|
|
|
531
410
|
context "end-to-end happy day tests" do
|
|
@@ -542,9 +421,7 @@ describe PartializerHelper do
|
|
|
542
421
|
PartializerHelper.new(
|
|
543
422
|
{
|
|
544
423
|
:partializer_utils => real_utils,
|
|
545
|
-
:c_extractor => double("CExtractor").as_null_object,
|
|
546
424
|
:c_extractor_declarations => CExtractorDeclarations.new({ c_extractor_code_text: CExtractorCodeText.new() }).tap(&:setup),
|
|
547
|
-
:file_path_utils => double("FilePathUtils"),
|
|
548
425
|
:parsing_parcels => ParsingParcels.new,
|
|
549
426
|
:loginator => double("Loginator").as_null_object
|
|
550
427
|
}
|
|
@@ -574,6 +451,91 @@ describe PartializerHelper do
|
|
|
574
451
|
expect(func.code_block).to include('static int count')
|
|
575
452
|
end
|
|
576
453
|
|
|
454
|
+
# A mocked Partial keeps a helper's promoted statics with the helper, so each knows its function
|
|
455
|
+
it "names the function each promoted variable came from" do
|
|
456
|
+
func = OpenStruct.new(
|
|
457
|
+
name: 'process',
|
|
458
|
+
body: "{\n static int count, total;\n return count + total;\n}",
|
|
459
|
+
code_block: "void process(void) {\n static int count, total;\n return count + total;\n}"
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
463
|
+
|
|
464
|
+
expect(result.map(&:promoted_from)).to eq(['process', 'process'])
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
# A function pointer's declarator wraps its name, so the new name has to reach it too
|
|
468
|
+
it "promotes a function-scope static function pointer under its new name, declarator and all" do
|
|
469
|
+
func = OpenStruct.new(
|
|
470
|
+
name: 'fire',
|
|
471
|
+
body: "{\n static int (*cache)(int) = 0;\n return cache(1);\n}",
|
|
472
|
+
code_block: "int fire(void) {\n static int (*cache)(int) = 0;\n return cache(1);\n}"
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
476
|
+
|
|
477
|
+
expect(result.map { |v| [v.name, v.type, v.declarator] }).to eq [['partial_fire_cache', 'int', '(*partial_fire_cache)(int)']]
|
|
478
|
+
expect(result.first.text).to include('(*partial_fire_cache)(int)')
|
|
479
|
+
expect(func.code_block).to include('return partial_fire_cache(1);')
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
it "promotes a function-scope static function pointer whose name sits in redundant parentheses" do
|
|
483
|
+
func = OpenStruct.new(
|
|
484
|
+
name: 'fire',
|
|
485
|
+
body: "{\n static int (*(cache))(int) = 0;\n return cache(1);\n}",
|
|
486
|
+
code_block: "int fire(void) {\n static int (*(cache))(int) = 0;\n return cache(1);\n}"
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
490
|
+
|
|
491
|
+
expect(result.map { |v| [v.name, v.declarator] }).to eq [['partial_fire_cache', '(*(partial_fire_cache))(int)']]
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
# A macro may declare a static whole, and one the extractor reads no name from stays in place
|
|
495
|
+
it "leaves a function-scope static it can't name in the body" do
|
|
496
|
+
func = OpenStruct.new(
|
|
497
|
+
name: 'tally',
|
|
498
|
+
body: "{\n static ARR_OF(int, hits)[3];\n static int n;\n return n;\n}",
|
|
499
|
+
code_block: "int tally(void) {\n static ARR_OF(int, hits)[3];\n static int n;\n return n;\n}"
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
503
|
+
|
|
504
|
+
expect(result.map(&:name)).to eq ['partial_tally_n']
|
|
505
|
+
expect(func.code_block).to include('static ARR_OF(int, hits)[3];')
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
# Renaming part of a statement would leave the rest of it unpromoted, so the whole one stays
|
|
509
|
+
it "leaves a compound static whole when it can't name one of its variables" do
|
|
510
|
+
func = OpenStruct.new(
|
|
511
|
+
name: 'tally',
|
|
512
|
+
body: "{\n static ARR_OF(int, hits)[3], n;\n static int m;\n return n + m;\n}",
|
|
513
|
+
code_block: "int tally(void) {\n static ARR_OF(int, hits)[3], n;\n static int m;\n return n + m;\n}"
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
517
|
+
|
|
518
|
+
expect(result.map(&:name)).to eq ['partial_tally_m']
|
|
519
|
+
expect(func.code_block).to include('static ARR_OF(int, hits)[3], n;', 'return n + partial_tally_m;')
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
it "promotes each function pointer of a compound static and an array of them" do
|
|
523
|
+
func = OpenStruct.new(
|
|
524
|
+
name: 'fire',
|
|
525
|
+
body: "{\n static int (*a)(int), (*b)(int);\n static int (*t[2])(int) = { 0 };\n return a(1) + b(2) + t[0](3);\n}",
|
|
526
|
+
code_block: "int fire(void) {\n static int (*a)(int), (*b)(int);\n static int (*t[2])(int) = { 0 };\n return a(1) + b(2) + t[0](3);\n}"
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
530
|
+
|
|
531
|
+
expect(result.map { |v| [v.name, v.declarator] }).to eq [
|
|
532
|
+
['partial_fire_a', '(*partial_fire_a)(int)'],
|
|
533
|
+
['partial_fire_b', '(*partial_fire_b)(int)'],
|
|
534
|
+
['partial_fire_t', '(*partial_fire_t[2])(int)']
|
|
535
|
+
]
|
|
536
|
+
expect(func.code_block).to include('return partial_fire_a(1) + partial_fire_b(2) + partial_fire_t[0](3);')
|
|
537
|
+
end
|
|
538
|
+
|
|
577
539
|
it "does not modify code_block when function body has only non-static variables" do
|
|
578
540
|
original_code_block = "void simple(void) {\n int x = 0;\n return x;\n}"
|
|
579
541
|
|
|
@@ -623,6 +585,148 @@ describe PartializerHelper do
|
|
|
623
585
|
# Replacement no-op with (incomplete) comment
|
|
624
586
|
expect(func.code_block).to include('(void)0; (void)0; /* `static int a, b;` replaced with no-op')
|
|
625
587
|
end
|
|
588
|
+
|
|
589
|
+
it "promotes each variable of a compound static whose first one has an initializer" do
|
|
590
|
+
func = OpenStruct.new(
|
|
591
|
+
name: 'calc',
|
|
592
|
+
body: "{\n static int x = 0, y;\n y++;\n return x + y;\n}",
|
|
593
|
+
code_block: "int calc(void) {\n static int x = 0, y;\n y++;\n return x + y;\n}"
|
|
594
|
+
)
|
|
595
|
+
|
|
596
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
597
|
+
|
|
598
|
+
expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_x', 'int partial_calc_x = 0;'], ['partial_calc_y', 'int partial_calc_y;']]
|
|
599
|
+
expect(func.code_block.scan('(void)0;').length).to eq(2)
|
|
600
|
+
expect(func.code_block).to include('return partial_calc_x + partial_calc_y;')
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
# One declarator's initializer can name another variable of the same statement
|
|
604
|
+
it "renames every variable of a compound static in each one's text" do
|
|
605
|
+
func = OpenStruct.new(
|
|
606
|
+
name: 'calc',
|
|
607
|
+
body: "{\n static int a = 1, *p = &a;\n return *p;\n}",
|
|
608
|
+
code_block: "int calc(void) {\n static int a = 1, *p = &a;\n return *p;\n}"
|
|
609
|
+
)
|
|
610
|
+
|
|
611
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
612
|
+
|
|
613
|
+
expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_a', 'int partial_calc_a = 1;'], ['partial_calc_p', 'int *partial_calc_p = &partial_calc_a;']]
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
it "renames a promoted static named in another one's array size" do
|
|
617
|
+
func = OpenStruct.new(
|
|
618
|
+
name: 'calc',
|
|
619
|
+
body: "{\n static int n = 4, m[sizeof(n)];\n return m[0];\n}",
|
|
620
|
+
code_block: "int calc(void) {\n static int n = 4, m[sizeof(n)];\n return m[0];\n}"
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
624
|
+
|
|
625
|
+
expect(result.map { |v| [v.name, v.array_suffix] }).to eq [['partial_calc_n', ''], ['partial_calc_m', '[sizeof(partial_calc_n)]']]
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
# A static's initializer can name one an earlier statement declares
|
|
629
|
+
it "renames a promoted static named by a later statement" do
|
|
630
|
+
func = OpenStruct.new(
|
|
631
|
+
name: 'calc',
|
|
632
|
+
body: "{\n static int a = 1;\n static int *p = &a;\n return *p;\n}",
|
|
633
|
+
code_block: "int calc(void) {\n static int a = 1;\n static int *p = &a;\n return *p;\n}"
|
|
634
|
+
)
|
|
635
|
+
|
|
636
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
637
|
+
|
|
638
|
+
expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_a', 'int partial_calc_a = 1;'], ['partial_calc_p', 'int *partial_calc_p = &partial_calc_a;']]
|
|
639
|
+
expect(func.code_block.scan('(void)0;').length).to eq(2)
|
|
640
|
+
expect(func.code_block).to include('return *partial_calc_p;')
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
# Under fallback preprocessing a code block keeps its comments, while the body blanks them
|
|
644
|
+
it "promotes a static whose statement holds comments" do
|
|
645
|
+
func = OpenStruct.new(
|
|
646
|
+
name: 'calc',
|
|
647
|
+
body: "{\n static int x = 0;\n static int a, b;\n return x + a + b;\n}",
|
|
648
|
+
code_block: "int calc(void) {\n static int x /* count */ = 0;\n static int a, // first\n b;\n return x + a + b;\n}"
|
|
649
|
+
)
|
|
650
|
+
|
|
651
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
652
|
+
|
|
653
|
+
expect(result.map(&:name)).to eq ['partial_calc_x', 'partial_calc_a', 'partial_calc_b']
|
|
654
|
+
expect(func.code_block.scan('(void)0;').length).to eq(3)
|
|
655
|
+
expect(func.code_block).not_to match(/^\s*static int/)
|
|
656
|
+
expect(func.code_block).to include('return partial_calc_x + partial_calc_a + partial_calc_b;')
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
# Each no-op stands where its statement did, and a statement over several lines keeps them,
|
|
660
|
+
# comments included, so coverage lines stay aligned. Line endings pass through as written.
|
|
661
|
+
["\n", "\r\n"].each do |ending|
|
|
662
|
+
it "keeps a function to its line count with #{ending.inspect} line endings" do
|
|
663
|
+
code = ["int f(void) {", " static struct {", " int n; /* a", " b */", " } st;", " return st.n;", "}"].join( ending )
|
|
664
|
+
func = OpenStruct.new( name: 'f', body: '', code_block: code )
|
|
665
|
+
|
|
666
|
+
real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
667
|
+
|
|
668
|
+
expect( func.code_block ).to include( 'return partial_f_st.n;' )
|
|
669
|
+
expect( func.code_block.count( "\n" ) ).to eq( code.count( "\n" ) )
|
|
670
|
+
expect( func.code_block.scan( ending ).size ).to eq( code.scan( ending ).size )
|
|
671
|
+
end
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
# The body opens at the first brace outside a literal, and an attribute's string may hold one
|
|
675
|
+
it "promotes a static in a function whose signature holds a brace in a string" do
|
|
676
|
+
func = OpenStruct.new(
|
|
677
|
+
name: 'calc',
|
|
678
|
+
body: "{ static int n = 0; return n; }",
|
|
679
|
+
code_block: "__attribute__((section(\"t{x}\"))) int calc(void) { static int n = 0; return n; }"
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
683
|
+
|
|
684
|
+
expect(result.map(&:name)).to eq ['partial_calc_n']
|
|
685
|
+
expect(func.code_block).to start_with('__attribute__((section("t{x}"))) int calc(void) { (void)0;')
|
|
686
|
+
expect(func.code_block).to end_with('return partial_calc_n; }')
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
it "promotes a static whose name holds '$'" do
|
|
690
|
+
func = OpenStruct.new(
|
|
691
|
+
name: 'calc',
|
|
692
|
+
body: "{\n static int c$1 = 0;\n int c = c$1;\n return c$1 + c;\n}",
|
|
693
|
+
code_block: "int calc(void) {\n static int c$1 = 0;\n int c = c$1;\n return c$1 + c;\n}"
|
|
694
|
+
)
|
|
695
|
+
|
|
696
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
697
|
+
|
|
698
|
+
expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_c$1', 'int partial_calc_c$1 = 0;']]
|
|
699
|
+
expect(func.code_block).to include('int c = partial_calc_c$1;', 'return partial_calc_c$1 + c;')
|
|
700
|
+
end
|
|
701
|
+
|
|
702
|
+
# A tag lives apart from variables, so a static's type keeps a tag another static shares
|
|
703
|
+
it "leaves a struct tag alone when another promoted static shares its name" do
|
|
704
|
+
func = OpenStruct.new(
|
|
705
|
+
name: 'calc',
|
|
706
|
+
body: "{\n static int node = 0;\n static struct node *head = 0;\n return node + (head == 0);\n}",
|
|
707
|
+
code_block: "int calc(void) {\n static int node = 0;\n static struct node *head = 0;\n return node + (head == 0);\n}"
|
|
708
|
+
)
|
|
709
|
+
|
|
710
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
711
|
+
|
|
712
|
+
expect(result.map { |v| [v.name, v.type, v.text] }).to eq [
|
|
713
|
+
['partial_calc_node', 'int', 'int partial_calc_node = 0;'],
|
|
714
|
+
['partial_calc_head', 'struct node *', 'struct node *partial_calc_head = 0;']
|
|
715
|
+
]
|
|
716
|
+
end
|
|
717
|
+
|
|
718
|
+
it "leaves a string literal alone when it renames a promoted static" do
|
|
719
|
+
func = OpenStruct.new(
|
|
720
|
+
name: 'calc',
|
|
721
|
+
body: "{\n static const char *a = \"x\", *b = \"a b\";\n printf(\"a=%s\", a);\n return b[0];\n}",
|
|
722
|
+
code_block: "int calc(void) {\n static const char *a = \"x\", *b = \"a b\";\n printf(\"a=%s\", a);\n return b[0];\n}"
|
|
723
|
+
)
|
|
724
|
+
|
|
725
|
+
result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
|
|
726
|
+
|
|
727
|
+
expect(result.map(&:text)).to eq ['char *partial_calc_a = "x";', 'char *partial_calc_b = "a b";']
|
|
728
|
+
expect(func.code_block).to include('printf("a=%s", partial_calc_a);')
|
|
729
|
+
end
|
|
626
730
|
end
|
|
627
731
|
end
|
|
628
732
|
|
|
@@ -634,8 +738,8 @@ describe PartializerHelper do
|
|
|
634
738
|
OpenStruct.new(name: name, decorators: decorators)
|
|
635
739
|
end
|
|
636
740
|
|
|
637
|
-
def make_c_module(funcs)
|
|
638
|
-
OpenStruct.new(function_definitions: funcs)
|
|
741
|
+
def make_c_module(funcs, declarations: [])
|
|
742
|
+
OpenStruct.new(function_definitions: funcs, function_declarations: declarations)
|
|
639
743
|
end
|
|
640
744
|
|
|
641
745
|
def make_pf(type: nil, additions: [], subtractions: [])
|
|
@@ -646,6 +750,68 @@ describe PartializerHelper do
|
|
|
646
750
|
OpenStruct.new(module: mod, tests: tests, mocks: mocks)
|
|
647
751
|
end
|
|
648
752
|
|
|
753
|
+
###
|
|
754
|
+
### validate_function_names_readable()
|
|
755
|
+
###
|
|
756
|
+
|
|
757
|
+
context "#validate_function_names_readable" do
|
|
758
|
+
def defined(name, signature)
|
|
759
|
+
CExtractorTypes::CFunctionDefinition.new( name: name, signature: signature )
|
|
760
|
+
end
|
|
761
|
+
|
|
762
|
+
it "does not raise when every definition has a name" do
|
|
763
|
+
c_module = CExtractorTypes::CModule.new(
|
|
764
|
+
function_definitions: [defined( 'ticker_get', 'int (*ticker_get(void))(int)' )],
|
|
765
|
+
function_declarations: [CExtractorTypes::CFunctionDeclaration.new( name: 'ticker_count', signature: 'int ticker_count(void);' )]
|
|
766
|
+
)
|
|
767
|
+
|
|
768
|
+
expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }.not_to raise_error
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
it "names the test, the module and the signature of a definition without a name" do
|
|
772
|
+
c_module = CExtractorTypes::CModule.new(
|
|
773
|
+
function_definitions: [defined( 'ticker_count', 'int ticker_count(void)' ), defined( nil, 'int (*ticker_get(void))(int)' )]
|
|
774
|
+
)
|
|
775
|
+
|
|
776
|
+
message = <<~MESSAGE.chomp
|
|
777
|
+
Partial test_ticker::ticker ⏩️ Cannot read the name of the function declared by `int (*ticker_get(void))(int)`.
|
|
778
|
+
|
|
779
|
+
OPTIONS:
|
|
780
|
+
1. If it returns or takes a function pointer, give that type a name with a typedef and use the name in this declaration.
|
|
781
|
+
2. If a macro generates the declaration, declare the function directly.
|
|
782
|
+
MESSAGE
|
|
783
|
+
|
|
784
|
+
expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }
|
|
785
|
+
.to raise_error( CeedlingException ) { |error| expect( error.message ).to eq( message ) }
|
|
786
|
+
end
|
|
787
|
+
|
|
788
|
+
# A prototype is written word for word and CMock reads its own name, so neither needs one
|
|
789
|
+
it "leaves a declaration without a name alone" do
|
|
790
|
+
c_module = CExtractorTypes::CModule.new(
|
|
791
|
+
function_declarations: [CExtractorTypes::CFunctionDeclaration.new( name: nil, signature: 'int __count__(void);' )]
|
|
792
|
+
)
|
|
793
|
+
|
|
794
|
+
expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }.not_to raise_error
|
|
795
|
+
end
|
|
796
|
+
|
|
797
|
+
it "collapses whitespace in the signature it shows" do
|
|
798
|
+
c_module = CExtractorTypes::CModule.new( function_definitions: [defined( nil, "int __count__(\n void )" )] )
|
|
799
|
+
|
|
800
|
+
expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }
|
|
801
|
+
.to raise_error( CeedlingException, /declared by `int __count__\( void \)`\./ )
|
|
802
|
+
end
|
|
803
|
+
|
|
804
|
+
# Extraction reads raw bytes, which may hold any character
|
|
805
|
+
it "shows a signature read as raw bytes" do
|
|
806
|
+
signature = "int caf\xC3\xA9$x(void)".b
|
|
807
|
+
c_module = CExtractorTypes::CModule.new( function_definitions: [defined( nil, signature )] )
|
|
808
|
+
|
|
809
|
+
expect( signature.encoding ).to eq( Encoding::BINARY )
|
|
810
|
+
expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }
|
|
811
|
+
.to raise_error( CeedlingException, /declared by `int café\$x\(void\)`\./ )
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
649
815
|
###
|
|
650
816
|
### validate_function_names_exist()
|
|
651
817
|
###
|
|
@@ -715,6 +881,58 @@ describe PartializerHelper do
|
|
|
715
881
|
expect { @helper.validate_function_names_exist(c_module, config, name) }
|
|
716
882
|
.to raise_error(CeedlingException, /test_mod.*case/)
|
|
717
883
|
end
|
|
884
|
+
|
|
885
|
+
# A mock of public functions alone reads only the header, which declares functions its
|
|
886
|
+
# source defines (#1427)
|
|
887
|
+
it "does not raise when a mocks name is only declared" do
|
|
888
|
+
name = "test_mod"
|
|
889
|
+
c_module = make_c_module([make_func('helper')], declarations: [make_func('port_read'), make_func('port_write')])
|
|
890
|
+
config = make_config('mod',
|
|
891
|
+
tests: make_pf,
|
|
892
|
+
mocks: make_pf(additions: ['port_read'], subtractions: ['port_write'])
|
|
893
|
+
)
|
|
894
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.not_to raise_error
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
it "raises when a mocks name differs only by case from a declared one" do
|
|
898
|
+
name = "test_mod"
|
|
899
|
+
c_module = make_c_module([], declarations: [make_func('port_write')])
|
|
900
|
+
config = make_config('mod', tests: make_pf, mocks: make_pf(subtractions: ['Port_Write']))
|
|
901
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /test_mod.*case/)
|
|
902
|
+
end
|
|
903
|
+
|
|
904
|
+
# A Test Partial carries only the functions its module defines
|
|
905
|
+
it "raises when a tests name is only declared" do
|
|
906
|
+
name = "test_mod"
|
|
907
|
+
c_module = make_c_module([], declarations: [make_func('port_write')])
|
|
908
|
+
config = make_config('mod', tests: make_pf(subtractions: ['port_write']), mocks: make_pf)
|
|
909
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /test_mod.*port_write/)
|
|
910
|
+
end
|
|
911
|
+
|
|
912
|
+
it "ignores a declaration with no name" do
|
|
913
|
+
name = "test_mod"
|
|
914
|
+
c_module = make_c_module([], declarations: [make_func(nil), make_func('port_write')])
|
|
915
|
+
config = make_config('mod', tests: make_pf, mocks: make_pf(subtractions: ['port_write']))
|
|
916
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.not_to raise_error
|
|
917
|
+
|
|
918
|
+
config = make_config('mod', tests: make_pf, mocks: make_pf(subtractions: ['port_nope']))
|
|
919
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /port_nope.*does not exist/)
|
|
920
|
+
end
|
|
921
|
+
|
|
922
|
+
# Its body is in another header, which a mock can never replace, so mock selection leaves it out
|
|
923
|
+
it "raises when a mocks name is an inline function the module only declares" do
|
|
924
|
+
name = "test_mod"
|
|
925
|
+
c_module = make_c_module([], declarations: [make_func('port_inl', decorators: ['inline'])])
|
|
926
|
+
config = make_config('mod', tests: make_pf, mocks: make_pf(additions: ['port_inl']))
|
|
927
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /port_inl.*does not exist/)
|
|
928
|
+
end
|
|
929
|
+
|
|
930
|
+
it "raises when a mocks name is a declaration whose inline body is elsewhere" do
|
|
931
|
+
name = "test_mod"
|
|
932
|
+
c_module = make_c_module([], declarations: [OpenStruct.new(name: 'port_inl', decorators: [], inline_elsewhere: true)])
|
|
933
|
+
config = make_config('mod', tests: make_pf, mocks: make_pf(additions: ['port_inl']))
|
|
934
|
+
expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /port_inl.*does not exist/)
|
|
935
|
+
end
|
|
718
936
|
end
|
|
719
937
|
|
|
720
938
|
###
|
|
@@ -795,6 +1013,15 @@ describe PartializerHelper do
|
|
|
795
1013
|
.not_to raise_error
|
|
796
1014
|
end
|
|
797
1015
|
|
|
1016
|
+
it "checks a PUBLIC mocks subtraction of a function the header only declares" do
|
|
1017
|
+
name = "test_mod"
|
|
1018
|
+
decl = make_func('port_write')
|
|
1019
|
+
c_module = make_c_module([], declarations: [decl])
|
|
1020
|
+
config = make_config('mod', tests: make_pf, mocks: make_pf(type: Partials::PUBLIC, subtractions: ['port_write']))
|
|
1021
|
+
allow(@partializer_utils).to receive(:matches_visibility?).with(decl.decorators, Partials::PUBLIC).and_return(true)
|
|
1022
|
+
expect { @helper.validate_additions_subtractions_visibility(c_module, config, name) }.not_to raise_error
|
|
1023
|
+
end
|
|
1024
|
+
|
|
798
1025
|
it "raises when PUBLIC subtractions include a private function" do
|
|
799
1026
|
name = "test_mod"
|
|
800
1027
|
func = make_func('priv', decorators: ['static'])
|
|
@@ -875,10 +1102,6 @@ describe PartializerHelper do
|
|
|
875
1102
|
end
|
|
876
1103
|
end
|
|
877
1104
|
|
|
878
|
-
###
|
|
879
|
-
### update_signatures_from_full_expansion()
|
|
880
|
-
###
|
|
881
|
-
|
|
882
1105
|
context "#validate_fallback_sufficiency" do
|
|
883
1106
|
# Fallback never runs a compiler, so two module shapes are knowably beyond it. Refusing here
|
|
884
1107
|
# trades a confusing failure several stages later for a specific one now. Text comes in as a
|
|
@@ -983,131 +1206,160 @@ describe PartializerHelper do
|
|
|
983
1206
|
end
|
|
984
1207
|
end
|
|
985
1208
|
|
|
986
|
-
context "#
|
|
1209
|
+
context "#mark_inline_elsewhere" do
|
|
987
1210
|
require 'ceedling/c_extractor/c_extractor_types'
|
|
988
1211
|
|
|
989
|
-
def
|
|
990
|
-
CExtractorTypes::
|
|
991
|
-
name:
|
|
992
|
-
signature: signature,
|
|
993
|
-
decorators: decorators,
|
|
994
|
-
signature_stripped: signature_stripped
|
|
1212
|
+
def decl(signature)
|
|
1213
|
+
CExtractorTypes::CFunctionDeclaration.new(
|
|
1214
|
+
name: signature[/(\w+)\s*\(/, 1], signature: signature, decorators: signature.start_with?( 'static' ) ? ['static'] : []
|
|
995
1215
|
)
|
|
996
1216
|
end
|
|
997
1217
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
)
|
|
1005
|
-
allow(func).to receive(:signature=)
|
|
1006
|
-
allow(func).to receive(:decorators=)
|
|
1007
|
-
allow(func).to receive(:signature_stripped=)
|
|
1218
|
+
# Under C99 the declaring file then holds the external definition
|
|
1219
|
+
it "marks a declaration whose function an included header defines inline" do
|
|
1220
|
+
twice = decl( 'int engine_get_twice(void);' )
|
|
1221
|
+
tick = decl( 'int board_tick(void);' )
|
|
1222
|
+
text = "# 1 \"src/engine_api.h\" 1\nint engine_get(void);\ninline int engine_get_twice(void)\n{\n return 2;\n}\n" \
|
|
1223
|
+
"# 2 \"src/engine.c\" 2\nint engine_get_twice(void);\nint board_tick(void);\n"
|
|
1008
1224
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
signature_stripped: 'int helper(void)'
|
|
1014
|
-
)
|
|
1015
|
-
expanded_module = CExtractorTypes::CModule.new(function_definitions: [expanded_func])
|
|
1016
|
-
|
|
1017
|
-
allow(@c_extractor).to receive(:from_file)
|
|
1018
|
-
.with('/build/full_expansion/mod.c')
|
|
1019
|
-
.and_return(expanded_module)
|
|
1020
|
-
|
|
1021
|
-
expect(func).to receive(:signature=).with('static int helper(void)')
|
|
1022
|
-
expect(func).to receive(:decorators=).with(['static'])
|
|
1023
|
-
expect(func).to receive(:signature_stripped=).with('int helper(void)')
|
|
1024
|
-
|
|
1025
|
-
@helper.update_signatures_from_full_expansion(
|
|
1026
|
-
funcs: [func],
|
|
1027
|
-
full_expansion_filepath: '/build/full_expansion/mod.c',
|
|
1028
|
-
name: 'TestMod',
|
|
1029
|
-
module_name: 'mod',
|
|
1030
|
-
file_type: 'source'
|
|
1031
|
-
)
|
|
1225
|
+
@helper.mark_inline_elsewhere( decls: [twice, tick], text: text )
|
|
1226
|
+
|
|
1227
|
+
expect( twice.inline_elsewhere ).to be(true)
|
|
1228
|
+
expect( tick.inline_elsewhere ).to be(false)
|
|
1032
1229
|
end
|
|
1033
1230
|
|
|
1034
|
-
it "
|
|
1035
|
-
|
|
1036
|
-
name: 'missing',
|
|
1037
|
-
signature: 'MACRO int missing(void)',
|
|
1038
|
-
decorators: [],
|
|
1039
|
-
signature_stripped: 'int missing(void)'
|
|
1040
|
-
)
|
|
1231
|
+
it "marks no declaration of a function a header defines static inline" do
|
|
1232
|
+
clamp = decl( 'int clamp(int v);' )
|
|
1041
1233
|
|
|
1042
|
-
|
|
1234
|
+
@helper.mark_inline_elsewhere( decls: [clamp], text: "static inline int clamp(int v) { return v; }\nint clamp(int v);\n" )
|
|
1043
1235
|
|
|
1044
|
-
|
|
1236
|
+
expect( clamp.inline_elsewhere ).to be(false)
|
|
1237
|
+
end
|
|
1045
1238
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
expect(func).not_to receive(:signature_stripped=)
|
|
1239
|
+
it "marks no static declaration" do
|
|
1240
|
+
local = decl( 'static int local(void);' )
|
|
1049
1241
|
|
|
1050
|
-
@helper.
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
name: 'TestMod',
|
|
1054
|
-
module_name: 'mod',
|
|
1055
|
-
file_type: 'source'
|
|
1056
|
-
)
|
|
1242
|
+
@helper.mark_inline_elsewhere( decls: [local], text: "inline int local(void) { return 1; }\n" )
|
|
1243
|
+
|
|
1244
|
+
expect( local.inline_elsewhere ).to be(false)
|
|
1057
1245
|
end
|
|
1058
1246
|
|
|
1059
|
-
it "
|
|
1060
|
-
|
|
1061
|
-
name: 'private_func',
|
|
1062
|
-
signature: 'MY_STATIC void private_func(void)',
|
|
1063
|
-
decorators: [],
|
|
1064
|
-
signature_stripped: 'void private_func(void)'
|
|
1065
|
-
)
|
|
1066
|
-
allow(func_match).to receive(:signature=)
|
|
1067
|
-
allow(func_match).to receive(:decorators=)
|
|
1068
|
-
allow(func_match).to receive(:signature_stripped=)
|
|
1247
|
+
it "marks no declaration of a function a header defines without inline" do
|
|
1248
|
+
plain = decl( 'int plain(void);' )
|
|
1069
1249
|
|
|
1070
|
-
|
|
1250
|
+
@helper.mark_inline_elsewhere( decls: [plain], text: "int plain(void) { return 1; }\nint plain(void);\n" )
|
|
1071
1251
|
|
|
1072
|
-
|
|
1073
|
-
name: 'private_func',
|
|
1074
|
-
signature: 'static void private_func(void)',
|
|
1075
|
-
decorators: ['static'],
|
|
1076
|
-
signature_stripped: 'void private_func(void)'
|
|
1077
|
-
)
|
|
1078
|
-
expanded_module = CExtractorTypes::CModule.new(function_definitions: [expanded_func])
|
|
1079
|
-
|
|
1080
|
-
allow(@c_extractor).to receive(:from_file).and_return(expanded_module)
|
|
1081
|
-
|
|
1082
|
-
expect(func_match).to receive(:signature=).with('static void private_func(void)')
|
|
1083
|
-
expect(func_match).to receive(:decorators=).with(['static'])
|
|
1084
|
-
expect(func_match).to receive(:signature_stripped=).with('void private_func(void)')
|
|
1085
|
-
expect(func_no_match).not_to receive(:signature=)
|
|
1086
|
-
expect(func_no_match).not_to receive(:decorators=)
|
|
1087
|
-
expect(func_no_match).not_to receive(:signature_stripped=)
|
|
1088
|
-
|
|
1089
|
-
@helper.update_signatures_from_full_expansion(
|
|
1090
|
-
funcs: [func_match, func_no_match],
|
|
1091
|
-
full_expansion_filepath: '/build/full_expansion/mod.c',
|
|
1092
|
-
name: 'TestMod',
|
|
1093
|
-
module_name: 'mod',
|
|
1094
|
-
file_type: 'source'
|
|
1095
|
-
)
|
|
1252
|
+
expect( plain.inline_elsewhere ).to be(false)
|
|
1096
1253
|
end
|
|
1097
1254
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1255
|
+
# A directive line between definitions holds no specifier of the definition after it
|
|
1256
|
+
it "reads past a directive line naming static" do
|
|
1257
|
+
twice = decl( 'int twice(void);' )
|
|
1101
1258
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1259
|
+
@helper.mark_inline_elsewhere( decls: [twice], text: "int a;\n#define LOCAL static\ninline int twice(void) { return 2; }\n" )
|
|
1260
|
+
|
|
1261
|
+
expect( twice.inline_elsewhere ).to be(true)
|
|
1262
|
+
end
|
|
1263
|
+
|
|
1264
|
+
# A raw copy holds every header the file includes, so the scan has to stay linear in its size.
|
|
1265
|
+
# A long stretch with no statement break ahead of the definition is the costly shape.
|
|
1266
|
+
it "scans a long stretch with no statement break in linear time" do
|
|
1267
|
+
twice = decl( 'int twice(void);' )
|
|
1268
|
+
text = ("#define LIMIT 1\n" * 20_000) + ";\ninline int twice(void) { return 2; }\n"
|
|
1269
|
+
|
|
1270
|
+
Timeout.timeout( 5 ) { @helper.mark_inline_elsewhere( decls: [twice], text: text ) }
|
|
1271
|
+
|
|
1272
|
+
expect( twice.inline_elsewhere ).to be(true)
|
|
1273
|
+
end
|
|
1274
|
+
|
|
1275
|
+
it "marks each of several declarations from one call" do
|
|
1276
|
+
twice = decl( 'int twice(void);' )
|
|
1277
|
+
clamp = decl( 'int clamp(int v);' )
|
|
1278
|
+
plain = decl( 'int plain(void);' )
|
|
1279
|
+
tick = decl( 'int tick(void);' )
|
|
1280
|
+
text = "inline int twice(void) { return 2; }\nstatic inline int clamp(int v) { return v; }\n" \
|
|
1281
|
+
"int plain(void) { return 1; }\n__inline__ int tick(void)\n{\n return twice();\n}\n"
|
|
1282
|
+
|
|
1283
|
+
@helper.mark_inline_elsewhere( decls: [twice, clamp, plain, tick], text: text )
|
|
1284
|
+
|
|
1285
|
+
expect( [twice, clamp, plain, tick].map( &:inline_elsewhere ) ).to eq( [true, false, false, true] )
|
|
1286
|
+
end
|
|
1287
|
+
|
|
1288
|
+
# A header-only Partial of a large API header asks about every function it declares
|
|
1289
|
+
it "marks many declarations in time linear in the text, not in the number of declarations" do
|
|
1290
|
+
decls = (1..5_000).map { |n| decl( "int api_#{n}(void);" ) }
|
|
1291
|
+
text = ("#define API_LIMIT 1\n" * 250_000) + ";\ninline int api_77(void) { return 77; }\n"
|
|
1292
|
+
|
|
1293
|
+
Timeout.timeout( 1 ) { @helper.mark_inline_elsewhere( decls: decls, text: text ) }
|
|
1294
|
+
|
|
1295
|
+
expect( decls.select( &:inline_elsewhere ).map( &:name ) ).to eq( ['api_77'] )
|
|
1296
|
+
end
|
|
1297
|
+
|
|
1298
|
+
# A block of macros holds no `;` or brace, so the whole block and the definition after it are
|
|
1299
|
+
# one stretch of text. Each mention of the name in it is judged by every word ahead of it.
|
|
1300
|
+
it "judges many mentions of a name in one stretch of text in linear time" do
|
|
1301
|
+
twice = decl( 'int twice(void);' )
|
|
1302
|
+
text = (1..16_000).map { |n| "#define WRAP_#{n}(v) twice(v)\n" }.join + "inline int twice(void) { return 2; }\n"
|
|
1303
|
+
|
|
1304
|
+
Timeout.timeout( 2 ) { @helper.mark_inline_elsewhere( decls: [twice], text: text ) }
|
|
1305
|
+
|
|
1306
|
+
expect( twice.inline_elsewhere ).to be(true)
|
|
1307
|
+
end
|
|
1308
|
+
|
|
1309
|
+
# Text read as characters rather than bytes must mark the same
|
|
1310
|
+
it "marks from text holding a multibyte character ahead of the definition" do
|
|
1311
|
+
twice = decl( 'int twice(void);' )
|
|
1312
|
+
|
|
1313
|
+
@helper.mark_inline_elsewhere( decls: [twice], text: "/* é */ inline int twice(void) { return 2; }\n" )
|
|
1314
|
+
|
|
1315
|
+
expect( twice.inline_elsewhere ).to be(true)
|
|
1316
|
+
end
|
|
1317
|
+
|
|
1318
|
+
it "does not take a longer name's inline definition for the declared function's" do
|
|
1319
|
+
twice = decl( 'int twice(void);' )
|
|
1320
|
+
|
|
1321
|
+
@helper.mark_inline_elsewhere( decls: [twice], text: "inline int get_twice(void) { return 2; }\n" )
|
|
1322
|
+
|
|
1323
|
+
expect( twice.inline_elsewhere ).to be(false)
|
|
1324
|
+
end
|
|
1325
|
+
|
|
1326
|
+
# A raw copy is read as bytes, and a vendor header's comments may hold any byte at all
|
|
1327
|
+
it "marks from a raw copy read as bytes, whatever bytes its comments hold" do
|
|
1328
|
+
twice = decl( 'int twice(void);' )
|
|
1329
|
+
text = "/* 10 \xB5s tick \xFF */\ninline int twice(void) { return 2; }\n".b
|
|
1330
|
+
|
|
1331
|
+
@helper.mark_inline_elsewhere( decls: [twice], text: text )
|
|
1332
|
+
|
|
1333
|
+
expect( twice.inline_elsewhere ).to be(true)
|
|
1334
|
+
end
|
|
1335
|
+
end
|
|
1336
|
+
|
|
1337
|
+
context "#associate_declaration_line_numbers" do
|
|
1338
|
+
require 'ceedling/c_extractor/c_extractor_types'
|
|
1339
|
+
|
|
1340
|
+
# One call locates every declaration from the file
|
|
1341
|
+
it "records each declaration's file and its line in that file's own text" do
|
|
1342
|
+
tick = CExtractorTypes::CFunctionDeclaration.new(name: 'tick', signature: 'int tick(void);', line_num: 1)
|
|
1343
|
+
tock = CExtractorTypes::CFunctionDeclaration.new(name: 'tock', signature: 'int tock(void);', line_num: 1)
|
|
1344
|
+
text = "#include \"x.h\"\nint tick(void);\nint tock(void);\n"
|
|
1345
|
+
expect(@partializer_utils).to receive(:locate_declarations_in_text)
|
|
1346
|
+
.with(signatures: ['int tick(void);', 'int tock(void);'], text: text).once.and_return([2, 3])
|
|
1347
|
+
|
|
1348
|
+
@helper.associate_declaration_line_numbers(decls: [tick, tock], filepath: 'src/mod.c', text: text)
|
|
1349
|
+
|
|
1350
|
+
expect([tick, tock].map(&:source_filepath)).to eq(['src/mod.c', 'src/mod.c'])
|
|
1351
|
+
expect([tick, tock].map(&:line_num)).to eq([2, 3])
|
|
1352
|
+
end
|
|
1353
|
+
|
|
1354
|
+
# Without a location the declaration is written without a #line, so nothing is reported
|
|
1355
|
+
it "leaves the line unset when the declaration is not found" do
|
|
1356
|
+
decl = CExtractorTypes::CFunctionDeclaration.new(name: 'tick', signature: 'int tick(void);', line_num: 1)
|
|
1357
|
+
allow(@partializer_utils).to receive(:locate_declarations_in_text).and_return([nil])
|
|
1358
|
+
|
|
1359
|
+
@helper.associate_declaration_line_numbers(decls: [decl], filepath: 'src/mod.c', text: '')
|
|
1360
|
+
|
|
1361
|
+
expect(decl.source_filepath).to eq('src/mod.c')
|
|
1362
|
+
expect(decl.line_num).to be_nil
|
|
1111
1363
|
end
|
|
1112
1364
|
end
|
|
1113
1365
|
|