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
@@ -0,0 +1,128 @@
1
+ # =========================================================================
2
+ # Ceedling - Test-Centered Build System for C
3
+ # ThrowTheSwitch.org
4
+ # Copyright (c) 2010-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
5
+ # SPDX-License-Identifier: MIT
6
+ # =========================================================================
7
+
8
+ require 'spec_helper'
9
+ require 'spec_integration_helper'
10
+ require 'partial_files_harness'
11
+ require 'dependency_tracker_integration_helper'
12
+
13
+ # Stage 7 across successive builds, with a real compiler and dependency tracker. The
14
+ # unit specs fix each decision with stand-ins. These prove the decisions hold together: what
15
+ # one build records is what the next build trusts.
16
+ describe 'Partial file preprocessing (integration)' do
17
+ include_context 'requires gcc'
18
+ include DependencyTrackerIntegrationHelper
19
+
20
+ before(:each) { skip 'requires -fdirectives-only support' unless directives_only_supported? }
21
+
22
+ # A module whose storage class comes from a macro in a header its source includes
23
+ WIDGET_TREE = {
24
+ 'src/config.h' => "#ifndef CONFIG_H\n#define CONFIG_H\n#define PRIVATE static\n#endif\n",
25
+ 'src/widget.h' => "#ifndef WIDGET_H\n#define WIDGET_H\n#include \"config.h\"\nint widget_get(void);\n#endif\n",
26
+ 'src/widget.c' => "#include \"widget.h\"\nPRIVATE int helper(void) { return 41; }\nint widget_get(void) { return helper() + 1; }\n"
27
+ }.freeze
28
+
29
+ def in_project
30
+ with_source_tree( WIDGET_TREE ) do |dir|
31
+ Dir.chdir( dir ) { yield }
32
+ end
33
+ end
34
+
35
+ def harness(**options)
36
+ IntegrationSpecHelpers::PartialFilesHarness.new( **options )
37
+ end
38
+
39
+ # One build of `filepath` by `with`, against a dependency store that persists between builds
40
+ def build(filepath = 'src/widget.c', with: harness)
41
+ return with.run_source( filepath, tracker: build_dependency_tracker( store_path: 'build/dependencies.yml' ) )
42
+ end
43
+
44
+ def past
45
+ return Time.at( 1_000_000_000 )
46
+ end
47
+
48
+ def backdate(paths)
49
+ File.utime( past, past, *paths )
50
+ end
51
+
52
+ def expanded(config)
53
+ File.read( config.expansion_filepath )
54
+ end
55
+
56
+ it 'records every file a build writes, and the next build recalls the same record without running' do
57
+ in_project do
58
+ first = build
59
+ paths = harness.artifact_paths( 'src/widget.c' )
60
+
61
+ expect( first ).to have_attributes(
62
+ raw_directives_only_filepath: paths[:raw_directives_only], fallback: false,
63
+ raw_expansion_filepath: paths[:raw_expansion], expansion_filepath: paths[:expanded_code]
64
+ )
65
+ expect( expanded( first ) ).to include( 'static int helper(void)' )
66
+ expect( File.read( first.raw_expansion_filepath ) ).to match( /^# \d+ "src\/config\.h"/ )
67
+
68
+ # A recalled record that ran nothing leaves every file exactly as it was. The files are
69
+ # dated back first, so a rewrite shows whatever the filesystem's mtime resolution.
70
+ files = paths.values + [first.assembled_filepath]
71
+ backdate( files )
72
+ second = build
73
+
74
+ expect( second.to_h ).to eq( first.to_h )
75
+ expect( files.map { |path| File.mtime( path ) } ).to all( eq( past ) )
76
+ end
77
+ end
78
+
79
+ # The macro lives in a header the module includes, never in the module itself
80
+ it 'preprocesses again when a header the expansion entered changes' do
81
+ in_project do
82
+ expect( expanded( build ) ).to include( 'static int helper(void)' )
83
+
84
+ File.write( 'src/config.h', "#ifndef CONFIG_H\n#define CONFIG_H\n#define PRIVATE\n#endif\n" )
85
+
86
+ code = expanded( build )
87
+ expect( code ).to include( 'int helper(void)' )
88
+ expect( code ).to_not include( 'static' )
89
+ end
90
+ end
91
+
92
+ # Only the full expansion meets the broken macro. Restoring the header is the one change
93
+ # before the next build, so only what the failed build left behind can make it expand again.
94
+ it 'leaves no expansion behind when the full expansion fails, and expands on the next build' do
95
+ in_project do
96
+ build
97
+ paths = harness.artifact_paths( 'src/widget.c' )
98
+ config = File.read( 'src/config.h' )
99
+
100
+ File.write( 'src/config.h', config.sub( '#define PRIVATE static', "#define WRAP(x) x\n#define PRIVATE WRAP(static" ) )
101
+ record = build
102
+
103
+ expect( record ).to have_attributes( expansion_filepath: nil, raw_expansion_filepath: nil )
104
+ expect( paths.values_at( :raw_expansion, :expanded_code ).select { |path| File.exist?( path ) } ).to be_empty
105
+
106
+ File.write( 'src/config.h', config )
107
+ expect( expanded( build ) ).to include( 'static int helper(void)' )
108
+ end
109
+ end
110
+
111
+ # An earlier build's raw copy must not pass for this file being preprocessed accurately
112
+ it 'records fallback for a file whose directives-only run fails, and recalls it on the next build' do
113
+ in_project do
114
+ expect( build.fallback ).to be( false )
115
+
116
+ failing = harness( directives_only_tool: IntegrationSpecHelpers.failing_tool( DEFAULT_TEST_FILE_DIRECTIVES_ONLY_PREPROCESSOR_TOOL ) )
117
+ File.write( 'src/widget.c', File.read( 'src/widget.c' ) + "\n" )
118
+
119
+ record = build( with: failing )
120
+ expect( record ).to have_attributes( fallback: true, raw_directives_only_filepath: nil )
121
+
122
+ # The next build recalls that record, rewriting nothing
123
+ backdate( [record.assembled_filepath] )
124
+ expect( build( with: failing ) ).to have_attributes( fallback: true, raw_directives_only_filepath: nil )
125
+ expect( File.mtime( record.assembled_filepath ) ).to eq( past )
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,520 @@
1
+ # =========================================================================
2
+ # Ceedling - Test-Centered Build System for C
3
+ # ThrowTheSwitch.org
4
+ # Copyright (c) 2010-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
5
+ # SPDX-License-Identifier: MIT
6
+ # =========================================================================
7
+
8
+ # What a Partial carries beyond the functions a test selected, proven with a real compiler.
9
+ #
10
+ # A module's code relies on more than its own selected functions. It declares functions
11
+ # defined elsewhere, and its header defines small static or inline helpers. A Partial
12
+ # carries the prototypes and the referenced helpers into its implementation source, after
13
+ # every include, so that code compiles and links. Each case below is a shape that failed to
14
+ # compile or link before carrying, or a shape carrying must leave alone.
15
+ #
16
+ # Generation runs through spec/support/integration/partials_generation_integration_helper.rb,
17
+ # which plans carrying the way PartialsManager does.
18
+
19
+ require 'spec_helper'
20
+ require 'spec_integration_helper'
21
+ require 'partials_generation_integration_helper'
22
+
23
+ describe 'What a Partial carries' do
24
+
25
+ include_context 'requires gcc'
26
+ before { skip 'directives-only preprocessing is unavailable' unless directives_only_supported? }
27
+
28
+ after(:each) { cleanup_partial( @result ) }
29
+
30
+ # The harness mocks every function unless told otherwise. A mocked function is never carried,
31
+ # so cases about carrying turn mocking off and a case about mocking says how it mocks.
32
+
33
+ let(:engine_api_h) do
34
+ <<~C
35
+ #ifndef ENGINE_API_H
36
+ #define ENGINE_API_H
37
+ inline int engine_get_twice(void) { return 42; }
38
+ #endif
39
+ C
40
+ end
41
+
42
+ # ---------------------------------------------------------------------------
43
+ context 'prototypes of functions the module declares but never defines' do
44
+ # ---------------------------------------------------------------------------
45
+
46
+ # The C99 inline idiom: a header holds the inline body, and one source file declares the
47
+ # function `extern inline` so its object holds the external definition. Nothing calls the
48
+ # prototype. Its whole job is that definition, which an unoptimized call links against.
49
+ it 'links a call to an inline function whose external definition the module provides' do
50
+ @result = generate_partial(
51
+ module_name: 'engine',
52
+ header: "#ifndef ENGINE_H\n#define ENGINE_H\nint engine_get(void);\n#endif\n",
53
+ source: "#include \"engine.h\"\n#include \"engine_api.h\"\nextern inline int engine_get_twice(void);\nint engine_get(void) { return 1; }\n",
54
+ source_includes: ['engine.h', 'engine_api.h'],
55
+ extra: { 'engine_api.h' => engine_api_h },
56
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
57
+ )
58
+
59
+ expect( @result.impl_c ).to include( 'extern inline int engine_get_twice(void);' )
60
+
61
+ link = link_partial( @result, references: ['engine_get_twice'], flags: '-O0' )
62
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
63
+ end
64
+
65
+ # C99 gives the external definition to a file declaring the function `extern` or without
66
+ # `inline`, so a plain prototype does the same job as `extern inline`
67
+ ['extern int engine_get_twice(void);', 'int engine_get_twice(void);'].each do |declaration|
68
+ it "links a call to an inline function the module declares as `#{declaration}`" do
69
+ @result = generate_partial(
70
+ module_name: 'engine',
71
+ header: "#ifndef ENGINE_H\n#define ENGINE_H\nint engine_get(void);\n#endif\n",
72
+ source: "#include \"engine.h\"\n#include \"engine_api.h\"\n#{declaration}\nint engine_get(void) { return 1; }\n",
73
+ source_includes: ['engine.h', 'engine_api.h'],
74
+ extra: { 'engine_api.h' => engine_api_h },
75
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
76
+ )
77
+
78
+ expect( @result.impl_c ).to include( declaration )
79
+
80
+ link = link_partial( @result, references: ['engine_get_twice'], flags: '-O0' )
81
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
82
+ end
83
+ end
84
+
85
+ it 'compiles a call to a function the source declares extern' do
86
+ @result = generate_partial(
87
+ module_name: 'ticker',
88
+ header: "#ifndef TICKER_H\n#define TICKER_H\nint ticker_get(void);\n#endif\n",
89
+ source: "#include \"ticker.h\"\nextern int board_tick(void);\nint ticker_get(void) { return board_tick() + 1; }\n",
90
+ source_includes: ['ticker.h'], mocks_expose: nil
91
+ )
92
+
93
+ compile = compile_objects( @result )
94
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
95
+ end
96
+
97
+ # Its #line names the header line the prototype came from, found in the header's own text
98
+ it 'compiles a call to a function the header declares and another module defines' do
99
+ @result = generate_partial(
100
+ module_name: 'counter',
101
+ header: "#ifndef COUNTER_H\n#define COUNTER_H\nint counter_get(void);\nint board_tick(void);\n#endif\n",
102
+ source: "#include \"counter.h\"\nint counter_get(void) { return board_tick() + 1; }\n",
103
+ source_includes: ['counter.h'], mocks_expose: nil
104
+ )
105
+
106
+ expect( @result.impl_c ).to match( /^#line 4 "[^"]*counter\.h"\nint board_tick\(void\);$/ )
107
+
108
+ compile = compile_objects( @result )
109
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
110
+ end
111
+ end
112
+
113
+ # ---------------------------------------------------------------------------
114
+ context 'prototypes a later macro renames' do
115
+ # ---------------------------------------------------------------------------
116
+
117
+ # A header included after the prototype turns calls into calls of another function. Nothing
118
+ # kept calls the original name, so its prototype stays behind where the macro can't mangle it.
119
+ it 'compiles when a function-like macro defined later shares a prototype\'s name' do
120
+ @result = generate_partial(
121
+ module_name: 'pooled',
122
+ header: "#ifndef POOLED_H\n#define POOLED_H\nvoid *pool_alloc(unsigned n);\nvoid *pooled_buf(void);\n#endif\n",
123
+ source: "#include \"pooled.h\"\n#include \"pool_dbg.h\"\nvoid *pooled_buf(void) { return pool_alloc(4); }\n",
124
+ source_includes: ['pooled.h', 'pool_dbg.h'],
125
+ extra: { 'pool_dbg.h' => "#ifndef POOL_DBG_H\n#define POOL_DBG_H\nvoid *pool_alloc_dbg(unsigned n, int line);\n#define pool_alloc(n) pool_alloc_dbg((n), __LINE__)\n#endif\n" },
126
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
127
+ )
128
+
129
+ compile = compile_objects( @result )
130
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
131
+ end
132
+ end
133
+
134
+ # ---------------------------------------------------------------------------
135
+ context 'functions the test left out' do
136
+ # ---------------------------------------------------------------------------
137
+
138
+ # A test subtracts a function to stub it. The selected function calling it links to the stub.
139
+ it 'links a selected call to a subtracted function against the test stub' do
140
+ @result = generate_partial(
141
+ module_name: 'reporter',
142
+ header: "#ifndef REPORTER_H\n#define REPORTER_H\nint reporter_poll(void);\nint reporter_report(void);\n#endif\n",
143
+ source: "#include \"reporter.h\"\nint reporter_poll(void) { return 1; }\nint reporter_report(void) { return reporter_poll() + 1; }\n",
144
+ source_includes: ['reporter.h'],
145
+ tests_expose: PartializerConfig::PUBLIC, tests_subtract: ['reporter_poll'], mocks_expose: nil
146
+ )
147
+
148
+ expect( @result.impl_c ).not_to include( 'return 1; }' )
149
+
150
+ link = link_partial( @result, references: ['reporter_report'], stubs: 'int reporter_poll(void) { return 7; }' )
151
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
152
+ end
153
+ end
154
+
155
+ # ---------------------------------------------------------------------------
156
+ context 'helpers the module header defines' do
157
+ # ---------------------------------------------------------------------------
158
+
159
+ it 'compiles a selected call to a static inline helper' do
160
+ @result = generate_partial(
161
+ module_name: 'clamped',
162
+ header: "#ifndef CLAMPED_H\n#define CLAMPED_H\nstatic inline int clamp(int v) { return v > 9 ? 9 : v; }\nint clamped_get(int v);\n#endif\n",
163
+ source: "#include \"clamped.h\"\nint clamped_get(int v) { return clamp(v); }\n",
164
+ source_includes: ['clamped.h'],
165
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
166
+ )
167
+
168
+ expect( @result.impl_c ).to include( 'static inline int clamp(int v)' )
169
+
170
+ compile = compile_objects( @result )
171
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
172
+ end
173
+
174
+ it 'leaves out a helper nothing kept calls, so its own calls never have to compile' do
175
+ @result = generate_partial(
176
+ module_name: 'quiet',
177
+ header: "#ifndef QUIET_H\n#define QUIET_H\nstatic void raw_write(void);\nstatic inline void log_raw(void) { raw_write(); }\nint quiet_get(void);\n#endif\n",
178
+ source: "#include \"quiet.h\"\nstatic void raw_write(void) { }\nint quiet_get(void) { return 1; }\n",
179
+ source_includes: ['quiet.h'],
180
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
181
+ )
182
+
183
+ expect( @result.impl_c ).not_to include( 'log_raw' )
184
+
185
+ compile = compile_objects( @result, flags: '-Wall -Werror' )
186
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
187
+ end
188
+
189
+ # The expanded copy shows the call the macro hides
190
+ it 'carries a helper that a macro calls' do
191
+ @result = generate_partial(
192
+ module_name: 'macroed',
193
+ header: "#ifndef MACROED_H\n#define MACROED_H\n#define CLAMP(x) clamp(x)\nstatic inline int clamp(int v) { return v > 9 ? 9 : v; }\nint macroed_get(int v);\n#endif\n",
194
+ source: "#include \"macroed.h\"\nint macroed_get(int v) { return CLAMP(v); }\n",
195
+ source_includes: ['macroed.h'],
196
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
197
+ )
198
+
199
+ expect( @result.impl_c ).to include( 'static inline int clamp(int v)' )
200
+
201
+ compile = compile_objects( @result )
202
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
203
+ end
204
+
205
+ # Promotion renames a helper's function-scope static and defines it once in the same file
206
+ it 'links a helper whose function-scope static was promoted' do
207
+ @result = generate_partial(
208
+ module_name: 'ticks',
209
+ header: "#ifndef TICKS_H\n#define TICKS_H\nstatic inline int counter(void) { static int n = 0; return ++n; }\nint ticks_next(void);\n#endif\n",
210
+ source: "#include \"ticks.h\"\nint ticks_next(void) { return counter(); }\n",
211
+ source_includes: ['ticks.h'],
212
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
213
+ )
214
+
215
+ link = link_partial( @result, references: ['ticks_next'] )
216
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
217
+ end
218
+
219
+ # The helper sits after the module's own interface include, where the mocked function is declared
220
+ it 'compiles a helper that calls a function the test mocks' do
221
+ @result = generate_partial(
222
+ module_name: 'noted',
223
+ header: "#ifndef NOTED_H\n#define NOTED_H\nvoid noted_log(int code);\nstatic inline void note(int code) { noted_log(code); }\nint noted_get(int v);\n#endif\n",
224
+ source: "#include \"noted.h\"\nvoid noted_log(int code) { (void)code; }\nint noted_get(int v) { note(v); return v + 1; }\n",
225
+ source_includes: ['noted.h'],
226
+ tests_expose: PartializerConfig::PUBLIC,
227
+ mocks_expose: PartializerConfig::ACCUMULATE, mocks_add: ['noted_log']
228
+ )
229
+
230
+ expect( @result.impl_c.index( 'static inline void note' ) ).to be > @result.impl_c.index( 'ceedling_partial_noted_interface.h' )
231
+
232
+ compile = compile_objects( @result )
233
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
234
+ end
235
+
236
+ # A mock-only Partial's interface stands in for its real header wherever another Partial
237
+ # includes it, so that header's helpers, statics and types still reach the other's code
238
+ it "compiles a module using a mocked header-only module's helper, table and types" do
239
+ dir = shared_partials_dir
240
+ header = <<~C
241
+ #ifndef SENSOR_INTERFACE_H
242
+ #define SENSOR_INTERFACE_H
243
+ #define SENSOR_SCALE 2
244
+ typedef struct { int raw; } sensor_reading_t;
245
+ static const int sensor_table[] = { 1, 2 };
246
+ static inline int sensor_twice(int x) { return SENSOR_SCALE * x; }
247
+ static sensor_reading_t sensor_inf_read(void);
248
+ #endif
249
+ C
250
+
251
+ mock = generate_partial(
252
+ module_name: 'sensor_interface', header: header, source: nil, tests_expose: nil,
253
+ mocks_expose: PartializerConfig::PRIVATE, mocks_subtract: ['sensor_twice'], dir: dir
254
+ )
255
+
256
+ expect( mock.extras_h ).to include( 'static const int sensor_table[] = { 1, 2 };' )
257
+ expect( mock.extras_h ).to include( 'static inline int sensor_twice(int x)' )
258
+ expect( mock.interface_h ).to include( 'sensor_reading_t sensor_inf_read(void);' )
259
+
260
+ @result = generate_partial(
261
+ module_name: 'sensor_manager',
262
+ header: "#ifndef SENSOR_MANAGER_H\n#define SENSOR_MANAGER_H\nint sensor_get(void);\n#endif\n",
263
+ source: "#include \"sensor_manager.h\"\n#include \"sensor_interface.h\"\n" \
264
+ "int sensor_get(void) { sensor_reading_t r = sensor_inf_read(); return sensor_twice(r.raw) * sensor_table[0]; }\n",
265
+ source_includes: ['sensor_manager.h', 'sensor_interface.h'],
266
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil,
267
+ partials: other_partial( 'sensor_interface', mocked: true ), dir: dir
268
+ )
269
+
270
+ compile = compile_objects( @result, flags: '-Wall -Werror' )
271
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
272
+ end
273
+
274
+ # A call through a member that shares a helper's name is not a use of the helper. Carrying
275
+ # the helper anyway leaves an unused static function, which -Wall -Werror rejects.
276
+ it 'carries no helper that only a member access names' do
277
+ @result = generate_partial(
278
+ module_name: 'buffers',
279
+ header: "#ifndef BUFFERS_H\n#define BUFFERS_H\n" \
280
+ "typedef struct buf { int len; int (*size)(const struct buf *b); } buf_t;\n" \
281
+ "static int size(const buf_t *b) { return b->len; }\nint buffers_get(const buf_t *b);\n#endif\n",
282
+ source: "#include \"buffers.h\"\nint buffers_get(const buf_t *b) { return b->size(b); }\n",
283
+ source_includes: ['buffers.h'],
284
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
285
+ )
286
+
287
+ expect( @result.impl_c ).not_to include( 'static int size' )
288
+
289
+ compile = compile_objects( @result, flags: '-Wall -Werror' )
290
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
291
+ end
292
+
293
+ # Passing a helper by name uses it as surely as calling it
294
+ it 'compiles a helper a selected body passes as a callback' do
295
+ @result = generate_partial(
296
+ module_name: 'ticker',
297
+ header: "#ifndef TICKER_H\n#define TICKER_H\ntypedef int (*ticker_cb_t)(int);\n" \
298
+ "static inline int doubled(int v) { return v * 2; }\n" \
299
+ "void ticker_register(ticker_cb_t cb);\nvoid ticker_init(void);\n#endif\n",
300
+ source: "#include \"ticker.h\"\nvoid ticker_init(void) { ticker_register(doubled); }\n",
301
+ source_includes: ['ticker.h'],
302
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
303
+ )
304
+
305
+ expect( @result.impl_c ).to include( 'static inline int doubled(int v)' )
306
+
307
+ compile = compile_objects( @result, flags: '-Wall -Werror' )
308
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
309
+ end
310
+
311
+ # A plain inline helper gets its external definition from the source's extern inline prototype
312
+ it 'links a plain inline helper through its extern inline prototype' do
313
+ @result = generate_partial(
314
+ module_name: 'twicer',
315
+ header: "#ifndef TWICER_H\n#define TWICER_H\nint twicer_base(void);\ninline int twicer_twice(void) { return 2 * twicer_base(); }\nint twicer_get(void);\n#endif\n",
316
+ source: "#include \"twicer.h\"\nextern inline int twicer_twice(void);\nint twicer_base(void) { return 21; }\nint twicer_get(void) { return twicer_twice(); }\n",
317
+ source_includes: ['twicer.h'],
318
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
319
+ )
320
+
321
+ link = link_partial( @result, references: ['twicer_get'], flags: '-O0' )
322
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
323
+ end
324
+ end
325
+
326
+ # ---------------------------------------------------------------------------
327
+ context 'a module header without an include guard' do
328
+ # ---------------------------------------------------------------------------
329
+
330
+ # Another header pulls the real module header in, helpers and all. A carried copy would collide.
331
+ it 'carries no helper, so the real header\'s copy compiles alone' do
332
+ @result = generate_partial(
333
+ module_name: 'onceful',
334
+ header: "#pragma once\nstatic inline int clamp(int v) { return v > 9 ? 9 : v; }\nint onceful_get(int v);\n",
335
+ source: "#include \"onceful.h\"\n#include \"onceful_cfg.h\"\nint onceful_get(int v) { return clamp(v) + ONCEFUL_BIAS; }\n",
336
+ source_includes: ['onceful.h', 'onceful_cfg.h'],
337
+ extra: { 'onceful_cfg.h' => "#ifndef ONCEFUL_CFG_H\n#define ONCEFUL_CFG_H\n#include \"onceful.h\"\n#define ONCEFUL_BIAS 0\n#endif\n" },
338
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: nil
339
+ )
340
+
341
+ expect( @result.impl_c ).not_to include( 'static inline int clamp' )
342
+ expect( @result.carry.skipped.map( &:item ) ).to eq( ['clamp'] )
343
+
344
+ compile = compile_objects( @result )
345
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
346
+ end
347
+ end
348
+
349
+ # ---------------------------------------------------------------------------
350
+ context 'prototypes a header already declared' do
351
+ # ---------------------------------------------------------------------------
352
+
353
+ def generate_repeats(suppress:)
354
+ generate_partial(
355
+ module_name: 'repeats',
356
+ header: "#ifndef REPEATS_H\n#define REPEATS_H\nint board_tick(void);\nint repeats_get(void);\n#endif\n",
357
+ source: "#include \"repeats.h\"\n#include \"repeats_board.h\"\nextern int board_tick(void);\nint repeats_get(void) { return board_tick(); }\n",
358
+ source_includes: ['repeats.h', 'repeats_board.h'],
359
+ extra: { 'repeats_board.h' => "#ifndef REPEATS_BOARD_H\n#define REPEATS_BOARD_H\nint board_tick(void);\n#endif\n" },
360
+ suppress_redundant_decls: suppress, mocks_expose: nil
361
+ )
362
+ end
363
+
364
+ it 'compiles under -Wredundant-decls -Werror with the redundant declarations suppressed' do
365
+ @result = generate_repeats( suppress: true )
366
+
367
+ compile = compile_objects( @result, flags: '-Wredundant-decls -Werror' )
368
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
369
+ end
370
+
371
+ it 'writes the prototypes bare when suppression is off' do
372
+ @result = generate_repeats( suppress: false )
373
+
374
+ expect( @result.impl_c ).to include( 'extern int board_tick(void);' )
375
+ expect( @result.impl_c ).not_to include( '#pragma' )
376
+ end
377
+
378
+ # Clang accepts -Wredundant-decls but never reports it, so only GCC shows what the pragmas quiet
379
+ it 'fails under -Wredundant-decls -Werror with suppression off' do
380
+ skip 'only GCC reports -Wredundant-decls' unless partials_compiler_gcc?
381
+
382
+ @result = generate_repeats( suppress: false )
383
+
384
+ compile = compile_objects( @result, flags: '-Wredundant-decls -Werror' )
385
+ expect( compile.ok ).to be(false)
386
+ expect( compile.stderr ).to include( 'redundant redeclaration' )
387
+ end
388
+ end
389
+
390
+ # ---------------------------------------------------------------------------
391
+ context 'a selected function that never returns' do
392
+ # ---------------------------------------------------------------------------
393
+
394
+ # A caller ending in a call to it needs to know it never returns, or -Wreturn-type objects
395
+ it 'keeps _Noreturn, so its callers compile under -Wall -Werror' do
396
+ @result = generate_partial(
397
+ module_name: 'parser',
398
+ header: "#ifndef PARSER_H\n#define PARSER_H\nint parser_parse(int x);\n#endif\n",
399
+ source: "#include \"parser.h\"\nstatic _Noreturn void fatal(void) { for (;;) {} }\nint parser_parse(int x) { if (x >= 0) return x; fatal(); }\n",
400
+ source_includes: ['parser.h'], mocks_expose: nil
401
+ )
402
+
403
+ expect( @result.impl_c ).to include( '_Noreturn void fatal(void)' )
404
+
405
+ compile = compile_objects( @result, flags: '-Wall -Werror' )
406
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
407
+ end
408
+ end
409
+
410
+ # ---------------------------------------------------------------------------
411
+ context 'variables' do
412
+ # ---------------------------------------------------------------------------
413
+
414
+ let(:tally_h) { "#ifndef TALLY_H\n#define TALLY_H\nextern int board_count;\nint tally_get(void);\n#endif\n" }
415
+ let(:tally_c) { "#include \"tally.h\"\nint tally_get(void) { return board_count + 1; }\n" }
416
+
417
+ # The weak definition gives way, even where common symbols are off and two definitions collide
418
+ it 'links a real definition of an extern variable over the weak one' do
419
+ @result = generate_partial(
420
+ module_name: 'tally', header: tally_h, source: tally_c, source_includes: ['tally.h'], mocks_expose: nil
421
+ )
422
+
423
+ expect( @result.impl_c ).to include( '__attribute__((weak)) int board_count;' )
424
+
425
+ link = link_partial( @result, references: ['tally_get'], stubs: 'int board_count = 41;', flags: '-fno-common' )
426
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
427
+ end
428
+
429
+ # The weak definition stands in when the defining module isn't part of the test
430
+ it 'links an extern variable nothing else defines' do
431
+ @result = generate_partial(
432
+ module_name: 'tally', header: tally_h, source: tally_c, source_includes: ['tally.h'], mocks_expose: nil
433
+ )
434
+
435
+ link = link_partial( @result, references: ['tally_get'], flags: '-fno-common' )
436
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
437
+ end
438
+
439
+ it 'leaves the definition to the test when told to' do
440
+ @result = generate_partial(
441
+ module_name: 'tally', header: tally_h, source: tally_c, source_includes: ['tally.h'],
442
+ mocks_expose: nil, extern_variables: :test
443
+ )
444
+
445
+ expect( @result.impl_c ).not_to include( 'int board_count' )
446
+
447
+ link = link_partial( @result, references: ['tally_get'], stubs: 'int board_count = 41;', flags: '-fno-common' )
448
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
449
+ end
450
+
451
+ # The implementation header declares the variable from its definition, size included
452
+ it 'keeps an array\'s size for a test\'s sizeof' do
453
+ @result = generate_partial(
454
+ module_name: 'table',
455
+ header: "#ifndef TABLE_H\n#define TABLE_H\nextern const int lut[];\nint table_get(int i);\n#endif\n",
456
+ source: "#include \"table.h\"\nconst int lut[4] = { 1, 2, 3, 4 };\nint table_get(int i) { return lut[i]; }\n",
457
+ source_includes: ['table.h'], mocks_expose: nil
458
+ )
459
+
460
+ link = link_partial( @result, references: ['table_get'], stubs: 'unsigned lut_size(void) { return sizeof(lut); }' )
461
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
462
+ end
463
+
464
+ # No definition of a type the module never completes can compile, so the defining module supplies it
465
+ it 'writes no definition of an extern variable of an opaque struct' do
466
+ @result = generate_partial(
467
+ module_name: 'handle',
468
+ header: "#ifndef HANDLE_H\n#define HANDLE_H\nstruct handle_s;\nextern struct handle_s the_handle;\nstruct handle_s *handle_get(void);\n#endif\n",
469
+ source: "#include \"handle.h\"\nstruct handle_s *handle_get(void) { return &the_handle; }\n",
470
+ source_includes: ['handle.h'], mocks_expose: nil
471
+ )
472
+
473
+ expect( @result.impl_c ).not_to include( 'struct handle_s the_handle;' )
474
+
475
+ link = link_partial( @result, references: ['handle_get'], stubs: 'struct handle_s { int id; }; struct handle_s the_handle;' )
476
+ expect( link.ok ).to be(true), "expected a clean link, got: #{link.first_error}"
477
+ end
478
+ end
479
+
480
+ # ---------------------------------------------------------------------------
481
+ context 'under fallback preprocessing' do
482
+ # ---------------------------------------------------------------------------
483
+
484
+ # Fallback keeps one branch of a conditional it can't evaluate, so a prototype arrives once
485
+ it 'carries a prototype from a conditional header' do
486
+ @result = generate_partial(
487
+ module_name: 'branchy',
488
+ header: "#ifndef BRANCHY_H\n#define BRANCHY_H\n#if BOARD_REV > 2\nint board_tick(int);\n#else\nlong board_tick(int);\n#endif\nint branchy_get(void);\n#endif\n",
489
+ source: "#include \"branchy.h\"\nint branchy_get(void) { return (int)board_tick(1); }\n",
490
+ source_includes: ['branchy.h'], mode: :fallback, mocks_expose: nil
491
+ )
492
+
493
+ expect( @result.carry.prototypes.size ).to eq( 1 )
494
+
495
+ compile = compile_objects( @result )
496
+ expect( compile.ok ).to be(true), "expected a clean compile, got: #{compile.first_error}"
497
+ end
498
+ end
499
+
500
+ # ---------------------------------------------------------------------------
501
+ context 'an inline function the module only declares, under a private mock' do
502
+ # ---------------------------------------------------------------------------
503
+
504
+ # Its body lives in a header the module includes, so a mock could never replace it
505
+ it 'keeps it out of the mock and carries its prototype instead' do
506
+ @result = generate_partial(
507
+ module_name: 'mocked',
508
+ header: "#ifndef MOCKED_H\n#define MOCKED_H\nint mocked_get(void);\n#endif\n",
509
+ source: "#include \"mocked.h\"\n#include \"engine_api.h\"\nextern inline int engine_get_twice(void);\nstatic int mocked_base(void) { return 41; }\nint mocked_get(void) { return mocked_base() + 1; }\n",
510
+ source_includes: ['mocked.h', 'engine_api.h'],
511
+ extra: { 'engine_api.h' => engine_api_h },
512
+ tests_expose: PartializerConfig::PUBLIC, mocks_expose: PartializerConfig::PRIVATE
513
+ )
514
+
515
+ expect( @result.interface_h ).not_to include( 'engine_get_twice' )
516
+ expect( @result.interface_h ).to include( 'int mocked_base(void);' )
517
+ expect( @result.impl_c ).to include( 'extern inline int engine_get_twice(void);' )
518
+ end
519
+ end
520
+ end