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
@@ -138,11 +138,22 @@ describe PartializerUtils do
138
138
  source_filepath: 'src/code/myfile.c',
139
139
  line_num: 34,
140
140
  decorators: ['__pragma__', 'static'],
141
+ hidden_decorators: [],
141
142
  code_block: "__pragma__ static void testFunc(int x) {\n return x * 2;\n}"
142
143
  )
143
144
  end
144
145
 
145
146
  context "when output_type is :impl" do
147
+ # A selected function's callers rely on it never returning
148
+ it "keeps _Noreturn on a testable function" do
149
+ func = double('function', name: 'die', decorators: ['static'], hidden_decorators: [], source_filepath: 'src/m.c', line_num: 3,
150
+ code_block: "static _Noreturn void die(void) { for (;;) {} }")
151
+
152
+ result = @utils.transform_function(func, '_Noreturn void die(void)', :impl)
153
+
154
+ expect(result.code_block).to eq("_Noreturn void die(void) { for (;;) {} }")
155
+ end
156
+
146
157
  it "returns a FunctionDefinition with source filepath, line number, signature, and code block" do
147
158
  signature = 'void testFunc(int x)'
148
159
 
@@ -167,6 +178,27 @@ describe PartializerUtils do
167
178
  expect(result).not_to respond_to(:code_block)
168
179
  end
169
180
 
181
+ # A mock always returns, so a mock declared never to return would contradict itself
182
+ it "drops _Noreturn from a mockable signature" do
183
+ result = @utils.transform_function(mock_func, '_Noreturn void testFunc(int x);', :interface)
184
+
185
+ expect(result.signature).to eq('void testFunc(int x)')
186
+ end
187
+
188
+ it "drops the GNU and C23 noreturn attributes from a mockable signature" do
189
+ gnu = @utils.transform_function(mock_func, '__attribute__((noreturn)) void testFunc(int x);', :interface)
190
+ c23 = @utils.transform_function(mock_func, '[[noreturn]] void testFunc(int x);', :interface)
191
+
192
+ expect(gnu.signature).to eq('void testFunc(int x)')
193
+ expect(c23.signature).to eq('void testFunc(int x)')
194
+ end
195
+
196
+ it "keeps an attribute that says something else" do
197
+ result = @utils.transform_function(mock_func, '__attribute__((warn_unused_result)) int testFunc(int x);', :interface)
198
+
199
+ expect(result.signature).to eq('__attribute__((warn_unused_result)) int testFunc(int x)')
200
+ end
201
+
170
202
  it "strips a trailing semicolon from a declaration-sourced signature" do
171
203
  # CFunctionDeclaration#signature_stripped always carries its own trailing
172
204
  # semicolon (it's a bare prototype); CFunctionDefinition#signature_stripped never
@@ -190,268 +222,269 @@ describe PartializerUtils do
190
222
  end
191
223
  end
192
224
 
193
- # Test private method for code block manipulation used by `transform_function()`
194
- context "#extract_code_block" do
195
- it "strips a single inline decorator and returns 0 leading newlines" do
196
- code_block = "static void foo(void) {\n return;\n}"
197
- result, newlines = @utils.send(:extract_code_block, code_block, ['static'])
225
+ # A macro the module's header defines, such as `#define PRIVATE static`, hides a decorator the
226
+ # written head can't be stripped of. The implementation header declares the expanded,
227
+ # stripped signature, so the definition takes the same one.
228
+ context "#transform_function with decorators a macro hides" do
229
+ def definition(code_block, hidden:, line_num: 10, name: 'helper', decorators: hidden)
230
+ CExtractorTypes::CFunctionDefinition.new(
231
+ name: name, code_block: code_block, line_num: line_num, decorators: decorators, hidden_decorators: hidden
232
+ )
233
+ end
198
234
 
199
- expect(result).to eq("void foo(void) {\n return;\n}")
200
- expect(newlines).to eq(0)
235
+ def transform(func, signature)
236
+ @utils.transform_function( func, signature, :impl )
201
237
  end
202
238
 
203
- it "strips multiple inline decorators and returns 0 leading newlines" do
204
- code_block = "__pragma__ static void foo(void) { return; }"
205
- result, newlines = @utils.send(:extract_code_block, code_block, ['__pragma__', 'static'])
239
+ it "writes the head from the signature and keeps the body as written" do
240
+ result = transform( definition( "PRIVATE int helper(void) {\n return 41;\n}", hidden: ['static'] ), 'int helper(void)' )
206
241
 
207
- expect(result).to eq("void foo(void) { return; }")
208
- expect(newlines).to eq(0)
242
+ expect( result.code_block ).to eq( "int helper(void) {\n return 41;\n}" )
243
+ expect( result.line_num ).to eq( 10 )
209
244
  end
210
245
 
211
- it "handles empty decorators array — no stripping, 0 leading newlines" do
212
- code_block = "void foo(void) { return; }"
213
- result, newlines = @utils.send(:extract_code_block, code_block, [])
246
+ it "rewrites a head a macro makes static and inline" do
247
+ result = transform( definition( "STATICINLINE int twice(int v) { return v * 2; }", hidden: ['static', 'inline'], name: 'twice' ), 'int twice(int v)' )
214
248
 
215
- expect(result).to eq(code_block)
216
- expect(newlines).to eq(0)
249
+ expect( result.code_block ).to eq( "int twice(int v) { return v * 2; }" )
217
250
  end
218
251
 
219
- it "counts 1 leading newline when decorator occupies its own line" do
220
- code_block = "static\nint foo(void) { return 0; }"
221
- result, newlines = @utils.send(:extract_code_block, code_block, ['static'])
252
+ # A macro that respells a keyword the head already names, as `#define inline __inline` does
253
+ it "rewrites a head whose written decorator a macro turns into another" do
254
+ func = definition( "inline int tick(void) { return 1; }", hidden: ['__inline'], decorators: ['inline'], name: 'tick' )
255
+ result = transform( func, 'int tick(void)' )
222
256
 
223
- expect(result).to eq("int foo(void) { return 0; }")
224
- expect(newlines).to eq(1)
257
+ expect( result.code_block ).to eq( "int tick(void) { return 1; }" )
225
258
  end
226
259
 
227
- it "counts 2 leading newlines when two decorators each occupy their own line" do
228
- code_block = "static\ninline\nint foo(void) { return 0; }"
229
- result, newlines = @utils.send(:extract_code_block, code_block, ['static', 'inline'])
260
+ # Coverage tools place a function at its name's line, and every body line keeps its own
261
+ it "keeps the name's line and every body line of a head spread over several lines" do
262
+ func = definition( "PRIVATE int\nhelper(int a,\n int b)\n{\n return a + b;\n}", hidden: ['static'] )
263
+ result = transform( func, "int helper(int a,\n int b)" )
230
264
 
231
- expect(result).to eq("int foo(void) { return 0; }")
232
- expect(newlines).to eq(2)
265
+ expect( result.code_block ).to eq( "int helper(int a, int b)\n\n{\n return a + b;\n}" )
266
+ expect( result.line_num ).to eq( 11 )
233
267
  end
234
268
 
235
- it "preserves body indentation and internal newlines" do
236
- code_block = "static void indented(void) {\n int x = 1;\n return x;\n}"
237
- result, _ = @utils.send(:extract_code_block, code_block, ['static'])
269
+ it "keeps what follows the parameter list as written" do
270
+ result = transform( definition( "PRIVATE int helper(void) /* note */ { return 1; }", hidden: ['static'] ), 'int helper(void)' )
238
271
 
239
- expect(result).to include(" int x = 1;")
240
- expect(result.count("\n")).to eq(3)
272
+ expect( result.code_block ).to eq( "int helper(void) /* note */ { return 1; }" )
241
273
  end
242
274
 
243
- it "handles multi-line parameter list without relying on signature substring match" do
244
- code_block = "static int multiline(\n int a,\n int b) {\n return a + b;\n}"
245
- result, newlines = @utils.send(:extract_code_block, code_block, ['static'])
275
+ # Fallback keeps comments, so a ';' in one after the list says nothing of K&R
276
+ it "rewrites a head whose comment after the list holds a ';'" do
277
+ result = transform( definition( "PRIVATE int helper(void) /* adds; */ { return 1; }", hidden: ['static'] ), 'int helper(void)' )
246
278
 
247
- expect(result).to eq("int multiline(\n int a,\n int b) {\n return a + b;\n}")
248
- expect(result).not_to include("static")
249
- expect(newlines).to eq(0)
279
+ expect( result.code_block ).to eq( "int helper(void) /* adds; */ { return 1; }" )
250
280
  end
251
281
 
252
- it "is a no-op when decorator is not present in code_block" do
253
- code_block = "void foo(void) { }"
254
- result, newlines = @utils.send(:extract_code_block, code_block, ['extern'])
282
+ # Fallback keeps comments, so the name can sit apart from its list. The body's recursive
283
+ # call must not pass for the name.
284
+ it "finds the name in the head alone, past a comment ahead of the list" do
285
+ code = "PRIVATE int helper /* c */ (int a) { return a ? helper( a - 1 ) : 0; }"
286
+ result = transform( definition( code, hidden: ['static'] ), 'int helper (int a)' )
255
287
 
256
- expect(result).to eq(code_block)
257
- expect(newlines).to eq(0)
288
+ expect( result.code_block ).to eq( "int helper (int a) { return a ? helper( a - 1 ) : 0; }" )
258
289
  end
259
290
 
260
- it "removes only the first occurrence of a decorator that appears in the body too" do
261
- # 'static' in the body (e.g., a local static var) must not be touched
262
- code_block = "static int foo(void) {\n static int x = 0;\n return x;\n}"
263
- result, _ = @utils.send(:extract_code_block, code_block, ['static'])
291
+ # A multibyte character ahead of the name counts as one character but several bytes
292
+ it "keeps the body intact behind a multibyte character ahead of the name" do
293
+ code = "__attribute__((section(\"région\"))) PRIVATE int\nhelper(void)\n{ return 1; }"
294
+ result = transform( definition( code, hidden: ['static'] ), '__attribute__((section("région"))) int helper(void)' )
264
295
 
265
- expect(result).to start_with("int foo(void)")
266
- expect(result).to include("static int x = 0;")
296
+ expect( result.code_block ).to eq( "__attribute__((section(\"région\"))) int helper(void)\n{ return 1; }" )
297
+ expect( result.line_num ).to eq( 11 )
267
298
  end
268
299
 
269
- it "strips multiple decorators and counts newlines for inline+multiline mix" do
270
- code_block = "extern\nstatic int bar(int x) { return x; }"
271
- result, newlines = @utils.send(:extract_code_block, code_block, ['extern', 'static'])
300
+ # A K&R definition declares its parameters between the list and the body
301
+ it "strips as written when a ';' follows the parameter list" do
302
+ code = "PRIVATE int helper(a)\n int a;\n{ return a; }"
303
+ result = transform( definition( code, hidden: ['static'] ), 'int helper(a)' )
272
304
 
273
- expect(result).to eq("int bar(int x) { return x; }")
274
- expect(newlines).to eq(1)
305
+ expect( result.code_block ).to eq( code )
275
306
  end
276
- end
277
307
 
278
- context "#adjust_line_num" do
279
- it "returns nil when line_num is nil" do
280
- expect(@utils.send(:adjust_line_num, nil, 3)).to be_nil
308
+ # A compound literal's brace inside the list hides where the body opens
309
+ it "strips as written when a brace sits inside the parameter list" do
310
+ code = "PRIVATE int helper(int n, int a[(int){3}]) { return n; }"
311
+ result = transform( definition( code, hidden: ['static'] ), 'int helper(int n, int a[(int){3}])' )
312
+
313
+ expect( result.code_block ).to eq( code )
281
314
  end
282
315
 
283
- it "returns line_num unchanged when stripped_newlines is 0" do
284
- expect(@utils.send(:adjust_line_num, 10, 0)).to eq(10)
316
+ # A `_Pragma` in the head expands to a directive, which can't share a line with the head
317
+ it "strips as written when the signature holds a directive" do
318
+ code = "PRIVATE NOUNUSED int helper(int a) { return 1; }"
319
+ signature = "\n#pragma GCC diagnostic ignored \"-Wunused-parameter\"\n int helper(int a)"
320
+ result = transform( definition( code, hidden: ['static'] ), signature )
321
+
322
+ expect( result.code_block ).to eq( code )
285
323
  end
286
324
 
287
- it "adds stripped_newlines to line_num" do
288
- expect(@utils.send(:adjust_line_num, 5, 2)).to eq(7)
325
+ it "strips as written when nothing is hidden" do
326
+ result = transform( definition( "static int helper(void) { return 1; }", hidden: [], decorators: ['static'] ), 'int helper(void)' )
327
+
328
+ expect( result.code_block ).to eq( "int helper(void) { return 1; }" )
289
329
  end
290
330
 
291
- it "handles a single stripped newline" do
292
- expect(@utils.send(:adjust_line_num, 1, 1)).to eq(2)
331
+ it "keeps line breaks the head's CRLF endings hold" do
332
+ result = transform( definition( "PRIVATE int\r\nhelper(void)\r\n{\r\n return 1;\r\n}", hidden: ['static'] ), 'int helper(void)' )
333
+
334
+ expect( result.code_block ).to eq( "int helper(void)\r\n{\r\n return 1;\r\n}" )
335
+ expect( result.line_num ).to eq( 11 )
293
336
  end
294
337
  end
295
338
 
296
- context "#replace_declaration_with_noop" do
297
- it "replaces first occurrence of declaration with noop containing placeholder in comment" do
298
- text = " static int count;\n count = 0;"
299
- result = @utils.replace_declaration_with_noop(text, "static int count", "MYPLACEHOLDER")
339
+ # Test private method for code block manipulation used by `transform_function()`
340
+ context "#extract_code_block" do
341
+ it "strips a decorator on the signature's own line and counts no newlines" do
342
+ code_block = "static void foo(void) {\n return;\n}"
343
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static'], 'foo')
300
344
 
301
- expect(result).to include("(void)0;")
302
- expect(result).to include("`MYPLACEHOLDER`")
303
- expect(result).not_to start_with(" static int count;")
345
+ expect(result).to eq("void foo(void) {\n return;\n}")
346
+ expect(newlines).to eq(0)
304
347
  end
305
348
 
306
- it "only replaces the first occurrence (sub, not gsub)" do
307
- text = "static int x; static int x;"
308
- result = @utils.replace_declaration_with_noop(text, "static int x", "PH")
349
+ it "strips several decorators on the signature's own line and counts no newlines" do
350
+ code_block = "static inline void foo(void) { return; }"
351
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static', 'inline'], 'foo')
309
352
 
310
- expect(result.scan("(void)0;").length).to eq(1)
311
- # Second occurrence is preserved
312
- expect(result).to include("static int x")
353
+ expect(result).to eq("void foo(void) { return; }")
354
+ expect(newlines).to eq(0)
313
355
  end
314
356
 
315
- it "works when declaration appears mid-string with surrounding context" do
316
- text = "/* leading comment */\n static int val;\n val = 5;"
317
- result = @utils.replace_declaration_with_noop(text, "static int val", "TOKEN")
357
+ it "handles empty decorators array — no stripping, 0 leading newlines" do
358
+ code_block = "void foo(void) { return; }"
359
+ result, newlines = @utils.send(:extract_code_block, code_block, [], 'foo')
318
360
 
319
- expect(result).to include("(void)0;")
320
- expect(result).to include("/* leading comment */")
361
+ expect(result).to eq(code_block)
362
+ expect(newlines).to eq(0)
321
363
  end
322
364
 
323
- it "returns unchanged text when declaration is not found" do
324
- text = "int x = 0;"
325
- result = @utils.replace_declaration_with_noop(text, "static int y", "PH")
365
+ it "counts 1 leading newline when decorator occupies its own line" do
366
+ code_block = "static\nint foo(void) { return 0; }"
367
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static'], 'foo')
326
368
 
327
- expect(result).to eq(text)
369
+ expect(result).to eq("int foo(void) { return 0; }")
370
+ expect(newlines).to eq(1)
328
371
  end
329
372
 
330
- it "handles declaration text that ends with a semicolon" do
331
- text = "static int count;"
332
- result = @utils.replace_declaration_with_noop(text, "static int count;", "PH")
373
+ it "counts 2 leading newlines when two decorators each occupy their own line" do
374
+ code_block = "static\ninline\nint foo(void) { return 0; }"
375
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static', 'inline'], 'foo')
333
376
 
334
- expect(result).to include("(void)0;")
377
+ expect(result).to eq("int foo(void) { return 0; }")
378
+ expect(newlines).to eq(2)
335
379
  end
336
- end
337
380
 
338
- context "#replace_compound_declaration_with_noops" do
339
- it "produces a single noop with comment for count=1" do
340
- text = " static int count;\n count = 0;"
341
- result = @utils.replace_compound_declaration_with_noops(text, "static int count", "PH_COUNT", 1)
381
+ it "preserves body indentation and internal newlines" do
382
+ code_block = "static void indented(void) {\n int x = 1;\n return x;\n}"
383
+ result, _ = @utils.send(:extract_code_block, code_block, ['static'], 'indented')
342
384
 
343
- expect(result.scan("(void)0;").length).to eq(1)
344
- expect(result).to include("`PH_COUNT`")
385
+ expect(result).to include(" int x = 1;")
386
+ expect(result.count("\n")).to eq(3)
345
387
  end
346
388
 
347
- it "produces two noops for count=2 with single comment containing placeholder" do
348
- text = "void f(void) { static int a, b; a = 0; b = 1; }"
349
- result = @utils.replace_compound_declaration_with_noops(text, "static int a, b;", "PH_A", 2)
389
+ it "handles multi-line parameter list without relying on signature substring match" do
390
+ code_block = "static int multiline(\n int a,\n int b) {\n return a + b;\n}"
391
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static'], 'multiline')
350
392
 
351
- expect(result.scan("(void)0;").length).to eq(2)
352
- expect(result).to include("`PH_A`")
353
- # Only one comment
354
- expect(result.scan("/*").length).to eq(1)
393
+ expect(result).to eq("int multiline(\n int a,\n int b) {\n return a + b;\n}")
394
+ expect(result).not_to include("static")
395
+ expect(newlines).to eq(0)
355
396
  end
356
397
 
357
- it "produces three noops for count=3 with a single comment" do
358
- text = "static int x, y, z;"
359
- result = @utils.replace_compound_declaration_with_noops(text, "static int x, y, z;", "PH_X", 3)
398
+ it "is a no-op when decorator is not present in code_block" do
399
+ code_block = "void foo(void) { }"
400
+ result, newlines = @utils.send(:extract_code_block, code_block, ['extern'], 'foo')
360
401
 
361
- expect(result.scan("(void)0;").length).to eq(3)
362
- expect(result).to include("`PH_X`")
363
- expect(result.scan("/*").length).to eq(1)
402
+ expect(result).to eq(code_block)
403
+ expect(newlines).to eq(0)
364
404
  end
365
405
 
366
- it "replaces only the first occurrence of the declaration (sub, not gsub)" do
367
- text = "static int a, b; static int a, b;"
368
- result = @utils.replace_compound_declaration_with_noops(text, "static int a, b;", "PH_A", 2)
406
+ it "leaves a decorator word in the body alone" do
407
+ # 'static' in the body (e.g., a local static var) must not be touched
408
+ code_block = "static int foo(void) {\n static int x = 0;\n return x;\n}"
409
+ result, _ = @utils.send(:extract_code_block, code_block, ['static'], 'foo')
369
410
 
370
- expect(result.scan("(void)0;").length).to eq(2) # two noops from one replacement
371
- expect(result).to include("static int a, b;") # second occurrence unchanged
411
+ expect(result).to start_with("int foo(void)")
412
+ expect(result).to include("static int x = 0;")
372
413
  end
373
414
 
374
- it "returns unchanged text when declaration is not found" do
375
- text = "int x = 0;"
376
- result = @utils.replace_compound_declaration_with_noops(text, "static int y, z;", "PH_Y", 2)
415
+ # Only the text before the name is searched, so a body's own static stays when a macro
416
+ # hides the signature's
417
+ it "leaves a body's decorator word alone when the signature spells its decorator as a macro" do
418
+ code_block = "PRIVATE int hidden(void) { static int n; return n; }"
419
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static'], 'hidden')
377
420
 
378
- expect(result).to eq(text)
421
+ expect(result).to eq(code_block)
422
+ expect(newlines).to eq(0)
379
423
  end
380
424
 
381
- it "placeholder token appears verbatim in the single comment" do
382
- text = "static int val1, val2;"
383
- result = @utils.replace_compound_declaration_with_noops(text, "static int val1, val2;", "TOKEN_1", 2)
425
+ it "strips multiple decorators and counts newlines for inline+multiline mix" do
426
+ code_block = "extern\nstatic int bar(int x) { return x; }"
427
+ result, newlines = @utils.send(:extract_code_block, code_block, ['extern', 'static'], 'bar')
384
428
 
385
- expect(result).to include("`TOKEN_1`")
386
- expect(result).not_to include("static int val1, val2;")
429
+ expect(result).to eq("int bar(int x) { return x; }")
430
+ expect(newlines).to eq(1)
387
431
  end
388
- end
389
432
 
390
- context "#rename_c_identifier" do
391
- it "replaces a single token-bounded occurrence" do
392
- result = @utils.rename_c_identifier("count = 0;", "count", "partial_foo_count")
393
- expect(result).to eq("partial_foo_count = 0;")
394
- end
433
+ # Only storage-class and inline keywords are stripped. A qualifier belongs to the return type.
434
+ it "keeps a const return type when stripping static" do
435
+ code_block = "static const char *name(void) { return \"n\"; }"
436
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static'], 'name')
395
437
 
396
- it "replaces all occurrences throughout the text (gsub)" do
397
- result = @utils.rename_c_identifier("count = count + 1;", "count", "partial_foo_count")
398
- expect(result).to eq("partial_foo_count = partial_foo_count + 1;")
438
+ expect(result).to eq("const char *name(void) { return \"n\"; }")
439
+ expect(newlines).to eq(0)
399
440
  end
400
441
 
401
- it "does not replace left-bounded substrings" do
402
- result = @utils.rename_c_identifier("recount = 0;", "count", "partial_foo_count")
403
- expect(result).to eq("recount = 0;")
404
- end
442
+ it "strips a storage class written after a qualifier" do
443
+ code_block = "const static int *table(void) { return 0; }"
444
+ result, _ = @utils.send(:extract_code_block, code_block, ['static'], 'table')
405
445
 
406
- it "does not replace right-bounded substrings" do
407
- result = @utils.rename_c_identifier("count_down = 0;", "count", "partial_foo_count")
408
- expect(result).to eq("count_down = 0;")
446
+ expect(result).to eq("const int *table(void) { return 0; }")
409
447
  end
410
448
 
411
- it "does not replace interior substrings" do
412
- result = @utils.rename_c_identifier("recount_down = 0;", "count", "partial_foo_count")
413
- expect(result).to eq("recount_down = 0;")
414
- end
449
+ # A decorator word inside the name or body is not a decorator
450
+ it "leaves a decorator word that appears inside the function name" do
451
+ code_block = "PRIVATE int is_static(void) { return 1; }"
452
+ result, _ = @utils.send(:extract_code_block, code_block, ['static'], 'is_static')
415
453
 
416
- it "replaces identifier in parentheses context" do
417
- result = @utils.rename_c_identifier("foo(count)", "count", "partial_foo_count")
418
- expect(result).to eq("foo(partial_foo_count)")
454
+ expect(result).to eq(code_block)
419
455
  end
420
456
 
421
- it "replaces pointer dereference context" do
422
- result = @utils.rename_c_identifier("*count = 0;", "count", "partial_foo_count")
423
- expect(result).to eq("*partial_foo_count = 0;")
424
- end
457
+ it "strips the decorator itself when an attribute string ahead of it holds the same word" do
458
+ code_block = '__attribute__((section(".text.static"))) static int g(void) { return 0; }'
459
+ result, _ = @utils.send(:extract_code_block, code_block, ['static'], 'g')
425
460
 
426
- it "replaces array subscript context" do
427
- result = @utils.rename_c_identifier("count[0]", "count", "partial_foo_count")
428
- expect(result).to eq("partial_foo_count[0]")
461
+ expect(result).to eq('__attribute__((section(".text.static"))) int g(void) { return 0; }')
429
462
  end
430
463
 
431
- it "replaces comparison context without spaces" do
432
- result = @utils.rename_c_identifier("count==5", "count", "partial_foo_count")
433
- expect(result).to eq("partial_foo_count==5")
464
+ it "leaves the text alone when a decorator from the expanded copy is absent" do
465
+ code_block = "PRIVATE int hidden(void) { return 0; }"
466
+ result, newlines = @utils.send(:extract_code_block, code_block, ['static'], 'hidden')
467
+
468
+ expect(result).to eq(code_block)
469
+ expect(newlines).to eq(0)
434
470
  end
471
+ end
435
472
 
436
- it "replaces compound assignment without spaces" do
437
- result = @utils.rename_c_identifier("count+=1", "count", "partial_foo_count")
438
- expect(result).to eq("partial_foo_count+=1")
473
+ context "#adjust_line_num" do
474
+ it "returns nil when line_num is nil" do
475
+ expect(@utils.send(:adjust_line_num, nil, 3)).to be_nil
439
476
  end
440
477
 
441
- it "replaces address-of context" do
442
- result = @utils.rename_c_identifier("&count", "count", "partial_foo_count")
443
- expect(result).to eq("&partial_foo_count")
478
+ it "returns line_num unchanged when stripped_newlines is 0" do
479
+ expect(@utils.send(:adjust_line_num, 10, 0)).to eq(10)
444
480
  end
445
481
 
446
- it "returns empty string unchanged" do
447
- result = @utils.rename_c_identifier("", "count", "partial_foo_count")
448
- expect(result).to eq("")
482
+ it "adds stripped_newlines to line_num" do
483
+ expect(@utils.send(:adjust_line_num, 5, 2)).to eq(7)
449
484
  end
450
485
 
451
- it "returns unchanged text when old_name not present" do
452
- text = "value = 5;"
453
- result = @utils.rename_c_identifier(text, "count", "partial_foo_count")
454
- expect(result).to eq(text)
486
+ it "handles a single stripped newline" do
487
+ expect(@utils.send(:adjust_line_num, 1, 1)).to eq(2)
455
488
  end
456
489
  end
457
490
 
@@ -479,88 +512,92 @@ describe PartializerUtils do
479
512
  end
480
513
  end
481
514
 
482
- context "#locate_function_in_source" do
483
- it "returns the line number when function is found" do
484
- expect(@code_finder).to receive(:find_in_c_file)
485
- .with('/path/to/file.c', 'void foo(void) {}')
486
- .and_return(42)
515
+ context "#locate_functions_in_source" do
516
+ it "returns each function's line from one search of the source" do
517
+ expect(@code_finder).to receive(:find_all_in_c_file)
518
+ .with('/path/to/file.c', ['void foo(void) {}', 'void missing(void) {}']).once
519
+ .and_return([42, nil])
520
+
521
+ result = @utils.locate_functions_in_source(code_blocks: ['void foo(void) {}', 'void missing(void) {}'], filepath: '/path/to/file.c')
522
+ expect(result).to eq([42, nil])
523
+ end
524
+ end
525
+
526
+ context "#locate_declarations_in_text" do
527
+ it "returns the line where each declaration appears in the text, in order" do
528
+ text = "int a;\nint tick(void);\nint tock(void);\n"
529
+ expect(@code_finder).to receive(:find_in_c_string).with(text, 'int tock(void);').and_return(3)
530
+ expect(@code_finder).to receive(:find_in_c_string).with(text, 'int tick(void);').and_return(2)
531
+
532
+ expect(@utils.locate_declarations_in_text(signatures: ['int tock(void);', 'int tick(void);'], text: text)).to eq([3, 2])
533
+ end
534
+
535
+ it "returns nil for a declaration not in the text" do
536
+ allow(@code_finder).to receive(:find_in_c_string).and_return(nil)
537
+
538
+ expect(@utils.locate_declarations_in_text(signatures: ['int tick(void);'], text: '')).to eq([nil])
539
+ end
540
+
541
+ # Blanking costs a pass over the whole file, so one blanked copy serves every declaration
542
+ it "searches every declaration in one blanked copy of the text" do
543
+ searched = []
544
+ allow(@code_finder).to receive(:find_in_c_string) { |text, _signature| searched << text; nil }
545
+
546
+ @utils.locate_declarations_in_text(signatures: ['int tick(void);', 'int tock(void);'], text: "/* c */\nint tick(void);\n")
487
547
 
488
- result = @utils.locate_function_in_source(code_block: 'void foo(void) {}', filepath: '/path/to/file.c')
489
- expect(result).to eq(42)
548
+ expect(searched.size).to eq(2)
549
+ expect(searched.map(&:object_id).uniq.size).to eq(1)
490
550
  end
491
551
 
492
- it "returns nil when function is not found" do
493
- allow(@code_finder).to receive(:find_in_c_file).and_return(nil)
552
+ # A commented-out copy of the declaration would otherwise be found first
553
+ it "searches the text with its comments blanked and its lines kept" do
554
+ line_comment = '// int tick(void);'
555
+ block_comment = '/* int tick(void); */'
556
+ expect(@code_finder).to receive(:find_in_c_string)
557
+ .with("#{' ' * line_comment.length}\n#{' ' * block_comment.length}\nint tick(void);\n", 'int tick(void);')
558
+ .and_return(3)
494
559
 
495
- result = @utils.locate_function_in_source(code_block: 'void missing(void) {}', filepath: '/path/to/file.c')
496
- expect(result).to be_nil
560
+ @utils.locate_declarations_in_text(signatures: ['int tick(void);'], text: "#{line_comment}\n#{block_comment}\nint tick(void);\n")
497
561
  end
498
562
 
499
- it "forwards exact arguments to code_finder" do
500
- expect(@code_finder).to receive(:find_in_c_file)
501
- .with('/exact/path.c', 'exact code block')
502
- .and_return(nil)
563
+ it "keeps a comment marker inside a string literal" do
564
+ text = "int open(const char *url) __attribute__((deprecated(\"see http://x\")));\n"
565
+ expect(@code_finder).to receive(:find_in_c_string).with(text, 'int open(void);').and_return(nil)
503
566
 
504
- @utils.locate_function_in_source(code_block: 'exact code block', filepath: '/exact/path.c')
567
+ @utils.locate_declarations_in_text(signatures: ['int open(void);'], text: text)
505
568
  end
506
569
  end
507
570
 
508
- context "#locate_function_via_preprocessed" do
571
+ context "#locate_functions_via_preprocessed" do
509
572
  let(:filepath) { '/path/to/source.c' }
510
573
  let(:preprocessed_filepath) { '/build/preproc/source.i' }
511
- let(:code_block) { 'void foo(void) {}' }
512
-
513
- it "returns line number from preprocessed file when found there" do
514
- expect(@code_finder).to receive(:find_in_preprocessed_file)
515
- .with(preprocessed_filepath, code_block)
516
- .and_return(10)
517
- expect(@code_finder).not_to receive(:find_in_c_file)
518
-
519
- result = @utils.locate_function_via_preprocessed(
520
- code_block: code_block,
521
- filepath: filepath,
522
- preprocessed_filepath: preprocessed_filepath
523
- )
524
- expect(result).to eq(10)
525
- end
574
+ let(:blocks) { ['void foo(void) {}', 'void bar(void) {}', 'void baz(void) {}'] }
526
575
 
527
- it "falls back to C source when not found in preprocessed file" do
528
- allow(@code_finder).to receive(:find_in_preprocessed_file).and_return(nil)
529
- expect(@code_finder).to receive(:find_in_c_file).with(filepath, code_block).and_return(25)
576
+ it "returns each function's line from the preprocessed file when found there" do
577
+ expect(@code_finder).to receive(:find_all_in_preprocessed_file).with(preprocessed_filepath, blocks).once.and_return([10, 20, 30])
578
+ expect(@code_finder).not_to receive(:find_all_in_c_file)
530
579
 
531
- result = @utils.locate_function_via_preprocessed(
532
- code_block: code_block,
533
- filepath: filepath,
534
- preprocessed_filepath: preprocessed_filepath
535
- )
536
- expect(result).to eq(25)
580
+ result = @utils.locate_functions_via_preprocessed(code_blocks: blocks, filepath: filepath, preprocessed_filepath: preprocessed_filepath)
581
+ expect(result).to eq([10, 20, 30])
537
582
  end
538
583
 
539
- it "returns nil when found in neither preprocessed nor C source" do
540
- allow(@code_finder).to receive(:find_in_preprocessed_file).and_return(nil)
541
- allow(@code_finder).to receive(:find_in_c_file).and_return(nil)
584
+ # The source is searched once, and only for what the preprocessed file lacks
585
+ it "falls back to the C source for just the functions the preprocessed file lacks" do
586
+ allow(@code_finder).to receive(:find_all_in_preprocessed_file).and_return([nil, 20, nil])
587
+ expect(@code_finder).to receive(:find_all_in_c_file).with(filepath, [blocks[0], blocks[2]]).once.and_return([25, nil])
542
588
 
543
- result = @utils.locate_function_via_preprocessed(
544
- code_block: code_block,
545
- filepath: filepath,
546
- preprocessed_filepath: preprocessed_filepath
547
- )
548
- expect(result).to be_nil
589
+ result = @utils.locate_functions_via_preprocessed(code_blocks: blocks, filepath: filepath, preprocessed_filepath: preprocessed_filepath)
590
+ expect(result).to eq([25, 20, nil])
549
591
  end
550
592
 
551
- it "forwards correct arguments to both code_finder methods" do
552
- expect(@code_finder).to receive(:find_in_preprocessed_file)
553
- .with('/exact/preproc.i', 'exact block')
554
- .and_return(nil)
555
- expect(@code_finder).to receive(:find_in_c_file)
556
- .with('/exact/source.c', 'exact block')
557
- .and_return(nil)
593
+ it "logs the fallback search once for each function that needs it" do
594
+ allow(@code_finder).to receive(:find_all_in_preprocessed_file).and_return([10, nil, nil])
595
+ allow(@code_finder).to receive(:find_all_in_c_file).and_return([25, nil])
558
596
 
559
- @utils.locate_function_via_preprocessed(
560
- code_block: 'exact block',
561
- filepath: '/exact/source.c',
562
- preprocessed_filepath: '/exact/preproc.i'
563
- )
597
+ expect(@loginator).to receive(:log)
598
+ .with("Using fallback C function location search for #{filepath}", Verbosity::OBNOXIOUS, LogLabels::WARNING).twice
599
+
600
+ @utils.locate_functions_via_preprocessed(code_blocks: blocks, filepath: filepath, preprocessed_filepath: preprocessed_filepath)
564
601
  end
565
602
  end
566
603