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.
Files changed (390) hide show
  1. checksums.yaml +4 -4
  2. data/GIT_COMMIT_SHA +1 -1
  3. data/README.md +1 -1
  4. data/assets/fixtures/tests_with_partials_coverage/src/private_macro.c +7 -0
  5. data/assets/fixtures/tests_with_partials_coverage/src/private_macro.h +5 -0
  6. data/assets/fixtures/tests_with_partials_coverage/src/tally.c +13 -0
  7. data/assets/fixtures/tests_with_partials_coverage/src/tally.h +4 -0
  8. data/assets/fixtures/tests_with_partials_coverage/test/test_private_macro.c +10 -0
  9. data/assets/fixtures/tests_with_partials_coverage/test/test_tally.c +9 -0
  10. data/docs/BreakingChanges.md +16 -0
  11. data/docs/Changelog.md +71 -0
  12. data/docs/KnownIssues.md +91 -4
  13. data/examples/wondrous_forest/README.md +29 -1
  14. data/examples/wondrous_forest/src/ForestUnits.h +23 -0
  15. data/examples/wondrous_forest/src/RainGauge.c +59 -0
  16. data/examples/wondrous_forest/src/RainGauge.h +39 -0
  17. data/examples/wondrous_forest/src/RainTipIsr.c +17 -0
  18. data/examples/wondrous_forest/src/RainTipIsr.h +14 -0
  19. data/examples/wondrous_forest/test/TestRainGauge.c +126 -0
  20. data/lib/ceedling/c_extractor/README.md +15 -7
  21. data/lib/ceedling/c_extractor/c_extractor.rb +25 -14
  22. data/lib/ceedling/c_extractor/c_extractor_code_text.rb +84 -54
  23. data/lib/ceedling/c_extractor/c_extractor_constants.rb +18 -7
  24. data/lib/ceedling/c_extractor/c_extractor_declarations.rb +319 -283
  25. data/lib/ceedling/c_extractor/c_extractor_declarator.rb +285 -0
  26. data/lib/ceedling/c_extractor/c_extractor_defined_type.rb +111 -0
  27. data/lib/ceedling/c_extractor/c_extractor_definitions.rb +174 -121
  28. data/lib/ceedling/c_extractor/c_extractor_functions.rb +191 -162
  29. data/lib/ceedling/c_extractor/c_extractor_preprocessing.rb +46 -55
  30. data/lib/ceedling/c_extractor/c_extractor_statement.rb +30 -0
  31. data/lib/ceedling/c_extractor/c_extractor_types.rb +63 -41
  32. data/lib/ceedling/c_extractor/c_module_edits.rb +48 -0
  33. data/lib/ceedling/c_identifier.rb +21 -0
  34. data/lib/ceedling/ceedling.h +8 -0
  35. data/lib/ceedling/config/configurator.rb +4 -3
  36. data/lib/ceedling/config/configurator_builder.rb +17 -0
  37. data/lib/ceedling/config/configurator_setup.rb +29 -5
  38. data/lib/ceedling/constants.rb +5 -1
  39. data/lib/ceedling/defaults.rb +31 -1
  40. data/lib/ceedling/dependencies/CACHE_SCHEMA.md +118 -0
  41. data/lib/ceedling/dependencies/README.md +1 -1
  42. data/lib/ceedling/dependencies/dependency_cache_store.rb +30 -25
  43. data/lib/ceedling/dependencies/dependency_tracker.rb +9 -3
  44. data/lib/ceedling/dependencies/dependinator.rb +13 -1
  45. data/lib/ceedling/diagnostics/DOCTOR.md +142 -0
  46. data/lib/ceedling/diagnostics/README.md +5 -0
  47. data/lib/ceedling/diagnostics/build_step_doctor.rb +110 -0
  48. data/lib/ceedling/diagnostics/duplicate_symbol_specialist.rb +108 -0
  49. data/lib/ceedling/diagnostics/guidance_phrases.rb +30 -0
  50. data/lib/ceedling/diagnostics/header_collision_guidance.rb +56 -0
  51. data/lib/ceedling/diagnostics/header_collision_specialist.rb +152 -0
  52. data/lib/ceedling/diagnostics/include_depth_specialist.rb +132 -0
  53. data/lib/ceedling/diagnostics/missing_symbol_specialist.rb +111 -0
  54. data/lib/ceedling/diagnostics/partial_name_specialist.rb +134 -0
  55. data/lib/ceedling/diagnostics/toolchain_output.rb +44 -0
  56. data/lib/ceedling/filesystem/PATH_HANDLING.md +83 -27
  57. data/lib/ceedling/filesystem/README.md +6 -1
  58. data/lib/ceedling/filesystem/build_roots.rb +105 -0
  59. data/lib/ceedling/filesystem/build_subpath.rb +110 -25
  60. data/lib/ceedling/filesystem/file_finder.rb +76 -110
  61. data/lib/ceedling/filesystem/file_finder_helper.rb +33 -11
  62. data/lib/ceedling/filesystem/file_path_utils.rb +113 -91
  63. data/lib/ceedling/filesystem/file_wrapper.rb +105 -28
  64. data/lib/ceedling/filesystem/path_matcher.rb +21 -0
  65. data/lib/ceedling/filesystem/test_build_layout.rb +114 -0
  66. data/lib/ceedling/filesystem/win_long_paths.rb +153 -0
  67. data/lib/ceedling/filesystem/win_path_limit.rb +83 -0
  68. data/lib/ceedling/filesystem/win_path_prober.rb +52 -0
  69. data/lib/ceedling/generators/generator.rb +27 -64
  70. data/lib/ceedling/generators/generator_helper.rb +0 -44
  71. data/lib/ceedling/generators/generator_mocks.rb +5 -0
  72. data/lib/ceedling/generators/generator_partials.rb +305 -243
  73. data/lib/ceedling/generators/generator_test_runner.rb +5 -8
  74. data/lib/ceedling/generators/partial_header_writer.rb +95 -0
  75. data/lib/ceedling/generators/partial_source_writer.rb +137 -0
  76. data/lib/ceedling/includes/header_search.rb +225 -0
  77. data/lib/ceedling/includes/include_factory.rb +9 -12
  78. data/lib/ceedling/includes/include_pathinator.rb +53 -31
  79. data/lib/ceedling/includes/includes.rb +149 -37
  80. data/lib/ceedling/objects.yml +89 -4
  81. data/lib/ceedling/partials/README.md +110 -16
  82. data/lib/ceedling/partials/carry_plan.rb +71 -0
  83. data/lib/ceedling/partials/definition_head.rb +74 -0
  84. data/lib/ceedling/partials/include_groups.rb +37 -0
  85. data/lib/ceedling/partials/interface_extras.rb +25 -0
  86. data/lib/ceedling/partials/partializer.rb +599 -120
  87. data/lib/ceedling/partials/partializer_config.rb +5 -0
  88. data/lib/ceedling/partials/partializer_helper.rb +851 -145
  89. data/lib/ceedling/partials/partializer_reconciler.rb +174 -0
  90. data/lib/ceedling/partials/partializer_utils.rb +89 -109
  91. data/lib/ceedling/partials/partials.rb +153 -10
  92. data/lib/ceedling/partials/type_macros.rb +126 -0
  93. data/lib/ceedling/preprocess/README.md +43 -33
  94. data/lib/ceedling/preprocess/preprocessinator.rb +100 -186
  95. data/lib/ceedling/preprocess/preprocessinator_code_finder.rb +65 -72
  96. data/lib/ceedling/preprocess/preprocessinator_file_assembler.rb +31 -75
  97. data/lib/ceedling/preprocess/preprocessinator_reconstructor.rb +51 -14
  98. data/lib/ceedling/setupinator.rb +16 -3
  99. data/lib/ceedling/test_invoker/HEADER_COLLISIONS.md +21 -7
  100. data/lib/ceedling/test_invoker/PIPELINE.md +57 -16
  101. data/lib/ceedling/test_invoker/README.md +1 -1
  102. data/lib/ceedling/test_invoker/derived_search_path_notices.rb +45 -0
  103. data/lib/ceedling/test_invoker/mock_locator.rb +116 -9
  104. data/lib/ceedling/test_invoker/partial_files_preprocessinator.rb +181 -0
  105. data/lib/ceedling/test_invoker/partials_manager.rb +265 -308
  106. data/lib/ceedling/test_invoker/standin_headerinator.rb +8 -15
  107. data/lib/ceedling/test_invoker/test_bare_includes_extractinator.rb +26 -3
  108. data/lib/ceedling/test_invoker/test_build_executor.rb +338 -198
  109. data/lib/ceedling/test_invoker/test_build_planner.rb +13 -19
  110. data/lib/ceedling/test_invoker/test_build_setup.rb +26 -6
  111. data/lib/ceedling/test_invoker/test_build_validations.rb +23 -20
  112. data/lib/ceedling/test_invoker/test_derived_search_paths.rb +189 -0
  113. data/lib/ceedling/test_invoker/test_file_preprocessinator.rb +1 -2
  114. data/lib/ceedling/test_invoker/test_includes_reconcilinator.rb +1 -1
  115. data/lib/ceedling/test_invoker/test_invoker_types.rb +28 -20
  116. data/lib/ceedling/test_invoker/test_pipeline_helpers.rb +5 -3
  117. data/lib/ceedling/test_invoker/test_pipeline_manager.rb +25 -8
  118. data/lib/ceedling/test_invoker/test_runner_generatinator.rb +31 -3
  119. data/lib/ceedling/test_invoker/test_search_paths.rb +30 -8
  120. data/lib/ceedling/test_invoker/test_substitutions.rb +72 -0
  121. data/lib/ceedling/tools/shell_quoting.rb +45 -0
  122. data/lib/ceedling/tools/tool_quoting.rb +79 -0
  123. data/lib/ceedling/{tool_validator.rb → tools/tool_validator.rb} +18 -7
  124. data/lib/version.rb +1 -1
  125. data/plugins/bullseye/bullseye.rake +1 -3
  126. data/plugins/bullseye/lib/bullseye.rb +15 -2
  127. data/plugins/command_hooks/lib/command_hooks.rb +1 -1
  128. data/plugins/fff/lib/fff.rb +42 -15
  129. data/plugins/fff/lib/fff_mock_generator.rb +12 -9
  130. data/plugins/fff/spec/fff_cmock_wrapper_spec.rb +134 -0
  131. data/plugins/fff/spec/fff_mock_header_generator_spec.rb +9 -0
  132. data/plugins/fff/spec/fff_mock_source_generator_spec.rb +20 -0
  133. data/plugins/gcov/lib/console_reportinator.rb +25 -19
  134. data/plugins/gcov/lib/reportgenerator_reportinator.rb +2 -1
  135. data/site-local/404.html +2 -2
  136. data/site-local/assets/javascripts/{bundle.c21346df.min.js → bundle.a5f9d56c.min.js} +1 -1
  137. data/site-local/assets/javascripts/{bundle.c21346df.min.js.map → bundle.a5f9d56c.min.js.map} +2 -2
  138. data/site-local/configuration/environment-vars.html +2 -2
  139. data/site-local/configuration/global-collections.html +3 -3
  140. data/site-local/configuration/index.html +2 -2
  141. data/site-local/configuration/loading.html +2 -2
  142. data/site-local/configuration/mixins.html +2 -2
  143. data/site-local/configuration/parallel-builds.html +2 -2
  144. data/site-local/configuration/project-file.html +2 -2
  145. data/site-local/configuration/reference/cexception.html +2 -2
  146. data/site-local/configuration/reference/cmock.html +5 -2
  147. data/site-local/configuration/reference/defines.html +2 -2
  148. data/site-local/configuration/reference/environment.html +2 -2
  149. data/site-local/configuration/reference/extension.html +2 -2
  150. data/site-local/configuration/reference/files.html +56 -9
  151. data/site-local/configuration/reference/flags.html +2 -2
  152. data/site-local/configuration/reference/index.html +2 -2
  153. data/site-local/configuration/reference/libraries.html +2 -2
  154. data/site-local/configuration/reference/mixins.html +2 -2
  155. data/site-local/configuration/reference/partials.html +84 -2
  156. data/site-local/configuration/reference/paths.html +7 -2
  157. data/site-local/configuration/reference/plugins.html +2 -2
  158. data/site-local/configuration/reference/project.html +247 -5
  159. data/site-local/configuration/reference/release-build.html +2 -2
  160. data/site-local/configuration/reference/test-build.html +2 -2
  161. data/site-local/configuration/reference/test-runner.html +2 -2
  162. data/site-local/configuration/reference/tools.html +49 -4
  163. data/site-local/configuration/reference/unity.html +2 -2
  164. data/site-local/configuration/which-ceedling.html +2 -2
  165. data/site-local/development/index.html +2 -2
  166. data/site-local/development/plugins/configuration.html +2 -2
  167. data/site-local/development/plugins/index.html +2 -2
  168. data/site-local/development/plugins/plugin-subclass.html +5 -4
  169. data/site-local/development/plugins/rake-tasks.html +2 -2
  170. data/site-local/development/releases.html +2 -2
  171. data/site-local/development/workflow.html +2 -2
  172. data/site-local/getting-started/builds.html +2 -2
  173. data/site-local/getting-started/command-line.html +2 -2
  174. data/site-local/getting-started/example-projects/cipher-quest.html +2 -2
  175. data/site-local/getting-started/example-projects/index.html +2 -2
  176. data/site-local/getting-started/example-projects/temp-sensor.html +2 -2
  177. data/site-local/getting-started/example-projects/wondrous-forest.html +10 -2
  178. data/site-local/getting-started/index.html +2 -2
  179. data/site-local/getting-started/installation.html +2 -2
  180. data/site-local/getting-started/quick-start.html +2 -2
  181. data/site-local/help.html +2 -2
  182. data/site-local/index.html +2 -2
  183. data/site-local/overview/build-system.html +2 -2
  184. data/site-local/overview/index.html +2 -2
  185. data/site-local/overview/test-environments.html +2 -2
  186. data/site-local/overview/tools-and-frameworks.html +2 -2
  187. data/site-local/plugins/beep.html +2 -2
  188. data/site-local/plugins/bullseye/index.html +45 -38
  189. data/site-local/plugins/bullseye/licensing.html +2 -2
  190. data/site-local/plugins/command-hooks.html +4 -4
  191. data/site-local/plugins/compile-commands-json-db.html +2 -2
  192. data/site-local/plugins/cppcheck.html +2 -2
  193. data/site-local/plugins/dependencies.html +2 -2
  194. data/site-local/plugins/fff.html +16 -2
  195. data/site-local/plugins/gcov/examples.html +2 -2
  196. data/site-local/plugins/gcov/gcovr.html +8 -2
  197. data/site-local/plugins/gcov/index.html +2 -2
  198. data/site-local/plugins/gcov/overview.html +2 -2
  199. data/site-local/plugins/gcov/reportgenerator.html +18 -14
  200. data/site-local/plugins/gcov/reporting.html +2 -2
  201. data/site-local/plugins/gcov/setup.html +2 -2
  202. data/site-local/plugins/gcov/tool-versions.html +2 -2
  203. data/site-local/plugins/gcov/troubleshooting.html +2 -2
  204. data/site-local/plugins/index.html +2 -2
  205. data/site-local/plugins/module-generator.html +2 -2
  206. data/site-local/plugins/report-build-warnings-log.html +2 -2
  207. data/site-local/plugins/report-tests-gtestlike-stdout.html +2 -2
  208. data/site-local/plugins/report-tests-ide-stdout.html +2 -2
  209. data/site-local/plugins/report-tests-log-factory.html +2 -2
  210. data/site-local/plugins/report-tests-pretty-stdout.html +2 -2
  211. data/site-local/plugins/report-tests-raw-output-log.html +2 -2
  212. data/site-local/plugins/report-tests-teamcity-stdout.html +2 -2
  213. data/site-local/plugins/sanitize.html +2 -2
  214. data/site-local/plugins/valgrind.html +2 -2
  215. data/site-local/project/index.html +2 -2
  216. data/site-local/project/release-history.html +2 -2
  217. data/site-local/project/sbom.html +2 -2
  218. data/site-local/project/upgrade.html +2 -2
  219. data/site-local/reference/build-directives.html +2 -2
  220. data/site-local/reference/command-line.html +2 -2
  221. data/site-local/reference/environment-vars.html +2 -2
  222. data/site-local/reference/gcov-plugin.html +2 -2
  223. data/site-local/reference/global-collections.html +12 -12
  224. data/site-local/reference/index.html +2 -2
  225. data/site-local/reference/partials-macros.html +47 -2
  226. data/site-local/reference/project-configuration.html +2 -2
  227. data/site-local/sitemap.xml.gz +0 -0
  228. data/site-local/snapshot/examples/cipher_quest/index.html +2 -2
  229. data/site-local/snapshot/examples/temp_sensor/index.html +2 -2
  230. data/site-local/snapshot/examples/wondrous_forest/index.html +72 -15
  231. data/site-local/testing-guide/build-directives.html +2 -2
  232. data/site-local/testing-guide/conventions.html +67 -22
  233. data/site-local/testing-guide/frameworks.html +2 -2
  234. data/site-local/testing-guide/index.html +2 -2
  235. data/site-local/testing-guide/partials/configuration.html +31 -4
  236. data/site-local/testing-guide/partials/conventions.html +509 -8
  237. data/site-local/testing-guide/partials/directives.html +4 -3
  238. data/site-local/testing-guide/partials/example.html +2 -2
  239. data/site-local/testing-guide/partials/index.html +2 -2
  240. data/site-local/testing-guide/partials/overview.html +30 -12
  241. data/site-local/testing-guide/partials/variables.html +169 -4
  242. data/site-local/testing-guide/test-cases.html +2 -2
  243. data/site-local/testing-guide/test-sample.html +2 -2
  244. data/site-local/testing-guide/test-suite-anatomy.html +2 -2
  245. data/spec/integration/build_step_doctor_spec.rb +270 -0
  246. data/spec/integration/c_extractor_composition_spec.rb +254 -4
  247. data/spec/integration/includes_extraction_spec.rb +27 -14
  248. data/spec/integration/nested_test_artifacts_spec.rb +1 -1
  249. data/spec/integration/partial_files_preprocessing_spec.rb +128 -0
  250. data/spec/integration/partials_carry_spec.rb +520 -0
  251. data/spec/integration/partials_declarations_spec.rb +655 -0
  252. data/spec/integration/partials_fallback_preprocessing_spec.rb +65 -0
  253. data/spec/integration/partials_function_pointers_spec.rb +277 -0
  254. data/spec/integration/partials_header_composition_spec.rb +268 -35
  255. data/spec/integration/partials_macro_decorators_spec.rb +267 -0
  256. data/spec/integration/partials_module_resolution_spec.rb +26 -19
  257. data/spec/integration/partials_symbol_linkage_spec.rb +13 -0
  258. data/spec/integration/path_length_reporting_spec.rb +64 -0
  259. data/spec/integration/path_scenarios_spec.rb +80 -3
  260. data/spec/integration/quote_include_isolator_spec.rb +56 -0
  261. data/spec/integration/test_build_parallel_barrier_spec.rb +1 -1
  262. data/spec/integration/test_includes_extractinator_spec.rb +70 -5
  263. data/spec/integration/test_naming_spec.rb +6 -3
  264. data/spec/integration/test_source_file_checks_spec.rb +5 -3
  265. data/spec/integration/tool_executor_spec.rb +1 -1
  266. data/spec/integration/tool_validator_spec.rb +2 -2
  267. data/spec/integration/win_long_paths_probe_spec.rb +46 -0
  268. data/spec/integration/win_path_limit_spec.rb +53 -0
  269. data/spec/integration/windows_registry_query_tool_spec.rb +41 -0
  270. data/spec/support/integration/configurator_integration_helper.rb +8 -3
  271. data/spec/support/integration/partial_files_harness.rb +181 -0
  272. data/spec/support/integration/partials_generation_integration_helper.rb +237 -141
  273. data/spec/support/integration/path_scenario_harness.rb +4 -2
  274. data/spec/support/integration/spec_integration_helper.rb +8 -3
  275. data/spec/support/integration/test_includes_harness.rb +56 -35
  276. data/spec/support/integration/tool_executor_integration_helper.rb +14 -2
  277. data/spec/system/bullseye_deployment_spec.rb +2 -0
  278. data/spec/system/delta_builds_spec.rb +26 -12
  279. data/spec/system/encoding_stress_spec.rb +4 -4
  280. data/spec/system/example_wondrous_forest_spec.rb +2 -2
  281. data/spec/system/gcov_deployment_spec.rb +2 -0
  282. data/spec/system/header_include_path_validation_spec.rb +4 -4
  283. data/spec/system/header_search_paths_spec.rb +1083 -0
  284. data/spec/system/mock_include_folders_spec.rb +121 -0
  285. data/spec/system/mockable_header_reassembly_spec.rb +184 -0
  286. data/spec/system/partials_carry_spec.rb +581 -0
  287. data/spec/system/partials_delta_builds_spec.rb +280 -0
  288. data/spec/system/partials_function_pointers_spec.rb +106 -0
  289. data/spec/system/partials_macro_decorators_spec.rb +127 -0
  290. data/spec/system/partials_module_disambiguation_spec.rb +125 -0
  291. data/spec/system/path_handling_probes_spec.rb +16 -12
  292. data/spec/system/pinned_thread_count_spec.rb +4 -4
  293. data/spec/system/preprocessing_fallback_conditionals_spec.rb +1 -1
  294. data/spec/system/short_build_paths_spec.rb +87 -0
  295. data/spec/system/sibling_header_collision_spec.rb +30 -6
  296. data/spec/system/support/bullseye_common_test_cases.rb +42 -0
  297. data/spec/system/support/common_test_cases.rb +2 -2
  298. data/spec/system/support/gcov_partials_test_cases.rb +48 -0
  299. data/spec/system/test_build_layout_spec.rb +209 -0
  300. data/spec/system/test_source_file_directive_spec.rb +35 -5
  301. data/spec/units/c_extractor/c_extractor_code_text_spec.rb +67 -10
  302. data/spec/units/c_extractor/c_extractor_declarations_spec.rb +501 -4
  303. data/spec/units/c_extractor/c_extractor_declarator_spec.rb +245 -0
  304. data/spec/units/c_extractor/c_extractor_defined_type_spec.rb +45 -0
  305. data/spec/units/c_extractor/c_extractor_definitions_spec.rb +163 -3
  306. data/spec/units/c_extractor/c_extractor_functions_spec.rb +462 -21
  307. data/spec/units/c_extractor/c_extractor_preprocessing_spec.rb +39 -0
  308. data/spec/units/c_extractor/c_extractor_spec.rb +4 -4
  309. data/spec/units/c_extractor/c_extractor_types_spec.rb +163 -0
  310. data/spec/units/c_identifier_spec.rb +35 -0
  311. data/spec/units/config/configurator_builder_spec.rb +24 -0
  312. data/spec/units/config/configurator_setup_spec.rb +72 -4
  313. data/spec/units/config/configurator_spec.rb +27 -1
  314. data/spec/units/dependencies/dependency_cache_store_spec.rb +68 -3
  315. data/spec/units/dependencies/dependency_tracker_spec.rb +25 -0
  316. data/spec/units/dependencies/dependinator_spec.rb +17 -2
  317. data/spec/units/diagnostics/build_step_doctor_spec.rb +170 -0
  318. data/spec/units/diagnostics/duplicate_symbol_specialist_spec.rb +117 -0
  319. data/spec/units/diagnostics/header_collision_specialist_spec.rb +267 -0
  320. data/spec/units/diagnostics/include_depth_specialist_spec.rb +137 -0
  321. data/spec/units/diagnostics/missing_symbol_specialist_spec.rb +154 -0
  322. data/spec/units/diagnostics/partial_name_specialist_spec.rb +129 -0
  323. data/spec/units/diagnostics/toolchain_output_spec.rb +86 -0
  324. data/spec/units/encodinator_spec.rb +3 -4
  325. data/spec/units/filesystem/build_roots_spec.rb +131 -0
  326. data/spec/units/filesystem/build_subpath_spec.rb +113 -0
  327. data/spec/units/filesystem/file_finder_helper_spec.rb +80 -0
  328. data/spec/units/filesystem/file_finder_spec.rb +242 -58
  329. data/spec/units/filesystem/file_path_utils_spec.rb +251 -118
  330. data/spec/units/filesystem/file_wrapper_spec.rb +191 -6
  331. data/spec/units/filesystem/path_matcher_spec.rb +36 -0
  332. data/spec/units/filesystem/test_build_layout_spec.rb +216 -0
  333. data/spec/units/filesystem/win_long_paths_spec.rb +204 -0
  334. data/spec/units/filesystem/win_path_prober_spec.rb +158 -0
  335. data/spec/units/generators/generator_helper_spec.rb +0 -60
  336. data/spec/units/generators/generator_mocks_spec.rb +13 -0
  337. data/spec/units/generators/generator_partials_spec.rb +656 -55
  338. data/spec/units/generators/generator_spec.rb +26 -0
  339. data/spec/units/generators/generator_test_runner_spec.rb +9 -5
  340. data/spec/units/generators/partial_source_writer_spec.rb +129 -0
  341. data/spec/units/includes/header_search_spec.rb +406 -0
  342. data/spec/units/includes/include_factory_spec.rb +22 -5
  343. data/spec/units/includes/include_pathinator_spec.rb +77 -13
  344. data/spec/units/includes/include_spec.rb +14 -0
  345. data/spec/units/includes/includes_spec.rb +176 -19
  346. data/spec/units/loginator_spec.rb +31 -0
  347. data/spec/units/mock_locator_spec.rb +199 -5
  348. data/spec/units/partials/include_groups_spec.rb +42 -0
  349. data/spec/units/partials/partializer_config_spec.rb +25 -0
  350. data/spec/units/partials/partializer_helper_carry_spec.rb +661 -0
  351. data/spec/units/partials/partializer_helper_interface_extras_spec.rb +396 -0
  352. data/spec/units/partials/partializer_helper_spec.rb +529 -277
  353. data/spec/units/partials/partializer_reconciler_spec.rb +661 -0
  354. data/spec/units/partials/partializer_spec.rb +1578 -270
  355. data/spec/units/partials/partializer_utils_spec.rb +269 -232
  356. data/spec/units/partials/partials_rename_spec.rb +160 -0
  357. data/spec/units/partials_manager_spec.rb +554 -261
  358. data/spec/units/plugins/bullseye_spec.rb +34 -0
  359. data/spec/units/plugins/console_reportinator_spec.rb +58 -9
  360. data/spec/units/plugins/report_tests_teamcity_stdout_spec.rb +1 -1
  361. data/spec/units/plugins/reportgenerator_reportinator_spec.rb +51 -3
  362. data/spec/units/preprocess/preprocessinator_code_finder_spec.rb +73 -10
  363. data/spec/units/preprocess/preprocessinator_file_assembler_spec.rb +125 -37
  364. data/spec/units/preprocess/preprocessinator_includes_handler_spec.rb +15 -0
  365. data/spec/units/preprocess/preprocessinator_reconstructor_spec.rb +197 -0
  366. data/spec/units/preprocess/preprocessinator_spec.rb +153 -95
  367. data/spec/units/setupinator_spec.rb +51 -0
  368. data/spec/units/standin_headerinator_spec.rb +27 -11
  369. data/spec/units/test_build_executor_spec.rb +780 -166
  370. data/spec/units/test_build_planner_spec.rb +116 -28
  371. data/spec/units/test_build_setup_spec.rb +83 -18
  372. data/spec/units/test_context_extractor_spec.rb +11 -2
  373. data/spec/units/test_derived_search_paths_spec.rb +259 -0
  374. data/spec/units/test_includes_extractinator_spec.rb +56 -8
  375. data/spec/units/test_invoker/objects_wiring_spec.rb +20 -3
  376. data/spec/units/test_invoker/partial_files_preprocessinator_spec.rb +264 -0
  377. data/spec/units/test_invoker/test_substitutions_spec.rb +122 -0
  378. data/spec/units/test_invoker_types_spec.rb +8 -7
  379. data/spec/units/test_pipeline_manager_spec.rb +54 -13
  380. data/spec/units/test_runner_generatinator_spec.rb +93 -1
  381. data/spec/units/test_search_paths_spec.rb +73 -5
  382. data/spec/units/{default_tools_quoting_spec.rb → tools/default_tools_quoting_spec.rb} +39 -5
  383. data/spec/units/tools/shell_quoting_spec.rb +76 -0
  384. data/spec/units/{tool_executor_helper_spec.rb → tools/tool_executor_helper_spec.rb} +1 -1
  385. data/spec/units/{tool_executor_spec.rb → tools/tool_executor_spec.rb} +1 -1
  386. data/spec/units/{tool_validator_spec.rb → tools/tool_validator_spec.rb} +110 -1
  387. data/spec/units/windows_registry_query_tool_spec.rb +53 -0
  388. metadata +161 -16
  389. /data/lib/ceedling/{tool_executor.rb → tools/tool_executor.rb} +0 -0
  390. /data/lib/ceedling/{tool_executor_helper.rb → tools/tool_executor_helper.rb} +0 -0
@@ -14,18 +14,104 @@ require 'ceedling/c_extractor/c_extractor'
14
14
  require 'ceedling/c_extractor/c_extractor_constants'
15
15
  require 'ceedling/c_extractor/c_extractor_types'
16
16
  require 'ceedling/constants'
17
+ require 'ceedling/filesystem/path_matcher'
18
+ require 'ceedling/filesystem/project_paths'
17
19
  require 'ceedling/filesystem/path_mirror'
18
20
  require 'ceedling/encodinator'
19
21
 
20
22
  class Partializer
21
23
 
22
- # Enough of a header to reach its include guard. The guard pair sits at the top of a header by
23
- # construction, so a bounded read beats loading a large file to find it.
24
- GUARD_SCAN_BYTES = 2048
24
+ # Holds the place between a generated header's include groups while a list is remapped.
25
+ # Matched by identity, and named so no real include or module can match it.
26
+ INCLUDE_BOUNDARY = UserInclude.new( '<ceedling include group boundary>' ) unless const_defined?(:INCLUDE_BOUNDARY, false)
27
+
28
+ # Holds the place of a module's own header in a list from a source that never includes it.
29
+ # Matched by identity, so it names no module. Whatever replaces the header takes its place.
30
+ OWN_HEADER_PLACE = UserInclude.new( '<ceedling own header place>' ) unless const_defined?(:OWN_HEADER_PLACE, false)
31
+
32
+ # A typedef of a struct or union, whose type a variable may hold before it is complete
33
+ AGGREGATE_TYPEDEF = /\Atypedef\s+(?:struct|union)(?![\w$])/ unless const_defined?(:AGGREGATE_TYPEDEF, false)
34
+
35
+ # Explains helpers a Partial leaves behind because the module header has no include guard
36
+ UNGUARDED_HELPERS_NOTICE = <<~NOTICE unless const_defined?(:UNGUARDED_HELPERS_NOTICE, false)
37
+ Partial %<partial>s ⏩️ Not carrying %<noun>s %<helpers>s from %<header>s.
38
+ Selected functions call %<these>s, but %<header>s has no include guard. Without a guard
39
+ a Partial cannot stand in for the header everywhere it is included, and a carried copy could
40
+ collide with the real one.
41
+
42
+ OPTIONS:
43
+ 1. Give %<header>s an include guard so the Partial can stand in for it.
44
+ 2. Select the %<noun>s with `+name` (for example `+%<first>s`). This works only when no other
45
+ header this module includes pulls in %<header>s.
46
+
47
+ See the docs on Partials conventions.
48
+ NOTICE
49
+
50
+ # Explains what a mock-only Partial leaves behind because its module header has no include guard
51
+ UNGUARDED_EXTRAS_NOTICE = <<~NOTICE unless const_defined?(:UNGUARDED_EXTRAS_NOTICE, false)
52
+ Partial %<partial>s ⏩️ Its mock leaves %<items>s from %<header>s behind.
53
+ %<header>s has no include guard. Without a guard the mock can't stand in for the header everywhere
54
+ it's included, and a copy could collide with the real one. Code that uses %<these>s compiles only where
55
+ another #include brings in the real header.
56
+
57
+ Give %<header>s an include guard so the mock keeps %<them>s.
58
+
59
+ See the docs on Partials conventions.
60
+ NOTICE
61
+
62
+ # The same for a header that guards itself with `#pragma once`, which no generated file can
63
+ # define the way it defines an include guard
64
+ PRAGMA_ONCE_EXTRAS_NOTICE = <<~NOTICE unless const_defined?(:PRAGMA_ONCE_EXTRAS_NOTICE, false)
65
+ Partial %<partial>s ⏩️ Its mock leaves %<items>s from %<header>s behind.
66
+
67
+ HOW THIS HAPPENS:
68
+ • %<header>s uses `#pragma once`, which is not an include guard.
69
+ • 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.
70
+ • Without one, a kept copy could collide with the real one, so the mock leaves %<them>s out.
71
+ • Code that uses %<these>s compiles only where another #include brings in the real header.
72
+
73
+ Replace `#pragma once` in %<header>s with an include guard so the mock keeps %<them>s.
74
+
75
+ See the docs on Partials conventions.
76
+ NOTICE
77
+
78
+ # The same for a module header that guards itself with `#pragma once`
79
+ PRAGMA_ONCE_HELPERS_NOTICE = <<~NOTICE unless const_defined?(:PRAGMA_ONCE_HELPERS_NOTICE, false)
80
+ Partial %<partial>s ⏩️ Not carrying %<noun>s %<helpers>s from %<header>s.
81
+
82
+ HOW THIS HAPPENS:
83
+ • Selected functions call %<these>s.
84
+ • %<header>s uses `#pragma once`, which is not an include guard.
85
+ • 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.
86
+ • Without one, a carried copy could collide with the real one.
87
+
88
+ OPTIONS:
89
+ 1. Replace `#pragma once` in %<header>s with an include guard so the Partial can stand in for it.
90
+ 2. Select the %<noun>s with `+name` (for example `+%<first>s`). This works only when no other header this module includes pulls in %<header>s.
91
+
92
+ See the docs on Partials conventions.
93
+ NOTICE
94
+
95
+ # Explains what other Partials go without from a module a test both tests and mocks. The
96
+ # notice follows the linker failure guidance: what happened, why, then numbered options.
97
+ TESTED_MOCK_NOTICE = <<~NOTICE unless const_defined?(:TESTED_MOCK_NOTICE, false)
98
+ Partial %<partial>s ⏩️ Other Partials in this test include %<header>s's mock, which leaves %<items>s out.
99
+
100
+ HOW THIS HAPPENS:
101
+ • A module both tested and mocked in one test keeps its header's helpers and static variables in its own implementation.
102
+ • Every other Partial that includes %<header>s gets the mock's interface in its place, which declares only the mocked functions.
103
+ • Code in those Partials that uses %<them>s fails to compile or link.
104
+
105
+ OPTIONS:
106
+ 1. Test %<module>s in a test file of its own, and only mock it in this one.
107
+ 2. Move what the other Partials use into a header that %<header>s includes, which the mock keeps.
108
+
109
+ See the docs on Partials conventions.
110
+ NOTICE
25
111
 
26
112
  include Partials
27
113
 
28
- constructor :configurator, :partializer_helper, :file_finder, :c_extractor, :file_path_utils,
114
+ constructor :configurator, :partializer_helper, :partializer_reconciler, :file_finder, :c_extractor, :file_path_utils,
29
115
  :preprocessinator_reconstructor, :file_wrapper, :reportinator, :loginator
30
116
 
31
117
  def setup()
@@ -33,7 +119,7 @@ class Partializer
33
119
  @helper = @partializer_helper
34
120
  end
35
121
 
36
- def validate_config(c_module:, config:, name:, fallback:)
122
+ def validate_config(c_module:, config:, name:)
37
123
  msg = @reportinator.generate_progress("Validating Partial config for '#{name}'")
38
124
  @loginator.log(msg, Verbosity::DEBUG)
39
125
  @helper.validate_function_names_exist(c_module, config, name)
@@ -43,7 +129,7 @@ class Partializer
43
129
  # Fallback preprocessing resolves strictly less than the accurate pass, and two module
44
130
  # shapes are knowably beyond it. Reading the original text happens here, at the I/O edge,
45
131
  # so the check itself stays pure.
46
- return unless fallback
132
+ return unless config.fallback?
47
133
 
48
134
  @helper.validate_fallback_sufficiency(
49
135
  name: name,
@@ -52,13 +138,70 @@ class Partializer
52
138
  )
53
139
  end
54
140
 
55
- def sanitize(c_module)
56
- # Remove macro definitions carrying a generated include guard. Ceedling writes these into
57
- # the headers it generates, and they belong to those headers, not the module.
58
- removed = c_module.macro_definitions.select { |m| m.text.match?(GENERATED_INCLUDE_GUARD_PATTERN) }
59
- # Remove from both the macro_definitions list and the element_sequence that references it
60
- c_module.macro_definitions.reject! { |m| removed.include?(m) }
61
- c_module.element_sequence.reject! { |e| removed.include?(e) }
141
+ # Removes the include guards the module's macros carry, from both macro_definitions and the
142
+ # element_sequence that references them. A generated guard belongs to a header Ceedling wrote.
143
+ # The real header's own guard survives preprocessing too, and every generated file already
144
+ # states it deliberately, so a carried copy would only repeat it. Only a guard defined bare
145
+ # counts, so a macro whose name merely begins with the guard's, or one giving it a value, stays.
146
+ def sanitize(c_module, include_guard: nil)
147
+ real = include_guard && /\A\s*#\s*define\s+#{Regexp.escape( include_guard )}\s*\z/
148
+ c_module.remove!( c_module.macro_definitions.select { |m| m.text.match?( GENERATED_INCLUDE_GUARD_PATTERN ) or (real and m.text.match?( real )) } )
149
+ end
150
+
151
+ # Decides what the Partial's implementation source carries beyond its selected functions.
152
+ # See PartializerHelper#plan_carry for the categories it applies.
153
+ #
154
+ # @param test [String] Test name (for log messages)
155
+ # @param c_module [CExtractorTypes::CModule] The module's merged contents
156
+ # @param impl [Array<Partials::FunctionDefinition>] Functions selected to test
157
+ # @param interface [Array<Partials::FunctionDeclaration>, nil] Functions selected to mock
158
+ # @param header_guarded [Boolean] Whether the module header has an include guard
159
+ # @param config [PartializerConfig::Config] The Partial, whose files are searched for
160
+ # carried prototypes and named in notices
161
+ # @return [Partials::CarryPlan]
162
+ def plan_carry(test:, c_module:, impl:, interface:, header_guarded:, config:)
163
+ plan = @helper.plan_carry(
164
+ c_module: c_module, impl: impl, interface: interface, fallback: config.fallback?, header_guarded: header_guarded
165
+ )
166
+
167
+ _locate_carried( plan, { header: config.header.filepath, source: config.source.filepath } )
168
+ plan.incomplete.merge( _incomplete_variables( c_module, config ) )
169
+
170
+ _log_plan( test, config.module, plan, config.header.filepath )
171
+ return plan
172
+ end
173
+
174
+ # Decides what a mock-only Partial's extras header keeps of its real header beyond the mocked
175
+ # functions. See PartializerHelper#plan_interface_extras for what it keeps and withholds.
176
+ #
177
+ # @param test [String] Test name (for log messages)
178
+ # @param c_module [CExtractorTypes::CModule] The module's merged contents
179
+ # @param interface [Array<Partials::FunctionDeclaration>] Functions selected to mock
180
+ # @param header_guarded [Boolean] Whether the module header has an include guard
181
+ # @param config [PartializerConfig::Config] The Partial, named in notices
182
+ # @return [Partials::InterfaceExtras]
183
+ def plan_interface_extras(test:, c_module:, interface:, header_guarded:, config:)
184
+ extras = @helper.plan_interface_extras(
185
+ c_module: c_module, interface: interface, fallback: config.fallback?, header_guarded: header_guarded
186
+ )
187
+
188
+ _log_extras( "#{test}::#{config.module}", extras, config.header.filepath )
189
+ return extras
190
+ end
191
+
192
+ # Explains what other Partials go without from a module the test both tests and mocks: its
193
+ # implementation carries what its own code uses, but its interface keeps no extras, so another
194
+ # Partial including its header gets only the mocked functions. Names only what the code of
195
+ # the other Partials including the header uses, and says nothing when that's nothing.
196
+ def explain_tested_mock(test:, c_module:, interface:, header_guarded:, config:, partials:)
197
+ items = _extras_others_use( c_module, interface, header_guarded, config, partials )
198
+ return if items.empty?
199
+
200
+ notice = format(
201
+ TESTED_MOCK_NOTICE, partial: "#{test}::#{config.module}", header: config.header.filepath, module: config.module,
202
+ items: _withheld_phrase( items ), them: items.size > 1 ? 'them' : 'it'
203
+ )
204
+ @loginator.log( notice, Verbosity::COMPLAIN, LogLabels::NOTICE )
62
205
  end
63
206
 
64
207
  def validate_extracted_functions(name:, partial:, impl:, interface:)
@@ -162,15 +305,16 @@ class Partializer
162
305
  )
163
306
  end
164
307
 
165
- # Includes for the generated implementation header. This module's own header is replaced by
166
- # the shared types header at its original list position; every other partialized module's
167
- # include is dropped.
308
+ # Includes for the generated implementation header, in groups (see _remap_include_groups). This
309
+ # module's own header is replaced by the shared types header at its original list position;
310
+ # every other partialized module's include is dropped.
168
311
  #
169
312
  # When `test:` is provided, logs the resulting includes at OBNOXIOUS.
170
- def remap_implementation_header_includes(name:, includes:, partials:, types_header: nil, test: nil)
171
- _remap_includes(
313
+ def remap_implementation_header_includes(name:, source_includes:, partials:, header_includes: [], types_header: nil, test: nil)
314
+ _remap_include_groups(
172
315
  name: name,
173
- includes: includes,
316
+ source: source_includes,
317
+ header: header_includes,
174
318
  partials: partials,
175
319
  replacement: types_header,
176
320
  others: :drop,
@@ -184,10 +328,11 @@ class Partializer
184
328
  # in one test file still gets exactly one definition of each of its types.
185
329
  #
186
330
  # When `test:` is provided, logs the resulting includes at OBNOXIOUS.
187
- def remap_interface_header_includes(name:, includes:, partials:, types_header: nil, test: nil)
188
- _remap_includes(
331
+ def remap_interface_header_includes(name:, source_includes:, partials:, header_includes: [], types_header: nil, test: nil)
332
+ _remap_include_groups(
189
333
  name: name,
190
- includes: includes,
334
+ source: source_includes,
335
+ header: header_includes,
191
336
  partials: partials,
192
337
  replacement: types_header,
193
338
  others: :drop,
@@ -205,7 +350,7 @@ class Partializer
205
350
  def remap_implementation_source_includes(name:, includes:, partials:, test: nil)
206
351
  _remap_includes(
207
352
  name: name,
208
- includes: includes,
353
+ includes: _own_header_index( name, includes, partials ) ? includes : includes + [OWN_HEADER_PLACE],
209
354
  partials: partials,
210
355
  replacement: @file_path_utils.form_partial_implementation_header_filename(name),
211
356
  others: :mock_or_keep,
@@ -221,10 +366,11 @@ class Partializer
221
366
  # very content that module's own Partial replaced.
222
367
  #
223
368
  # When `test:` is provided, logs the resulting includes at OBNOXIOUS.
224
- def remap_types_header_includes(name:, includes:, partials:, test: nil)
225
- _remap_includes(
369
+ def remap_types_header_includes(name:, source_includes:, partials:, header_includes: [], test: nil)
370
+ _remap_include_groups(
226
371
  name: name,
227
- includes: includes,
372
+ source: source_includes,
373
+ header: header_includes,
228
374
  partials: partials,
229
375
  replacement: nil,
230
376
  others: :mock_or_drop,
@@ -243,7 +389,7 @@ class Partializer
243
389
  def extract_module_include_guard(filepath)
244
390
  return nil if filepath.nil?
245
391
 
246
- text = @file_wrapper.read( filepath, GUARD_SCAN_BYTES ).clean_encoding
392
+ text = @file_wrapper.read( filepath ).clean_encoding
247
393
  @preprocessinator_reconstructor.extract_include_guard( text )
248
394
  end
249
395
 
@@ -255,10 +401,8 @@ class Partializer
255
401
  # CModule structure.
256
402
  #
257
403
  # @param name [String] The test this extraction is running for (log/error context).
258
- # @param config [Partials::ModuleConfig] The Partial's own config, carrying `header`/
404
+ # @param config [PartializerConfig::Config] The Partial's own config, carrying `header`/
259
405
  # `source` (each a ConfigFileInfo) and `module`, the module name.
260
- # @param fallback [Boolean] Passed through to `associate_function_line_numbers` --
261
- # whether to fall back to plain (non-directives-only) line-number association.
262
406
  #
263
407
  # @return [CExtractorTypes::CModule] A merged CModule containing all extracted contents
264
408
  # from both files. The structure includes:
@@ -268,59 +412,24 @@ class Partializer
268
412
  #
269
413
  # @note The method always starts with an empty CModule and merges in contents
270
414
  # from any provided files using the CModule's + operator for combining structures.
271
- def extract_module_contents(name, config, fallback:)
415
+ def extract_module_contents(name, config)
272
416
  # Array for CModule structs
273
417
  contents = [CExtractorTypes::CModule.new()]
274
418
 
275
419
  # Process the C module source and/or header associated with the Partial config
276
420
  [config.header, config.source].zip(['header', 'source']).each do |c_file, file_type|
277
- # Do nothing if there's no directives-only preprocessed filepath (e.g. no source only header for a Partial mock)
278
- next unless c_file.directives_only_filepath
279
-
280
- c_module = @c_extractor.from_file( c_file.directives_only_filepath )
281
-
282
- _log_module_contents(name, config.module, file_type, c_module)
283
-
284
- # Update function signatures from fully preprocessed output when available.
285
- # Replaces signature/decorators/signature_stripped (but NOT code_block) so that
286
- # macros wrapping `static` and `inline` are resolved before visibility filtering.
287
- if c_file.full_expansion_filepath
288
- @helper.update_signatures_from_full_expansion(
289
- funcs: c_module.function_definitions,
290
- full_expansion_filepath: c_file.full_expansion_filepath,
291
- name: name,
292
- module_name: config.module,
293
- file_type: file_type
294
- )
295
- end
296
-
297
- # Align extracted function definitions with line markers in preprocessor output.
298
- # This perfectly remaps functions found in expanded preprocessor output with
299
- # original source location.
300
- # This routine depends on original, unaltered function definitions.
301
- @helper.associate_function_line_numbers(
302
- name: name,
303
- funcs: c_module.function_definitions,
304
- filepath: c_file.filepath,
305
- fallback: fallback
306
- )
307
-
308
- # 1. Find any function-scope static variable declarations.
309
- # 2. Replace them in function definitions with no-ops (for proper coverage reporting).
310
- # 3. Promote the function-scoped variables to be module-level variables.
311
- decls = @helper.extract_function_scope_static_vars(
312
- c_module.function_definitions,
313
- name: name, module_name: config.module, file_type: file_type
314
- )
315
- c_module.variable_declarations.concat(decls)
316
- c_module.element_sequence.concat(decls) unless decls.empty?
421
+ # Skip a file preprocessing never assembled, such as the absent source of a header-only Partial mock
422
+ next unless c_file.assembled_filepath
317
423
 
318
- contents << c_module
424
+ contents << _extract_file_contents( name, config, c_file, file_type )
319
425
  end
320
426
 
321
427
  # Use `+` operator for CModule to merge everything
322
428
  contents = contents.reduce(&:+)
323
429
 
430
+ # Only the merged module knows which functions have a body
431
+ _mark_inline_elsewhere( config, contents )
432
+
324
433
  return contents
325
434
  end
326
435
 
@@ -411,12 +520,7 @@ class Partializer
411
520
  Verbosity::DEBUG
412
521
  )
413
522
 
414
- # A mock interface only ever needs a signature, never a body, so a declaration-only
415
- # function (no body found anywhere in this module's merged content) is just as valid a
416
- # candidate as one with a definition -- unlike extract_implementation_functions, which
417
- # needs real code to inject and so stays definitions-only. A function named in both
418
- # (declared in the header, defined in the paired source) is only counted once.
419
- candidates = definitions + declarations.reject { |d| definitions.any? { |f| f.name == d.name } }
523
+ candidates = _mock_candidates( test, partial, definitions, declarations )
420
524
 
421
525
  # Build initial list by visibility; ACCUMULATE yields []
422
526
  funcs = @helper.filter_and_transform_funcs(candidates, pf.type, :interface)
@@ -453,6 +557,295 @@ class Partializer
453
557
 
454
558
  private
455
559
 
560
+ # Extracts one of a module's files, a header or a source, ready to merge with the other.
561
+ def _extract_file_contents(name, config, c_file, file_type)
562
+ c_module = @c_extractor.from_file( c_file.assembled_filepath )
563
+ @helper.validate_function_names_readable( c_module, name, config.module )
564
+
565
+ _log_module_contents(name, config.module, file_type, c_module)
566
+
567
+ _reconcile( name, config, c_file, file_type, c_module ) if c_file.expansion_filepath
568
+ _locate_contents( c_file, c_module )
569
+ _promote_function_scope_statics( name, config, file_type, c_module )
570
+ Partials.name_defined_types( c_module, config.module )
571
+
572
+ return c_module.stamp_origin!( file_type.to_sym )
573
+ end
574
+
575
+ # Each item takes from its twin in the file's expanded code what a macro can hide, before
576
+ # visibility filtering reads it. What line location reads stays as written.
577
+ def _reconcile(name, config, c_file, file_type, c_module)
578
+ @partializer_reconciler.reconcile(
579
+ c_module: c_module, expansion_filepath: c_file.expansion_filepath, name: name, module_name: config.module, file_type: file_type
580
+ )
581
+ end
582
+
583
+ # A header a file includes may define inline a function the module declares but never
584
+ # defines. Under C99 the declaring file then holds that function's external definition. Each
585
+ # file's raw directives-only copy holds every header it includes, so the inline body is
586
+ # looked for there. A function the module defines is never looked for, since nothing reads
587
+ # its mark. The copy is read as bytes, which is all the scan needs.
588
+ def _mark_inline_elsewhere(config, c_module)
589
+ undefined = _declaration_only( c_module.function_definitions, c_module.function_declarations )
590
+
591
+ { header: config.header, source: config.source }.each do |origin, c_file|
592
+ decls = undefined.select { |decl| decl.origin == origin }
593
+ _mark_from_raw_copy( c_file, decls ) unless decls.empty?
594
+ end
595
+ end
596
+
597
+ # A file preprocessed in fallback has no raw copy, so nothing is marked from it
598
+ def _mark_from_raw_copy(c_file, decls)
599
+ raw = c_file.raw_directives_only_filepath
600
+ return if raw.nil?
601
+
602
+ @helper.mark_inline_elsewhere( decls: decls, text: @file_wrapper.read_binary( raw ) )
603
+ end
604
+
605
+ # The declarations of functions with no definition among `definitions`
606
+ def _declaration_only(definitions, declarations)
607
+ defined = Set.new( definitions.map( &:name ) )
608
+ return declarations.reject { |decl| defined.include?( decl.name ) }
609
+ end
610
+
611
+ def _locate_contents(c_file, c_module)
612
+ # Align extracted function definitions with line markers in preprocessor output.
613
+ # This perfectly remaps functions found in expanded preprocessor output with
614
+ # original source location.
615
+ # This routine depends on original, unaltered function definitions.
616
+ @helper.associate_function_line_numbers(
617
+ funcs: c_module.function_definitions, filepath: c_file.filepath, raw_filepath: c_file.raw_directives_only_filepath
618
+ )
619
+ end
620
+
621
+ # 1. Find any function-scope static variable declarations.
622
+ # 2. Replace them in function definitions with no-ops (for proper coverage reporting).
623
+ # 3. Promote the function-scoped variables to be module-level variables.
624
+ def _promote_function_scope_statics(name, config, file_type, c_module)
625
+ @helper.promote_function_scope_statics( c_module, name: name, module_name: config.module, file_type: file_type )
626
+ end
627
+
628
+ # A mock interface only ever needs a signature, never a body, so a declaration-only
629
+ # function (no body found anywhere in this module's merged content) is just as valid a
630
+ # candidate as one with a definition -- unlike extract_implementation_functions, which
631
+ # needs real code to inject and so stays definitions-only. A function named in both
632
+ # (declared in the header, defined in the paired source) is only counted once.
633
+ #
634
+ # An inline function the module only declares has its body in a header it includes. A mock
635
+ # can never replace that body, so mocking it would only define the function twice. It stays
636
+ # out, and the implementation source carries its prototype when the module is also tested.
637
+ def _mock_candidates(test, partial, definitions, declarations)
638
+ declaration_only = _declaration_only( definitions, declarations )
639
+ foreign_inline = Set.new( declaration_only.select { |d| Partials.foreign_inline?( d ) }.map( &:name ) )
640
+
641
+ _log_not_mockable( test, partial, foreign_inline )
642
+ return definitions + declaration_only.reject { |d| foreign_inline.include?( d.name ) }
643
+ end
644
+
645
+ def _log_not_mockable(test, partial, names)
646
+ return if names.empty?
647
+
648
+ @loginator.log_list(
649
+ names.map { |n| "`#{n}`" },
650
+ "Not mockable for Partial #{test}::#{partial} (inline, body outside module):",
651
+ Verbosity::DEBUG
652
+ )
653
+ end
654
+
655
+ # Variables the module declares `extern` whose struct or union type is never completed,
656
+ # directly or through a typedef the module makes. No definition of one compiles, weak or not.
657
+ # The module's own files are searched for the completing definition, and so are their raw
658
+ # directives-only copies where those exist, since a copy holds every header its file includes.
659
+ def _incomplete_variables(c_module, config)
660
+ candidates = _extern_aggregates( c_module )
661
+ return Set.new if candidates.empty?
662
+
663
+ texts = _translation_unit_texts( config )
664
+ return Set.new( candidates.filter_map { |var, tag| var.name unless _completed?( tag, texts ) } )
665
+ end
666
+
667
+ # Each extern variable whose type names a struct or union by value, paired with its tag. A
668
+ # declarator in parentheses makes a pointer, which holds no struct by value.
669
+ def _extern_aggregates(c_module)
670
+ tags = _aggregate_tags( c_module )
671
+ plain = c_module.variable_declarations.select { |v| v.extern? and v.declarator.nil? }
672
+ return plain.filter_map { |v| [v, tags[Partials.named_type( v )]] if tags.key?( Partials.named_type( v ) ) }
673
+ end
674
+
675
+ # Each type a variable may name by value that is a struct or union tag, keyed to its tag. A
676
+ # pointer to an incomplete type is complete itself, so only `struct x` and typedef names count.
677
+ def _aggregate_tags(c_module)
678
+ tags = {}
679
+ c_module.variable_declarations.each do |v|
680
+ tag = Partials.named_type( v )[/\A(?:struct|union)\s+([\w$]+)\z/, 1]
681
+ tags[Partials.named_type( v )] = tag if tag
682
+ end
683
+ c_module.type_definitions.each do |typedef|
684
+ tags[typedef.type_name] = typedef.tag if typedef.tag and typedef.type_name and typedef.text.match?( AGGREGATE_TYPEDEF )
685
+ end
686
+
687
+ return tags
688
+ end
689
+
690
+ # Each of the module's files and its raw copy where one exists, read as bytes, which is all
691
+ # the search needs.
692
+ # Transcoding a raw copy would cost far more than reading it.
693
+ def _translation_unit_texts(config)
694
+ files = [config.header, config.source].select( &:filepath )
695
+ paths = files.map( &:filepath ) + files.filter_map( &:raw_directives_only_filepath )
696
+ return paths.map { |path| @file_wrapper.read_binary( path ) }
697
+ end
698
+
699
+ def _completed?(tag, texts)
700
+ return texts.any? { |text| text.match?( /(?<![\w$])(?:struct|union)\s+#{Regexp.escape( tag )}\s*\{/ ) }
701
+ end
702
+
703
+ # A carried prototype is written behind a #line naming its own file and line. Each is found in
704
+ # its original file's own text, where no included header's lines can be mistaken for it. Only
705
+ # carried prototypes are located, since each costs a search of the file.
706
+ def _locate_carried(plan, filepaths)
707
+ plan.prototypes.map( &:item ).group_by( &:origin ).each do |origin, decls|
708
+ filepath = filepaths[origin]
709
+ next if filepath.nil?
710
+
711
+ @helper.associate_declaration_line_numbers(
712
+ decls: decls, filepath: filepath, text: @file_wrapper.read( filepath ).clean_encoding
713
+ )
714
+ end
715
+ end
716
+
717
+ def _log_plan(test, partial, plan, header_filepath)
718
+ _log_carried( test, partial, plan )
719
+ plan.skipped.each { |skipped| _log_not_carried( test, partial, skipped ) }
720
+
721
+ unguarded = plan.skipped.select { |skipped| skipped.kind == :unguarded_helper }.map( &:item )
722
+ _log_unguarded_helpers( test, partial, unguarded, header_filepath ) unless unguarded.empty?
723
+ end
724
+
725
+ # Lists what a Partial carries and why, so a user can trace what its implementation holds
726
+ def _log_carried(test, partial, plan)
727
+ entries = plan.prototypes.map { |carried| "`#{carried.item.signature.strip}` (#{carried.reason})" }
728
+ entries += plan.helpers.map { |name, carried| "`#{name}()` (#{carried.reason})" }
729
+ return if entries.empty?
730
+
731
+ @loginator.log_list( entries, "Carried into Partial #{test}::#{partial} implementation:", Verbosity::DEBUG )
732
+ end
733
+
734
+ # A skipped name is one a selected function may need, so each gets a notice saying why
735
+ def _log_not_carried(test, partial, skipped)
736
+ msg = _not_carried_message( skipped.kind, skipped.item )
737
+ @loginator.log( "Partial #{test}::#{partial} ⏩️ #{msg}", Verbosity::COMPLAIN, LogLabels::NOTICE ) if msg
738
+ end
739
+
740
+ def _not_carried_message(kind, name)
741
+ case kind
742
+ when :helper_conflict
743
+ return "Not carrying helper `#{name}()`: fallback preprocessing found more than one definition. " \
744
+ "Add `+#{name}` if a selected function needs it"
745
+ when :prototype_conflict
746
+ return "Not carrying `#{name}()`: fallback preprocessing found conflicting declarations"
747
+ end
748
+
749
+ return nil
750
+ end
751
+
752
+ # A header without an include guard can't be stood in for, so its helpers stay behind. The
753
+ # notice follows the linker failure guidance: what happened, why, then numbered options.
754
+ def _log_unguarded_helpers(test, partial, names, header)
755
+ many = names.size > 1
756
+ notice = format(
757
+ _pragma_once?( header ) ? PRAGMA_ONCE_HELPERS_NOTICE : UNGUARDED_HELPERS_NOTICE,
758
+ partial: "#{test}::#{partial}", header: header, first: names.first,
759
+ helpers: names.map { |n| "`#{n}()`" }.join( ', ' ),
760
+ noun: many ? 'helpers' : 'helper', these: many ? 'these helpers' : 'this helper'
761
+ )
762
+
763
+ @loginator.log( notice, Verbosity::COMPLAIN, LogLabels::NOTICE )
764
+ end
765
+
766
+ # Lists what a mock-only Partial keeps, and explains what an unguarded header's mock leaves behind
767
+ def _log_extras(partial, extras, header)
768
+ entries = extras.items.map { |item| _extras_entry( item ) }
769
+ @loginator.log_list( entries, "Kept in the mock of Partial #{partial}:", Verbosity::DEBUG ) unless entries.empty?
770
+ return if extras.withheld.empty?
771
+
772
+ many = extras.withheld.size > 1
773
+ notice = _pragma_once?( header ) ? PRAGMA_ONCE_EXTRAS_NOTICE : UNGUARDED_EXTRAS_NOTICE
774
+ @loginator.log(
775
+ format( notice, partial: partial, header: header, items: _withheld_phrase( extras.withheld ),
776
+ these: many ? 'these' : 'it', them: many ? 'them' : 'it' ),
777
+ Verbosity::COMPLAIN, LogLabels::NOTICE
778
+ )
779
+ end
780
+
781
+ # The header is read again only when something stays behind, to say what guards it
782
+ def _pragma_once?(header)
783
+ return @preprocessinator_reconstructor.pragma_once?( @file_wrapper.read( header ).clean_encoding )
784
+ end
785
+
786
+ def _extras_entry(item)
787
+ case item
788
+ when CExtractorTypes::CFunctionDefinition then return "`#{item.name}()` (helper)"
789
+ when CExtractorTypes::CFunctionDeclaration then return "`#{item.name}()` (prototype)"
790
+ end
791
+
792
+ return "`#{item.name}` (#{item.extern? ? 'extern declaration' : 'static variable'})"
793
+ end
794
+
795
+ # As in "helper `twice()` and variables `a`, `b`", or "helper `twice()`, variable `a` and prototype `get()`"
796
+ def _withheld_phrase(items)
797
+ phrases = EXTRAS_NOUNS.filter_map do |kind, noun|
798
+ named = items.select { |item| item.is_a?( kind ) }
799
+ _named( noun, named.map { |item| kind == CExtractorTypes::CVariableDeclaration ? "`#{item.name}`" : "`#{item.name}()`" } ) unless named.empty?
800
+ end
801
+
802
+ return phrases.size > 1 ? "#{phrases[0..-2].join( ', ' )} and #{phrases.last}" : phrases.join
803
+ end
804
+
805
+ # What an extras item is called in a notice
806
+ EXTRAS_NOUNS = {
807
+ CExtractorTypes::CFunctionDefinition => 'helper',
808
+ CExtractorTypes::CVariableDeclaration => 'variable',
809
+ CExtractorTypes::CFunctionDeclaration => 'prototype'
810
+ }.freeze unless const_defined?(:EXTRAS_NOUNS, false)
811
+
812
+ # What a module's mock would keep in extras that the code of other Partials including its header uses
813
+ def _extras_others_use(c_module, interface, header_guarded, config, partials)
814
+ extras = @helper.plan_interface_extras(
815
+ c_module: c_module, interface: interface, fallback: config.fallback?, header_guarded: header_guarded
816
+ )
817
+ return [] if extras.items.empty?
818
+
819
+ used = _names_used_by_includers( config.module, partials )
820
+ return extras.items.select { |item| used.include?( item.name ) }
821
+ end
822
+
823
+ # The names the code of every other Partial including the module's header uses, from each
824
+ # file's full expansion, which shows a use through a macro, or else the file stages 6 and 7
825
+ # assembled for it
826
+ def _names_used_by_includers(_module, partials)
827
+ paths = _includers( _module, partials ).flat_map { |config| _module_files( config ) }.filter_map do |file|
828
+ file.expansion_filepath || file.assembled_filepath
829
+ end
830
+
831
+ return paths.each_with_object( Set.new ) { |path, used| used.merge( @helper.names_in( @file_wrapper.read( path ).clean_encoding ) ) }
832
+ end
833
+
834
+ # Every other Partial whose files include the module's header
835
+ def _includers(_module, partials)
836
+ return partials.reject { |other, _| other == _module }.values.select do |config|
837
+ _module_files( config ).flat_map { |file| Array( file.includes ) }.any? { |include| _names_module?( include, _module, partials ) }
838
+ end
839
+ end
840
+
841
+ def _module_files(config)
842
+ return [config.source, config.header].compact
843
+ end
844
+
845
+ def _named(noun, names)
846
+ return "#{noun}#{'s' if names.size > 1} #{names.join( ', ' )}"
847
+ end
848
+
456
849
  # Log all user-defined (non-function) C content extracted from a module's source/header at OBNOXIOUS level.
457
850
  # Covers the four categories that are injected into generated Partial files:
458
851
  # variable declarations, type definitions, macro definitions, and aggregate definitions
@@ -507,16 +900,42 @@ class Partializer
507
900
  )
508
901
  end
509
902
 
510
- # The module's own header and source text, keyed by filepath. A declaration-only Partial has
511
- # no paired source, which leaves that filepath legitimately nil.
903
+ # The text of each module file preprocessed in fallback, keyed by filepath. Fallback's limits
904
+ # belong to the file that fell back, so a file preprocessed accurately isn't checked. A
905
+ # declaration-only Partial has no paired source, which leaves that filepath legitimately nil.
512
906
  def _module_file_texts(config)
513
907
  [config.header, config.source].filter_map do |file_info|
514
- next if file_info.nil? || file_info.filepath.nil?
908
+ next if file_info.nil? || file_info.filepath.nil? || !file_info.fallback
515
909
 
516
910
  [file_info.filepath, @file_wrapper.read( file_info.filepath ).clean_encoding]
517
911
  end.to_h
518
912
  end
519
913
 
914
+ # A generated header's includes in the order the source compiles them: the source's includes
915
+ # ahead of the module's header, the header's own, then the source's after it. The last make
916
+ # up the following group (see Partials::IncludeGroups).
917
+ #
918
+ # A source that never includes its own header, or a header-only module's absent source, is
919
+ # read as including it last. OWN_HEADER_PLACE holds that place, so whatever replaces the
920
+ # module's header lands there, in the leading group, ahead of the declarations. The following
921
+ # group is then empty.
922
+ #
923
+ # The whole list is remapped at once, so deduplication, redirects, and sorting see every
924
+ # include. An include in both groups keeps its earlier place. A marker holds the boundary.
925
+ def _remap_include_groups(name:, source:, header:, **remap)
926
+ index = _own_header_index( name, source, remap[:partials] )
927
+ leading = index.nil? ? source + [OWN_HEADER_PLACE] : source[0..index]
928
+ following = index.nil? ? [] : source[(index + 1)..]
929
+ remapped = _remap_includes( name: name, includes: leading + header + [INCLUDE_BOUNDARY] + following, **remap )
930
+
931
+ return Partials::IncludeGroups.split( remapped, INCLUDE_BOUNDARY )
932
+ end
933
+
934
+ # Where the source includes the module's own header, or nil when it never does
935
+ def _own_header_index(name, source, partials)
936
+ return source.index { |include| _names_module?( include, name, partials ) }
937
+ end
938
+
520
939
  # One body behind all four public remaps. Each differs only in what replaces this module's
521
940
  # own header, what becomes of other partialized modules, and the noun it logs under -- the
522
941
  # splice, the sanitize, and the logging are identical in every case.
@@ -529,12 +948,12 @@ class Partializer
529
948
  _includes = includes.clone()
530
949
 
531
950
  # A nil replacement strips this module's own header and substitutes nothing.
532
- _includes = splice_in_replacement( includes: _includes, name: name, replacement: replacement )
951
+ _includes = splice_in_replacement( includes: _includes, name: name, replacement: replacement, partials: partials )
533
952
 
534
953
  _includes =
535
954
  case others
536
955
  when :drop
537
- remove_matching_includes( includes: _includes, modules: (partials.keys - [name]) )
956
+ remove_matching_includes( includes: _includes, modules: (partials.keys - [name]), partials: partials )
538
957
  when :mock_or_keep, :mock_or_drop
539
958
  # The types header differs from the generated source in two ways at once, which is why
540
959
  # both flags below read from one condition.
@@ -555,17 +974,19 @@ class Partializer
555
974
  name: name,
556
975
  partials: partials,
557
976
  drop_unmocked: shared_types_header,
558
- skip_self: shared_types_header
977
+ skip_self: shared_types_header,
978
+ replacement: replacement
559
979
  )
560
980
  else
561
981
  PartializerRuntime.raise_on_option( others )
562
982
  end
563
983
 
564
- # Remove any duplicates
984
+ # Remove any duplicates, and fallback's unresolved text beside the header it names
565
985
  Includes.sanitize!(_includes)
986
+ Includes.drop_shadowed!(_includes)
566
987
 
567
988
  @loginator.log_list(
568
- _includes,
989
+ _includes.reject { |include| include.equal?( INCLUDE_BOUNDARY ) },
569
990
  "#{noun} #{test}::#{name}:",
570
991
  Verbosity::OBNOXIOUS
571
992
  ) if test
@@ -573,10 +994,10 @@ class Partializer
573
994
  return _includes
574
995
  end
575
996
 
576
- # Appends the generated interface header for each mocked partialized module the original list
577
- # named, then removes the real headers those replaced. `skip_self` decides whether the module
578
- # being generated counts as one of them, which it does everywhere except the types header --
579
- # see the call site.
997
+ # Puts the generated interface header of each mocked partialized module the original list
998
+ # named where that module's real header was, then removes any other copies of the real
999
+ # headers. `skip_self` decides whether the module being generated counts as one of them,
1000
+ # which it does everywhere except the types header -- see the call site.
580
1001
  #
581
1002
  # Mutates `includes`, which always arrives fresh from splice_in_replacement.
582
1003
  #
@@ -585,24 +1006,44 @@ class Partializer
585
1006
  # added later without updating the check, so a module mocked via either was silently never
586
1007
  # redirected: its real header, and any static inline or static function bodies in it, stayed
587
1008
  # #include'd verbatim and compiled straight past the mock.
588
- def _redirect_mocked_partials(includes:, original:, name:, partials:, drop_unmocked:, skip_self:)
1009
+ def _redirect_mocked_partials(includes:, original:, name:, partials:, drop_unmocked:, skip_self:, replacement:)
589
1010
  retired = []
590
1011
 
591
1012
  partials.each do |_module, config|
592
1013
  next if skip_self && _module == name
593
- next unless original.any? { |include| include.filename.ext().downcase() == _module.downcase() }
1014
+ next unless _named_in?( original, _module, name, partials )
594
1015
 
595
1016
  if config.mocks.type.nil?
596
1017
  retired << _module if drop_unmocked
597
1018
  else
598
- includes << UserInclude.new(
599
- @file_path_utils.form_partial_interface_header_filename(_module)
600
- )
1019
+ _place_interface_header( includes, _module, (_module == name) ? replacement : nil, partials )
601
1020
  retired << _module
602
1021
  end
603
1022
  end
604
1023
 
605
- remove_matching_includes( includes: includes, modules: retired )
1024
+ remove_matching_includes( includes: includes, modules: retired, partials: partials )
1025
+ end
1026
+
1027
+ # Whether a list names a partialized module. The module being generated is named by the
1028
+ # place a source that never includes its own header holds for it, too.
1029
+ def _named_in?(includes, _module, name, partials)
1030
+ return includes.any? { |include| (_module == name) ? _own_header?( include, name, partials ) : _names_module?( include, _module, partials ) }
1031
+ end
1032
+
1033
+ # An interface header declares what its module's real header declared, which the includes
1034
+ # after it may rely on. So it takes that header's place. The module being generated has
1035
+ # already had its header replaced, so its interface header follows the replacement. With
1036
+ # neither in the list, it goes last.
1037
+ def _place_interface_header(includes, _module, replacement, partials)
1038
+ interface = UserInclude.new( @file_path_utils.form_partial_interface_header_filename(_module) )
1039
+
1040
+ index = includes.index { |include| _names_module?( include, _module, partials ) }
1041
+ return includes[index] = interface if index
1042
+
1043
+ index = replacement && includes.index { |include| include.filename == File.basename( replacement ) }
1044
+ return includes.insert( index + 1, interface ) if index
1045
+
1046
+ includes << interface
606
1047
  end
607
1048
 
608
1049
  # Swaps `name`'s own header include for `replacement` at that same list position,
@@ -622,40 +1063,78 @@ class Partializer
622
1063
  # depends on that came before it in the source's own working include order (e.g. a
623
1064
  # shared Types.h), while still landing ahead of anything transitively re-reaching the
624
1065
  # real header afterward.
625
- def splice_in_replacement(includes:, name:, replacement:)
626
- return remove_matching_includes(includes: includes, modules: [name]) unless replacement
627
-
628
- replaced = false
629
- spliced = includes.map do |include|
630
- if !replaced && module_basename( name ) == include.filename.ext().downcase()
631
- replaced = true
632
- UserInclude.new(replacement)
633
- else
634
- include
635
- end
1066
+ def splice_in_replacement(includes:, name:, replacement:, partials: {})
1067
+ spliced = includes.dup
1068
+ index = spliced.index { |include| _own_header?( include, name, partials ) }
1069
+
1070
+ # Every remap holds a place for the module's own header (see OWN_HEADER_PLACE). A list
1071
+ # without one has no position to preserve, so the replacement goes last.
1072
+ if replacement
1073
+ index ? (spliced[index] = UserInclude.new( replacement )) : (spliced << UserInclude.new( replacement ))
636
1074
  end
637
- # This module's own header wasn't in the includes list at all -- no original
638
- # position to preserve, so fall back to appending.
639
- spliced << UserInclude.new(replacement) unless replaced
640
1075
 
641
1076
  # A duplicate/case-variant entry beyond the first match (e.g. both 'module.h' and
642
- # 'MODULE.H' present) has no meaningful position of its own to preserve -- drop it
643
- # like remove_matching_includes always has.
644
- spliced = remove_matching_includes(includes: spliced, modules: [name])
645
- spliced
1077
+ # 'MODULE.H' present) has no meaningful position of its own to preserve -- drop it too.
1078
+ return spliced.reject { |include| _own_header?( include, name, partials ) }
646
1079
  end
647
1080
 
648
- # Remove includes that match the given module names (case-insensitive)
649
- # Returns a new array with matching includes removed
650
- def remove_matching_includes(includes:, modules:)
651
- normalized_modules = modules.map { |_module| module_basename( _module ) }
1081
+ # The module's own header, or the place a source that never includes it holds for it
1082
+ def _own_header?(include, name, partials)
1083
+ return (include.equal?( OWN_HEADER_PLACE ) or _names_module?( include, name, partials ))
1084
+ end
652
1085
 
653
- # Filter out includes (minus extension) that match any module name
1086
+ # Remove includes that name any of the given modules (see _names_module?)
1087
+ # Returns a new array with matching includes removed
1088
+ def remove_matching_includes(includes:, modules:, partials: {})
654
1089
  return includes.reject do |include|
655
- normalized_modules.include?(include.filename.ext().downcase())
1090
+ modules.any? { |_module| _names_module?( include, _module, partials ) }
656
1091
  end
657
1092
  end
658
1093
 
1094
+ # Whether `include` names partialized module `_module`: its filename, less extension and in
1095
+ # any case, is the module's basename.
1096
+ #
1097
+ # A module named without a directory is named by its basename alone, as its own #include
1098
+ # spells it, short of a header a same-named module named by directory claims. Naming a
1099
+ # module by directory says its basename isn't enough, since another header, partialized or
1100
+ # not, may share it, so that module's header path decides (see _same_header_path?). One
1101
+ # whose header path is unknown is named by basename alone.
1102
+ def _names_module?(include, _module, partials)
1103
+ return false unless include.filename.ext().downcase() == module_basename( _module )
1104
+ return !_claimed_by_directory?( include, _module, partials ) if File.dirname( _module ) == '.'
1105
+
1106
+ header = partials.dig( _module )&.header&.filepath
1107
+ return true if header.nil? or _unanchored?( include )
1108
+
1109
+ return _same_header_path?( include.filepath, header )
1110
+ end
1111
+
1112
+ # Fallback anchors a `..` #include to its file's own directory. One naming no file there was
1113
+ # found elsewhere through a search path, so its path says nothing and its filename decides.
1114
+ def _unanchored?(include)
1115
+ return (include.directory_relative? and !@file_wrapper.exist?( include.filepath ))
1116
+ end
1117
+
1118
+ # Whether a module sharing `_module`'s basename, named by directory, claims `include` by its header's path
1119
+ def _claimed_by_directory?(include, _module, partials)
1120
+ headers = partials.filter_map do |other, config|
1121
+ config&.header&.filepath if File.dirname( other ) != '.' and module_basename( other ) == module_basename( _module )
1122
+ end
1123
+
1124
+ return headers.any? { |header| _same_header_path?( include.filepath, header ) }
1125
+ end
1126
+
1127
+ # Whether an include's path ends the way a header's path does, in any case, as a
1128
+ # case-insensitive filesystem reaches the header by either. A bare #include, as fallback
1129
+ # preprocessing leaves one, ends any such path. An absolute path and a relative one, such as
1130
+ # `../shared/x.h` from a project's paths, are compared as the absolute paths they name.
1131
+ def _same_header_path?(include_path, header_path)
1132
+ return true if PathMatcher.correspond?( include_path.downcase(), header_path.downcase() )
1133
+ return false unless PathMatcher.absolute?( include_path ) or PathMatcher.absolute?( header_path )
1134
+
1135
+ return ProjectPaths.absolute( include_path ).downcase() == ProjectPaths.absolute( header_path ).downcase()
1136
+ end
1137
+
659
1138
  # A module name reduced to what an #include actually carries. An #include names a
660
1139
  # file, not a module, so a module named by directory still has to be recognized by
661
1140
  # the basename its own header include spells out.