ceedling 1.2.1 → 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 (545) hide show
  1. checksums.yaml +4 -4
  2. data/GIT_COMMIT_SHA +1 -1
  3. data/README.md +11 -9
  4. data/Rakefile +2 -1
  5. data/assets/features/ceedling +1 -1
  6. data/assets/fixtures/test_source_file_duplicate_basenames/test_calc_typo.c +14 -0
  7. data/assets/fixtures/tests_with_duplicate_test_names/test_foo.c +21 -0
  8. data/assets/fixtures/tests_with_partials_coverage/src/private_macro.c +7 -0
  9. data/assets/fixtures/tests_with_partials_coverage/src/private_macro.h +5 -0
  10. data/assets/fixtures/tests_with_partials_coverage/src/tally.c +13 -0
  11. data/assets/fixtures/tests_with_partials_coverage/src/tally.h +4 -0
  12. data/assets/fixtures/tests_with_partials_coverage/test/test_private_macro.c +10 -0
  13. data/assets/fixtures/tests_with_partials_coverage/test/test_tally.c +9 -0
  14. data/bin/actionator.rb +6 -12
  15. data/bin/app_cfg.rb +14 -1
  16. data/bin/ceedling +13 -3
  17. data/bin/cli.rb +25 -6
  18. data/bin/cli_handler.rb +113 -73
  19. data/bin/cli_helper.rb +51 -78
  20. data/bin/installation_selector.rb +81 -0
  21. data/bin/launchinator.rb +69 -0
  22. data/bin/mixin_resolvinator.rb +26 -36
  23. data/bin/objects.yml +13 -0
  24. data/bin/path_validator.rb +25 -29
  25. data/bin/versionator.rb +47 -48
  26. data/ceedling.gemspec +19 -15
  27. data/docs/BreakingChanges.md +86 -1
  28. data/docs/Changelog.md +145 -3
  29. data/docs/KnownIssues.md +179 -6
  30. data/docs/ReleaseNotes.md +13 -0
  31. data/examples/wondrous_forest/README.md +29 -1
  32. data/examples/wondrous_forest/src/ForestUnits.h +23 -0
  33. data/examples/wondrous_forest/src/RainGauge.c +59 -0
  34. data/examples/wondrous_forest/src/RainGauge.h +39 -0
  35. data/examples/wondrous_forest/src/RainTipIsr.c +17 -0
  36. data/examples/wondrous_forest/src/RainTipIsr.h +14 -0
  37. data/examples/wondrous_forest/test/TestRainGauge.c +126 -0
  38. data/lib/ceedling/build_log_writer.rb +33 -0
  39. data/lib/ceedling/c_extractor/README.md +15 -7
  40. data/lib/ceedling/c_extractor/c_extractor.rb +25 -14
  41. data/lib/ceedling/c_extractor/c_extractor_code_text.rb +84 -54
  42. data/lib/ceedling/c_extractor/c_extractor_constants.rb +18 -7
  43. data/lib/ceedling/c_extractor/c_extractor_declarations.rb +319 -283
  44. data/lib/ceedling/c_extractor/c_extractor_declarator.rb +285 -0
  45. data/lib/ceedling/c_extractor/c_extractor_defined_type.rb +111 -0
  46. data/lib/ceedling/c_extractor/c_extractor_definitions.rb +174 -121
  47. data/lib/ceedling/c_extractor/c_extractor_functions.rb +191 -162
  48. data/lib/ceedling/c_extractor/c_extractor_preprocessing.rb +46 -55
  49. data/lib/ceedling/c_extractor/c_extractor_statement.rb +30 -0
  50. data/lib/ceedling/c_extractor/c_extractor_types.rb +63 -41
  51. data/lib/ceedling/c_extractor/c_module_edits.rb +48 -0
  52. data/lib/ceedling/c_identifier.rb +21 -0
  53. data/lib/ceedling/ceedling.h +8 -0
  54. data/lib/ceedling/config/build_root_policy.rb +70 -0
  55. data/lib/ceedling/config/configurator.rb +18 -19
  56. data/lib/ceedling/config/configurator_builder.rb +75 -28
  57. data/lib/ceedling/config/configurator_paths_validator.rb +179 -0
  58. data/lib/ceedling/config/configurator_plugins.rb +1 -1
  59. data/lib/ceedling/config/configurator_setup.rb +44 -33
  60. data/lib/ceedling/config/configurator_validator.rb +1 -110
  61. data/lib/ceedling/constants.rb +5 -1
  62. data/lib/ceedling/defaults.rb +35 -5
  63. data/lib/ceedling/dependencies/CACHE_SCHEMA.md +118 -0
  64. data/lib/ceedling/dependencies/README.md +18 -16
  65. data/lib/ceedling/dependencies/dependency_cache_store.rb +43 -21
  66. data/lib/ceedling/dependencies/dependency_hasher.rb +35 -1
  67. data/lib/ceedling/dependencies/dependency_tracker.rb +9 -3
  68. data/lib/ceedling/dependencies/dependinator.rb +13 -1
  69. data/lib/ceedling/diagnostics/DOCTOR.md +142 -0
  70. data/lib/ceedling/diagnostics/README.md +5 -0
  71. data/lib/ceedling/diagnostics/build_step_doctor.rb +110 -0
  72. data/lib/ceedling/diagnostics/duplicate_symbol_specialist.rb +108 -0
  73. data/lib/ceedling/diagnostics/guidance_phrases.rb +30 -0
  74. data/lib/ceedling/diagnostics/header_collision_guidance.rb +56 -0
  75. data/lib/ceedling/diagnostics/header_collision_specialist.rb +152 -0
  76. data/lib/ceedling/diagnostics/include_depth_specialist.rb +132 -0
  77. data/lib/ceedling/diagnostics/missing_symbol_specialist.rb +111 -0
  78. data/lib/ceedling/diagnostics/partial_name_specialist.rb +134 -0
  79. data/lib/ceedling/diagnostics/toolchain_output.rb +44 -0
  80. data/lib/ceedling/filename_extension.rb +7 -1
  81. data/lib/ceedling/filesystem/FILE_TREE.md +253 -0
  82. data/lib/ceedling/filesystem/PATH_HANDLING.md +360 -0
  83. data/lib/ceedling/filesystem/README.md +46 -0
  84. data/lib/ceedling/filesystem/build_roots.rb +105 -0
  85. data/lib/ceedling/filesystem/build_subpath.rb +187 -0
  86. data/lib/ceedling/filesystem/destination_collision.rb +25 -0
  87. data/lib/ceedling/{file_finder.rb → filesystem/file_finder.rb} +177 -156
  88. data/lib/ceedling/filesystem/file_finder_helper.rb +154 -0
  89. data/lib/ceedling/filesystem/file_path_collection_utils.rb +183 -0
  90. data/lib/ceedling/{file_path_utils.rb → filesystem/file_path_utils.rb} +200 -167
  91. data/lib/ceedling/{file_system_wrapper.rb → filesystem/file_system_wrapper.rb} +6 -5
  92. data/lib/ceedling/filesystem/file_tree.rb +241 -0
  93. data/lib/ceedling/{file_wrapper.rb → filesystem/file_wrapper.rb} +149 -65
  94. data/lib/ceedling/filesystem/path_exclusions.rb +30 -0
  95. data/lib/ceedling/{path_matcher.rb → filesystem/path_matcher.rb} +48 -23
  96. data/lib/ceedling/{path_mirror.rb → filesystem/path_mirror.rb} +19 -18
  97. data/lib/ceedling/filesystem/path_spellings.rb +55 -0
  98. data/lib/ceedling/filesystem/project_paths.rb +184 -0
  99. data/lib/ceedling/filesystem/test_build_layout.rb +114 -0
  100. data/lib/ceedling/filesystem/win_long_paths.rb +153 -0
  101. data/lib/ceedling/filesystem/win_path_limit.rb +83 -0
  102. data/lib/ceedling/filesystem/win_path_prober.rb +52 -0
  103. data/lib/ceedling/filesystem/working_dir.rb +40 -0
  104. data/lib/ceedling/generators/generator.rb +32 -70
  105. data/lib/ceedling/generators/generator_helper.rb +0 -44
  106. data/lib/ceedling/generators/generator_mocks.rb +5 -0
  107. data/lib/ceedling/generators/generator_partials.rb +306 -244
  108. data/lib/ceedling/generators/generator_test_results_backtrace.rb +7 -7
  109. data/lib/ceedling/generators/generator_test_runner.rb +5 -8
  110. data/lib/ceedling/generators/partial_header_writer.rb +95 -0
  111. data/lib/ceedling/generators/partial_source_writer.rb +137 -0
  112. data/lib/ceedling/handoff.rb +121 -0
  113. data/lib/ceedling/includes/header_search.rb +225 -0
  114. data/lib/ceedling/includes/include_factory.rb +9 -12
  115. data/lib/ceedling/includes/include_pathinator.rb +112 -33
  116. data/lib/ceedling/includes/includes.rb +150 -38
  117. data/lib/ceedling/installation.rb +92 -0
  118. data/lib/ceedling/library_resolver.rb +99 -0
  119. data/lib/ceedling/objects.yml +112 -6
  120. data/lib/ceedling/partials/README.md +110 -16
  121. data/lib/ceedling/partials/carry_plan.rb +71 -0
  122. data/lib/ceedling/partials/definition_head.rb +74 -0
  123. data/lib/ceedling/partials/include_groups.rb +37 -0
  124. data/lib/ceedling/partials/interface_extras.rb +25 -0
  125. data/lib/ceedling/partials/partializer.rb +603 -124
  126. data/lib/ceedling/partials/partializer_config.rb +8 -1
  127. data/lib/ceedling/partials/partializer_helper.rb +851 -145
  128. data/lib/ceedling/partials/partializer_reconciler.rb +174 -0
  129. data/lib/ceedling/partials/partializer_utils.rb +89 -109
  130. data/lib/ceedling/partials/partials.rb +153 -10
  131. data/lib/ceedling/partials/type_macros.rb +126 -0
  132. data/lib/ceedling/plugins/report_log_writer_plugin.rb +3 -5
  133. data/lib/ceedling/preprocess/README.md +43 -33
  134. data/lib/ceedling/preprocess/preprocessinator.rb +100 -186
  135. data/lib/ceedling/preprocess/preprocessinator_code_finder.rb +65 -72
  136. data/lib/ceedling/preprocess/preprocessinator_file_assembler.rb +32 -76
  137. data/lib/ceedling/preprocess/preprocessinator_includes_handler.rb +1 -1
  138. data/lib/ceedling/preprocess/preprocessinator_line_marker_includes_extractor.rb +1 -1
  139. data/lib/ceedling/preprocess/preprocessinator_reconstructor.rb +51 -14
  140. data/lib/ceedling/rake_app/rakefile_component_resolver.rb +10 -17
  141. data/lib/ceedling/rakefile.rb +15 -1
  142. data/lib/ceedling/rakefiles/base/tasks_base.rake +1 -1
  143. data/lib/ceedling/rakefiles/release/rules_release.rake +4 -7
  144. data/lib/ceedling/release_invoker/release_build_executor.rb +33 -44
  145. data/lib/ceedling/release_invoker/release_build_planner.rb +14 -6
  146. data/lib/ceedling/reportinator.rb +3 -4
  147. data/lib/ceedling/setupinator.rb +104 -87
  148. data/lib/ceedling/test_context_extractor.rb +5 -1
  149. data/lib/ceedling/test_invoker/HEADER_COLLISIONS.md +21 -7
  150. data/lib/ceedling/test_invoker/PIPELINE.md +62 -19
  151. data/lib/ceedling/test_invoker/README.md +1 -1
  152. data/lib/ceedling/test_invoker/derived_search_path_notices.rb +45 -0
  153. data/lib/ceedling/test_invoker/mock_locator.rb +175 -10
  154. data/lib/ceedling/test_invoker/partial_files_preprocessinator.rb +181 -0
  155. data/lib/ceedling/test_invoker/partials_manager.rb +271 -302
  156. data/lib/ceedling/test_invoker/standin_headerinator.rb +19 -17
  157. data/lib/ceedling/test_invoker/test_bare_includes_extractinator.rb +26 -3
  158. data/lib/ceedling/test_invoker/test_build_executor.rb +358 -234
  159. data/lib/ceedling/test_invoker/test_build_planner.rb +46 -33
  160. data/lib/ceedling/test_invoker/test_build_setup.rb +43 -18
  161. data/lib/ceedling/test_invoker/test_build_validations.rb +35 -47
  162. data/lib/ceedling/test_invoker/test_derived_search_paths.rb +189 -0
  163. data/lib/ceedling/test_invoker/test_file_preprocessinator.rb +2 -3
  164. data/lib/ceedling/test_invoker/test_includes_reconcilinator.rb +1 -1
  165. data/lib/ceedling/test_invoker/test_invoker.rb +6 -1
  166. data/lib/ceedling/test_invoker/test_invoker_types.rb +28 -20
  167. data/lib/ceedling/test_invoker/test_pipeline_helpers.rb +6 -4
  168. data/lib/ceedling/test_invoker/test_pipeline_manager.rb +25 -8
  169. data/lib/ceedling/test_invoker/test_runner_generatinator.rb +31 -3
  170. data/lib/ceedling/test_invoker/test_search_paths.rb +30 -8
  171. data/lib/ceedling/test_invoker/test_source_file_directive_resolver.rb +40 -20
  172. data/lib/ceedling/test_invoker/test_substitutions.rb +72 -0
  173. data/lib/ceedling/tools/shell_quoting.rb +45 -0
  174. data/lib/ceedling/{tool_executor.rb → tools/tool_executor.rb} +9 -3
  175. data/lib/ceedling/tools/tool_quoting.rb +79 -0
  176. data/lib/ceedling/{tool_validator.rb → tools/tool_validator.rb} +18 -7
  177. data/lib/ceedling/yaml_wrapper.rb +3 -2
  178. data/lib/version.rb +1 -1
  179. data/plugins/bullseye/bullseye.rake +1 -3
  180. data/plugins/bullseye/config/defaults_bullseye.rb +1 -1
  181. data/plugins/bullseye/lib/bullseye.rb +24 -9
  182. data/plugins/command_hooks/lib/command_hooks.rb +1 -1
  183. data/plugins/cppcheck/config/defaults_cppcheck.rb +1 -1
  184. data/plugins/dependencies/config/defaults.yml +6 -6
  185. data/plugins/dependencies/dependencies.rake +4 -1
  186. data/plugins/dependencies/lib/dependencies.rb +18 -8
  187. data/plugins/dependencies/lib/dependency_spec.rb +17 -5
  188. data/plugins/fff/lib/fff.rb +79 -46
  189. data/plugins/fff/lib/fff_mock_generator.rb +12 -9
  190. data/plugins/fff/spec/fff_cmock_wrapper_spec.rb +262 -0
  191. data/plugins/fff/spec/fff_mock_header_generator_spec.rb +9 -0
  192. data/plugins/fff/spec/fff_mock_source_generator_spec.rb +20 -0
  193. data/plugins/gcov/config/defaults_gcov.rb +1 -1
  194. data/plugins/gcov/lib/console_reportinator.rb +28 -36
  195. data/plugins/gcov/lib/gcov.rb +9 -2
  196. data/plugins/gcov/lib/gcovr_reportinator.rb +8 -40
  197. data/plugins/gcov/lib/gcovr_thresholds.rb +74 -0
  198. data/plugins/gcov/lib/reportgenerator_reportinator.rb +3 -2
  199. data/plugins/module_generator/lib/module_generator.rb +3 -3
  200. data/plugins/report_tests_teamcity_stdout/lib/report_tests_teamcity_stdout.rb +53 -80
  201. data/plugins/sanitize/lib/sanitize_records.rb +3 -6
  202. data/plugins/valgrind/lib/valgrind.rb +14 -7
  203. data/site-local/404.html +2 -2
  204. data/site-local/assets/javascripts/{bundle.c21346df.min.js → bundle.a5f9d56c.min.js} +1 -1
  205. data/site-local/assets/javascripts/{bundle.c21346df.min.js.map → bundle.a5f9d56c.min.js.map} +2 -2
  206. data/site-local/configuration/environment-vars.html +2 -2
  207. data/site-local/configuration/global-collections.html +3 -3
  208. data/site-local/configuration/index.html +2 -2
  209. data/site-local/configuration/loading.html +2 -2
  210. data/site-local/configuration/mixins.html +2 -2
  211. data/site-local/configuration/parallel-builds.html +2 -2
  212. data/site-local/configuration/project-file.html +2 -2
  213. data/site-local/configuration/reference/cexception.html +2 -2
  214. data/site-local/configuration/reference/cmock.html +7 -3
  215. data/site-local/configuration/reference/defines.html +2 -2
  216. data/site-local/configuration/reference/environment.html +2 -2
  217. data/site-local/configuration/reference/extension.html +2 -2
  218. data/site-local/configuration/reference/files.html +65 -12
  219. data/site-local/configuration/reference/flags.html +2 -2
  220. data/site-local/configuration/reference/index.html +2 -2
  221. data/site-local/configuration/reference/libraries.html +23 -5
  222. data/site-local/configuration/reference/mixins.html +2 -2
  223. data/site-local/configuration/reference/partials.html +84 -2
  224. data/site-local/configuration/reference/paths.html +36 -8
  225. data/site-local/configuration/reference/plugins.html +2 -2
  226. data/site-local/configuration/reference/project.html +264 -12
  227. data/site-local/configuration/reference/release-build.html +4 -2
  228. data/site-local/configuration/reference/test-build.html +2 -2
  229. data/site-local/configuration/reference/test-runner.html +2 -2
  230. data/site-local/configuration/reference/tools.html +58 -4
  231. data/site-local/configuration/reference/unity.html +2 -2
  232. data/site-local/configuration/which-ceedling.html +379 -19
  233. data/site-local/development/index.html +2 -2
  234. data/site-local/development/plugins/configuration.html +2 -2
  235. data/site-local/development/plugins/index.html +2 -2
  236. data/site-local/development/plugins/plugin-subclass.html +5 -4
  237. data/site-local/development/plugins/rake-tasks.html +2 -2
  238. data/site-local/development/releases.html +7 -3
  239. data/site-local/development/workflow.html +50 -45
  240. data/site-local/getting-started/builds.html +4 -2
  241. data/site-local/getting-started/command-line.html +58 -6
  242. data/site-local/getting-started/example-projects/cipher-quest.html +2 -2
  243. data/site-local/getting-started/example-projects/index.html +2 -2
  244. data/site-local/getting-started/example-projects/temp-sensor.html +2 -2
  245. data/site-local/getting-started/example-projects/wondrous-forest.html +10 -2
  246. data/site-local/getting-started/index.html +2 -2
  247. data/site-local/getting-started/installation.html +2 -2
  248. data/site-local/getting-started/quick-start.html +2 -2
  249. data/site-local/help.html +2 -2
  250. data/site-local/index.html +2 -2
  251. data/site-local/overview/build-system.html +2 -2
  252. data/site-local/overview/index.html +2 -2
  253. data/site-local/overview/test-environments.html +2 -2
  254. data/site-local/overview/tools-and-frameworks.html +2 -2
  255. data/site-local/plugins/beep.html +2 -2
  256. data/site-local/plugins/bullseye/index.html +45 -38
  257. data/site-local/plugins/bullseye/licensing.html +2 -2
  258. data/site-local/plugins/command-hooks.html +4 -4
  259. data/site-local/plugins/compile-commands-json-db.html +2 -2
  260. data/site-local/plugins/cppcheck.html +2 -2
  261. data/site-local/plugins/dependencies.html +8 -5
  262. data/site-local/plugins/fff.html +58 -13
  263. data/site-local/plugins/gcov/examples.html +2 -2
  264. data/site-local/plugins/gcov/gcovr.html +23 -14
  265. data/site-local/plugins/gcov/index.html +2 -2
  266. data/site-local/plugins/gcov/overview.html +2 -2
  267. data/site-local/plugins/gcov/reportgenerator.html +18 -14
  268. data/site-local/plugins/gcov/reporting.html +2 -2
  269. data/site-local/plugins/gcov/setup.html +4 -3
  270. data/site-local/plugins/gcov/tool-versions.html +2 -2
  271. data/site-local/plugins/gcov/troubleshooting.html +2 -2
  272. data/site-local/plugins/index.html +2 -2
  273. data/site-local/plugins/module-generator.html +2 -2
  274. data/site-local/plugins/report-build-warnings-log.html +2 -2
  275. data/site-local/plugins/report-tests-gtestlike-stdout.html +2 -2
  276. data/site-local/plugins/report-tests-ide-stdout.html +2 -2
  277. data/site-local/plugins/report-tests-log-factory.html +2 -2
  278. data/site-local/plugins/report-tests-pretty-stdout.html +2 -2
  279. data/site-local/plugins/report-tests-raw-output-log.html +5 -3
  280. data/site-local/plugins/report-tests-teamcity-stdout.html +8 -5
  281. data/site-local/plugins/sanitize.html +9 -8
  282. data/site-local/plugins/valgrind.html +10 -9
  283. data/site-local/project/index.html +2 -2
  284. data/site-local/project/release-history.html +2 -2
  285. data/site-local/project/sbom.html +2 -2
  286. data/site-local/project/upgrade.html +5 -2
  287. data/site-local/reference/build-directives.html +2 -2
  288. data/site-local/reference/command-line.html +11 -4
  289. data/site-local/reference/environment-vars.html +2 -2
  290. data/site-local/reference/gcov-plugin.html +2 -2
  291. data/site-local/reference/global-collections.html +12 -12
  292. data/site-local/reference/index.html +2 -2
  293. data/site-local/reference/partials-macros.html +47 -2
  294. data/site-local/reference/project-configuration.html +2 -2
  295. data/site-local/sitemap.xml.gz +0 -0
  296. data/site-local/snapshot/examples/cipher_quest/index.html +2 -2
  297. data/site-local/snapshot/examples/temp_sensor/index.html +2 -2
  298. data/site-local/snapshot/examples/wondrous_forest/index.html +72 -15
  299. data/site-local/snapshot/plugins/bullseye/config/defaults_bullseye.rb +1 -1
  300. data/site-local/snapshot/plugins/gcov/config/defaults_gcov.rb +1 -1
  301. data/site-local/testing-guide/build-directives.html +2 -2
  302. data/site-local/testing-guide/conventions.html +113 -15
  303. data/site-local/testing-guide/frameworks.html +2 -2
  304. data/site-local/testing-guide/index.html +2 -2
  305. data/site-local/testing-guide/partials/configuration.html +31 -4
  306. data/site-local/testing-guide/partials/conventions.html +509 -8
  307. data/site-local/testing-guide/partials/directives.html +4 -3
  308. data/site-local/testing-guide/partials/example.html +2 -2
  309. data/site-local/testing-guide/partials/index.html +2 -2
  310. data/site-local/testing-guide/partials/overview.html +30 -12
  311. data/site-local/testing-guide/partials/variables.html +169 -4
  312. data/site-local/testing-guide/test-cases.html +2 -2
  313. data/site-local/testing-guide/test-sample.html +2 -2
  314. data/site-local/testing-guide/test-suite-anatomy.html +2 -2
  315. data/spec/integration/actionator_file_operations_spec.rb +91 -1
  316. data/spec/integration/build_step_doctor_spec.rb +270 -0
  317. data/spec/integration/c_extractor_composition_spec.rb +254 -4
  318. data/spec/integration/compile_commands_json_db_spec.rb +1 -1
  319. data/spec/integration/configurator_validation_spec.rb +1 -1
  320. data/spec/integration/dependencies/dependency_tracker_cache_hardening_spec.rb +26 -0
  321. data/spec/integration/dependencies/dependency_tracker_core_spec.rb +22 -0
  322. data/spec/integration/includes_extraction_spec.rb +27 -14
  323. data/spec/integration/launcher_handoff_spec.rb +297 -0
  324. data/spec/integration/mixin_loading_spec.rb +1 -1
  325. data/spec/integration/module_generator_spec.rb +3 -3
  326. data/spec/integration/nested_test_artifacts_spec.rb +99 -0
  327. data/spec/integration/partial_files_preprocessing_spec.rb +128 -0
  328. data/spec/integration/partials_carry_spec.rb +520 -0
  329. data/spec/integration/partials_declarations_spec.rb +655 -0
  330. data/spec/integration/partials_fallback_preprocessing_spec.rb +65 -0
  331. data/spec/integration/partials_function_pointers_spec.rb +277 -0
  332. data/spec/integration/partials_header_composition_spec.rb +268 -35
  333. data/spec/integration/partials_macro_decorators_spec.rb +267 -0
  334. data/spec/integration/partials_module_resolution_spec.rb +33 -23
  335. data/spec/integration/partials_symbol_linkage_spec.rb +13 -0
  336. data/spec/integration/path_intake_scenarios_spec.rb +101 -0
  337. data/spec/integration/path_length_reporting_spec.rb +64 -0
  338. data/spec/integration/path_scenarios_spec.rb +399 -0
  339. data/spec/integration/quote_include_isolator_spec.rb +57 -1
  340. data/spec/integration/report_build_warnings_log_spec.rb +1 -1
  341. data/spec/integration/report_tests_log_factory_spec.rb +1 -1
  342. data/spec/integration/test_build_parallel_barrier_spec.rb +1 -1
  343. data/spec/integration/test_executable_manifest_spec.rb +1 -1
  344. data/spec/integration/test_includes_extractinator_spec.rb +69 -3
  345. data/spec/integration/test_naming_spec.rb +201 -0
  346. data/spec/integration/test_source_file_checks_spec.rb +168 -0
  347. data/spec/integration/tool_executor_spec.rb +1 -1
  348. data/spec/integration/tool_validator_spec.rb +3 -3
  349. data/spec/integration/upgrade_docs_spec.rb +84 -0
  350. data/spec/integration/vendor_copy_transient_io_retry_spec.rb +74 -5
  351. data/spec/integration/win_long_paths_probe_spec.rb +46 -0
  352. data/spec/integration/win_path_limit_spec.rb +53 -0
  353. data/spec/integration/windows_registry_query_tool_spec.rb +41 -0
  354. data/spec/support/file_tree_helper.rb +88 -0
  355. data/spec/support/integration/configurator_integration_helper.rb +14 -9
  356. data/spec/support/integration/dependency_tracker_integration_helper.rb +1 -1
  357. data/spec/support/integration/partial_files_harness.rb +181 -0
  358. data/spec/support/integration/partials_generation_integration_helper.rb +239 -143
  359. data/spec/support/integration/path_scenario_harness.rb +175 -0
  360. data/spec/support/integration/spec_integration_helper.rb +9 -4
  361. data/spec/support/integration/test_includes_harness.rb +69 -37
  362. data/spec/support/integration/tool_executor_integration_helper.rb +14 -2
  363. data/spec/support/spec_helper.rb +2 -0
  364. data/spec/support/system/spec_system_helper.rb +7 -6
  365. data/spec/support/system/system_context.rb +21 -3
  366. data/spec/support/working_dir_tracking.rb +49 -0
  367. data/spec/system/build_output_mirroring_spec.rb +2 -2
  368. data/spec/system/bullseye_deployment_spec.rb +2 -0
  369. data/spec/system/conditional_mock_includes_spec.rb +1 -1
  370. data/spec/system/delta_builds_spec.rb +163 -23
  371. data/spec/system/encoding_stress_spec.rb +4 -4
  372. data/spec/system/example_wondrous_forest_spec.rb +2 -2
  373. data/spec/system/gcov_deployment_spec.rb +3 -0
  374. data/spec/system/header_include_path_validation_spec.rb +4 -4
  375. data/spec/system/header_search_paths_spec.rb +1083 -0
  376. data/spec/system/launcher_handoff_spec.rb +82 -0
  377. data/spec/system/mock_include_folders_spec.rb +212 -0
  378. data/spec/system/mockable_header_reassembly_spec.rb +184 -0
  379. data/spec/system/parent_directory_reference_spec.rb +5 -3
  380. data/spec/system/partials_carry_spec.rb +581 -0
  381. data/spec/system/partials_delta_builds_spec.rb +280 -0
  382. data/spec/system/partials_function_pointers_spec.rb +106 -0
  383. data/spec/system/partials_macro_decorators_spec.rb +127 -0
  384. data/spec/system/partials_module_disambiguation_spec.rb +125 -0
  385. data/spec/system/path_handling_probes_spec.rb +196 -0
  386. data/spec/system/pinned_thread_count_spec.rb +4 -4
  387. data/spec/system/preprocessing_fallback_conditionals_spec.rb +1 -1
  388. data/spec/system/preprocessing_parameterized_tests_spec.rb +1 -1
  389. data/spec/system/rake_release_task_path_disambiguation_spec.rb +6 -6
  390. data/spec/system/rake_test_task_path_disambiguation_spec.rb +85 -0
  391. data/spec/system/short_build_paths_spec.rb +87 -0
  392. data/spec/system/sibling_header_collision_spec.rb +30 -6
  393. data/spec/system/special_path_characters_spec.rb +86 -0
  394. data/spec/system/support/bullseye_common_test_cases.rb +42 -0
  395. data/spec/system/support/common_test_cases.rb +23 -21
  396. data/spec/system/support/gcov_common_test_cases.rb +37 -9
  397. data/spec/system/support/gcov_partials_test_cases.rb +48 -0
  398. data/spec/system/support/sanitize_common_test_cases.rb +2 -2
  399. data/spec/system/support/valgrind_common_test_cases.rb +12 -12
  400. data/spec/system/test_build_layout_spec.rb +209 -0
  401. data/spec/system/test_pipeline_stop_points_spec.rb +4 -4
  402. data/spec/system/test_runner_system_include_spec.rb +1 -1
  403. data/spec/system/test_source_file_directive_spec.rb +64 -5
  404. data/spec/units/bin/actionator_spec.rb +14 -17
  405. data/spec/units/bin/app_cfg_spec.rb +37 -0
  406. data/spec/units/bin/cli_handler_spec.rb +282 -6
  407. data/spec/units/bin/cli_helper_spec.rb +116 -45
  408. data/spec/units/bin/installation_selector_spec.rb +114 -0
  409. data/spec/units/bin/launchinator_spec.rb +171 -0
  410. data/spec/units/bin/path_validator_spec.rb +10 -0
  411. data/spec/units/bin/versionator_spec.rb +38 -6
  412. data/spec/units/build_log_writer_spec.rb +57 -0
  413. data/spec/units/c_extractor/c_extractor_code_text_spec.rb +67 -10
  414. data/spec/units/c_extractor/c_extractor_declarations_spec.rb +501 -4
  415. data/spec/units/c_extractor/c_extractor_declarator_spec.rb +245 -0
  416. data/spec/units/c_extractor/c_extractor_defined_type_spec.rb +45 -0
  417. data/spec/units/c_extractor/c_extractor_definitions_spec.rb +163 -3
  418. data/spec/units/c_extractor/c_extractor_functions_spec.rb +462 -21
  419. data/spec/units/c_extractor/c_extractor_preprocessing_spec.rb +39 -0
  420. data/spec/units/c_extractor/c_extractor_spec.rb +4 -4
  421. data/spec/units/c_extractor/c_extractor_types_spec.rb +163 -0
  422. data/spec/units/c_identifier_spec.rb +35 -0
  423. data/spec/units/config/build_root_policy_spec.rb +61 -0
  424. data/spec/units/config/configurator_builder_spec.rb +61 -6
  425. data/spec/units/config/configurator_paths_validator_spec.rb +292 -0
  426. data/spec/units/config/configurator_setup_spec.rb +80 -68
  427. data/spec/units/config/configurator_spec.rb +54 -6
  428. data/spec/units/config/configurator_validator_spec.rb +1 -172
  429. data/spec/units/dependencies/dependency_cache_store_spec.rb +98 -2
  430. data/spec/units/dependencies/dependency_debug_tree_spec.rb +1 -1
  431. data/spec/units/dependencies/dependency_hasher_spec.rb +42 -1
  432. data/spec/units/dependencies/dependency_path_normalizer_spec.rb +1 -1
  433. data/spec/units/dependencies/dependency_tracker_spec.rb +28 -1
  434. data/spec/units/dependencies/dependinator_spec.rb +17 -2
  435. data/spec/units/diagnostics/build_step_doctor_spec.rb +170 -0
  436. data/spec/units/diagnostics/duplicate_symbol_specialist_spec.rb +117 -0
  437. data/spec/units/diagnostics/header_collision_specialist_spec.rb +267 -0
  438. data/spec/units/diagnostics/include_depth_specialist_spec.rb +137 -0
  439. data/spec/units/diagnostics/missing_symbol_specialist_spec.rb +154 -0
  440. data/spec/units/diagnostics/partial_name_specialist_spec.rb +129 -0
  441. data/spec/units/diagnostics/toolchain_output_spec.rb +86 -0
  442. data/spec/units/encodinator_spec.rb +3 -4
  443. data/spec/units/filename_extension_spec.rb +11 -0
  444. data/spec/units/filesystem/build_roots_spec.rb +131 -0
  445. data/spec/units/filesystem/build_subpath_spec.rb +235 -0
  446. data/spec/units/filesystem/destination_collision_spec.rb +30 -0
  447. data/spec/units/{file_finder_helper_spec.rb → filesystem/file_finder_helper_spec.rb} +126 -1
  448. data/spec/units/filesystem/file_finder_spec.rb +845 -0
  449. data/spec/units/{file_path_collection_utils_spec.rb → filesystem/file_path_collection_utils_spec.rb} +181 -1
  450. data/spec/units/{file_path_utils_spec.rb → filesystem/file_path_utils_spec.rb} +435 -185
  451. data/spec/units/filesystem/file_system_wrapper_spec.rb +33 -0
  452. data/spec/units/filesystem/file_tree_spec.rb +511 -0
  453. data/spec/units/filesystem/file_tree_windows_spec.rb +78 -0
  454. data/spec/units/{file_wrapper_spec.rb → filesystem/file_wrapper_spec.rb} +286 -18
  455. data/spec/units/{path_matcher_spec.rb → filesystem/path_matcher_spec.rb} +48 -1
  456. data/spec/units/{path_mirror_spec.rb → filesystem/path_mirror_spec.rb} +32 -4
  457. data/spec/units/filesystem/project_paths_spec.rb +147 -0
  458. data/spec/units/filesystem/test_build_layout_spec.rb +216 -0
  459. data/spec/units/filesystem/win_long_paths_spec.rb +204 -0
  460. data/spec/units/filesystem/win_path_prober_spec.rb +158 -0
  461. data/spec/units/filesystem/working_dir_spec.rb +71 -0
  462. data/spec/units/generators/generator_helper_spec.rb +0 -60
  463. data/spec/units/generators/generator_mocks_spec.rb +13 -0
  464. data/spec/units/generators/generator_partials_spec.rb +656 -55
  465. data/spec/units/generators/generator_spec.rb +38 -6
  466. data/spec/units/generators/generator_test_results_backtrace_spec.rb +50 -46
  467. data/spec/units/generators/generator_test_results_spec.rb +1 -1
  468. data/spec/units/generators/generator_test_runner_spec.rb +9 -5
  469. data/spec/units/generators/partial_source_writer_spec.rb +129 -0
  470. data/spec/units/handoff_spec.rb +205 -0
  471. data/spec/units/includes/header_search_spec.rb +406 -0
  472. data/spec/units/includes/include_factory_spec.rb +23 -6
  473. data/spec/units/includes/include_pathinator_spec.rb +118 -8
  474. data/spec/units/includes/include_spec.rb +14 -0
  475. data/spec/units/includes/includes_spec.rb +176 -19
  476. data/spec/units/installation_spec.rb +228 -0
  477. data/spec/units/library_resolver_spec.rb +157 -0
  478. data/spec/units/loginator_spec.rb +31 -0
  479. data/spec/units/mock_locator_spec.rb +275 -6
  480. data/spec/units/partials/include_groups_spec.rb +42 -0
  481. data/spec/units/partials/partializer_config_spec.rb +32 -0
  482. data/spec/units/partials/partializer_helper_carry_spec.rb +661 -0
  483. data/spec/units/partials/partializer_helper_interface_extras_spec.rb +396 -0
  484. data/spec/units/partials/partializer_helper_spec.rb +529 -277
  485. data/spec/units/partials/partializer_reconciler_spec.rb +661 -0
  486. data/spec/units/partials/partializer_spec.rb +1579 -270
  487. data/spec/units/partials/partializer_utils_spec.rb +269 -232
  488. data/spec/units/partials/partials_rename_spec.rb +160 -0
  489. data/spec/units/partials_manager_spec.rb +561 -251
  490. data/spec/units/plugins/bullseye_spec.rb +49 -2
  491. data/spec/units/plugins/console_reportinator_spec.rb +73 -26
  492. data/spec/units/plugins/dependencies_spec.rb +33 -7
  493. data/spec/units/plugins/dependency_spec_spec.rb +17 -0
  494. data/spec/units/plugins/gcov_spec.rb +28 -3
  495. data/spec/units/plugins/gcovr_reportinator_spec.rb +19 -47
  496. data/spec/units/plugins/gcovr_thresholds_spec.rb +95 -0
  497. data/spec/units/plugins/module_generator_spec.rb +5 -5
  498. data/spec/units/plugins/report_build_warnings_log_spec.rb +3 -3
  499. data/spec/units/plugins/report_log_writer_plugin_spec.rb +10 -1
  500. data/spec/units/plugins/report_tests_raw_output_log_spec.rb +13 -2
  501. data/spec/units/plugins/report_tests_teamcity_stdout_spec.rb +77 -3
  502. data/spec/units/plugins/reportgenerator_reportinator_spec.rb +52 -4
  503. data/spec/units/plugins/sanitize_records_spec.rb +3 -1
  504. data/spec/units/plugins/sanitize_spec.rb +1 -1
  505. data/spec/units/plugins/valgrind_spec.rb +23 -8
  506. data/spec/units/preprocess/preprocessinator_code_finder_spec.rb +73 -10
  507. data/spec/units/preprocess/preprocessinator_comment_stripper_spec.rb +1 -1
  508. data/spec/units/preprocess/preprocessinator_file_assembler_spec.rb +125 -37
  509. data/spec/units/preprocess/preprocessinator_includes_handler_spec.rb +15 -0
  510. data/spec/units/preprocess/preprocessinator_reconstructor_spec.rb +197 -0
  511. data/spec/units/preprocess/preprocessinator_spec.rb +153 -95
  512. data/spec/units/rake_app/rakefile_component_resolver_spec.rb +21 -0
  513. data/spec/units/release_build_executor_spec.rb +53 -14
  514. data/spec/units/release_build_planner_spec.rb +15 -3
  515. data/spec/units/reportinator_spec.rb +5 -5
  516. data/spec/units/setupinator_spec.rb +51 -0
  517. data/spec/units/standin_headerinator_spec.rb +55 -9
  518. data/spec/units/test_build_executor_spec.rb +842 -166
  519. data/spec/units/test_build_planner_spec.rb +205 -15
  520. data/spec/units/test_build_setup_spec.rb +179 -30
  521. data/spec/units/test_context_extractor_spec.rb +36 -2
  522. data/spec/units/test_derived_search_paths_spec.rb +259 -0
  523. data/spec/units/test_file_preprocessinator_spec.rb +17 -1
  524. data/spec/units/test_includes_extractinator_spec.rb +61 -9
  525. data/spec/units/test_invoker/objects_wiring_spec.rb +24 -4
  526. data/spec/units/test_invoker/partial_files_preprocessinator_spec.rb +264 -0
  527. data/spec/units/test_invoker/test_substitutions_spec.rb +122 -0
  528. data/spec/units/test_invoker_spec.rb +14 -1
  529. data/spec/units/test_invoker_types_spec.rb +8 -7
  530. data/spec/units/test_pipeline_manager_spec.rb +54 -13
  531. data/spec/units/test_runner_generatinator_spec.rb +93 -1
  532. data/spec/units/test_search_paths_spec.rb +73 -5
  533. data/spec/units/test_source_file_directive_resolver_spec.rb +38 -7
  534. data/spec/units/tools/default_tools_quoting_spec.rb +117 -0
  535. data/spec/units/tools/shell_quoting_spec.rb +76 -0
  536. data/spec/units/{tool_executor_helper_spec.rb → tools/tool_executor_helper_spec.rb} +1 -1
  537. data/spec/units/{tool_executor_spec.rb → tools/tool_executor_spec.rb} +27 -1
  538. data/spec/units/{tool_validator_spec.rb → tools/tool_validator_spec.rb} +110 -1
  539. data/spec/units/windows_registry_query_tool_spec.rb +53 -0
  540. data/spec/units/yaml_wrapper_spec.rb +11 -0
  541. metadata +265 -36
  542. data/lib/ceedling/file_finder_helper.rb +0 -127
  543. data/lib/ceedling/file_path_collection_utils.rb +0 -164
  544. data/spec/units/file_finder_spec.rb +0 -495
  545. /data/lib/ceedling/{tool_executor_helper.rb → tools/tool_executor_helper.rb} +0 -0
@@ -8,6 +8,7 @@
8
8
 
9
9
  require 'set'
10
10
  require 'spec_helper'
11
+ require 'timeout'
11
12
  require 'ceedling/partials/partializer_helper'
12
13
  require 'ceedling/partials/partializer_utils'
13
14
  require 'ceedling/partials/partials'
@@ -18,18 +19,14 @@ require 'ostruct'
18
19
  describe PartializerHelper do
19
20
  before(:each) do
20
21
  @partializer_utils = double("PartializerUtils")
21
- @c_extractor = double("CExtractor")
22
22
  @c_extractor_declarations = double("CExtractorDeclarations")
23
- @file_path_utils = double("FilePathUtils")
24
23
  @parsing_parcels = ParsingParcels.new
25
24
  @loginator = double("Loginator").as_null_object
26
25
 
27
26
  @helper = described_class.new(
28
27
  {
29
28
  :partializer_utils => @partializer_utils,
30
- :c_extractor => @c_extractor,
31
29
  :c_extractor_declarations => @c_extractor_declarations,
32
- :file_path_utils => @file_path_utils,
33
30
  :parsing_parcels => @parsing_parcels,
34
31
  :loginator => @loginator
35
32
  }
@@ -276,130 +273,89 @@ describe PartializerHelper do
276
273
 
277
274
  context "#associate_function_line_numbers" do
278
275
  before(:each) do
279
- @name = 'TestModule'
280
- @filepath = '/path/to/module.c'
281
- @preprocessed_filepath = '/build/preproc/module_TestModule.i'
282
-
283
- allow(@file_path_utils).to receive(:form_preprocessed_file_raw_directives_only_filepath)
284
- .with(@filepath, @name)
285
- .and_return(@preprocessed_filepath)
276
+ @filepath = '/path/to/module.c'
277
+ @raw_filepath = '/build/preproc/directives_only/raw/module.c'
286
278
 
287
279
  allow(@partializer_utils).to receive(:stamp_source_filepaths)
288
280
  allow(@partializer_utils).to receive(:format_line_number_list).and_return([])
281
+ allow(@partializer_utils).to receive(:locate_functions_in_source).and_return([])
282
+ allow(@partializer_utils).to receive(:locate_functions_via_preprocessed).and_return([])
289
283
  end
290
284
 
291
- it "calls stamp_source_filepaths for empty funcs with fallback: false" do
292
- expect(@partializer_utils).to receive(:stamp_source_filepaths).with([], @filepath)
293
-
294
- @helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: false)
295
- end
296
-
297
- it "calls stamp_source_filepaths for empty funcs with fallback: true" do
298
- expect(@partializer_utils).to receive(:stamp_source_filepaths).with([], @filepath)
299
-
300
- @helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: true)
301
- end
302
-
303
- it "makes no locate calls when funcs is empty" do
304
- expect(@partializer_utils).not_to receive(:locate_function_in_source)
305
- expect(@partializer_utils).not_to receive(:locate_function_via_preprocessed)
306
-
307
- @helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: false)
285
+ def locate(funcs, raw_filepath: @raw_filepath)
286
+ @helper.associate_function_line_numbers( funcs: funcs, filepath: @filepath, raw_filepath: raw_filepath )
308
287
  end
309
288
 
310
- it "constructs preprocessed filepath from name and filepath" do
311
- expect(@file_path_utils).to receive(:form_preprocessed_file_raw_directives_only_filepath)
312
- .with(@filepath, @name)
313
- .and_return(@preprocessed_filepath)
289
+ it "stamps source filepaths with or without a raw copy" do
290
+ expect(@partializer_utils).to receive(:stamp_source_filepaths).with([], @filepath).twice
314
291
 
315
- @helper.associate_function_line_numbers(name: @name, funcs: [], filepath: @filepath, fallback: false)
292
+ locate( [] )
293
+ locate( [], raw_filepath: nil )
316
294
  end
317
295
 
318
- it "uses locate_function_in_source for each func when fallback: true" do
296
+ # The file is read once for all of its functions
297
+ it "locates every function in the source with one call when there is no raw copy" do
319
298
  func1 = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
320
299
  func2 = OpenStruct.new(code_block: 'int bar(int x) {}', line_num: nil)
321
300
 
322
- expect(@partializer_utils).to receive(:locate_function_in_source)
323
- .with(code_block: func1.code_block, filepath: @filepath)
324
- .and_return(10)
325
- expect(@partializer_utils).to receive(:locate_function_in_source)
326
- .with(code_block: func2.code_block, filepath: @filepath)
327
- .and_return(25)
301
+ expect(@partializer_utils).to receive(:locate_functions_in_source)
302
+ .with(code_blocks: [func1.code_block, func2.code_block], filepath: @filepath).once
303
+ .and_return([10, 25])
304
+ expect(@partializer_utils).not_to receive(:locate_functions_via_preprocessed)
328
305
 
329
- @helper.associate_function_line_numbers(name: @name, funcs: [func1, func2], filepath: @filepath, fallback: true)
306
+ locate( [func1, func2], raw_filepath: nil )
330
307
 
331
308
  expect(func1.line_num).to eq(10)
332
309
  expect(func2.line_num).to eq(25)
333
310
  end
334
311
 
335
- it "uses locate_function_via_preprocessed for each func when fallback: false" do
312
+ it "locates every function in the raw copy it is given with one call" do
336
313
  func1 = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
337
314
  func2 = OpenStruct.new(code_block: 'int bar(int x) {}', line_num: nil)
338
315
 
339
- expect(@partializer_utils).to receive(:locate_function_via_preprocessed)
340
- .with(code_block: func1.code_block, filepath: @filepath, preprocessed_filepath: @preprocessed_filepath)
341
- .and_return(10)
342
- expect(@partializer_utils).to receive(:locate_function_via_preprocessed)
343
- .with(code_block: func2.code_block, filepath: @filepath, preprocessed_filepath: @preprocessed_filepath)
344
- .and_return(25)
316
+ expect(@partializer_utils).to receive(:locate_functions_via_preprocessed)
317
+ .with(code_blocks: [func1.code_block, func2.code_block], filepath: @filepath, preprocessed_filepath: @raw_filepath).once
318
+ .and_return([10, 25])
319
+ expect(@partializer_utils).not_to receive(:locate_functions_in_source)
345
320
 
346
- @helper.associate_function_line_numbers(name: @name, funcs: [func1, func2], filepath: @filepath, fallback: false)
321
+ locate( [func1, func2] )
347
322
 
348
323
  expect(func1.line_num).to eq(10)
349
324
  expect(func2.line_num).to eq(25)
350
325
  end
351
326
 
352
- it "sets line_num to nil when locate_function_via_preprocessed returns nil" do
327
+ it "sets line_num to nil for a function that isn't found" do
353
328
  func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
354
329
 
355
- allow(@partializer_utils).to receive(:locate_function_via_preprocessed).and_return(nil)
330
+ allow(@partializer_utils).to receive(:locate_functions_via_preprocessed).and_return([nil])
356
331
 
357
- @helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: false)
332
+ locate( [func] )
358
333
 
359
334
  expect(func.line_num).to be_nil
360
335
  end
361
336
 
362
- it "does not call locate_function_via_preprocessed when fallback: true" do
363
- func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
364
-
365
- expect(@partializer_utils).not_to receive(:locate_function_via_preprocessed)
366
- allow(@partializer_utils).to receive(:locate_function_in_source).and_return(1)
367
-
368
- @helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: true)
369
- end
370
-
371
- it "does not call locate_function_in_source when fallback: false" do
372
- func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
373
-
374
- expect(@partializer_utils).not_to receive(:locate_function_in_source)
375
- allow(@partializer_utils).to receive(:locate_function_via_preprocessed).and_return(1)
376
-
377
- @helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: false)
378
- end
379
-
380
337
  it "calls format_line_number_list with funcs and passes result to loginator" do
381
338
  func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil, name: 'foo')
382
339
 
383
- allow(@partializer_utils).to receive(:locate_function_via_preprocessed).and_return(5)
340
+ allow(@partializer_utils).to receive(:locate_functions_via_preprocessed).and_return([5])
384
341
 
385
342
  expect(@partializer_utils).to receive(:format_line_number_list).with([func]).and_return(["foo(): 5"])
386
343
 
387
- @helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: false)
344
+ locate( [func] )
388
345
  end
346
+ end
389
347
 
390
- it "forwards the constructed preprocessed_filepath to locate_function_via_preprocessed" do
391
- func = OpenStruct.new(code_block: 'void foo(void) {}', line_num: nil)
392
-
393
- custom_preproc = '/custom/preproc/output.i'
394
- allow(@file_path_utils).to receive(:form_preprocessed_file_raw_directives_only_filepath)
395
- .with(@filepath, @name)
396
- .and_return(custom_preproc)
397
-
398
- expect(@partializer_utils).to receive(:locate_function_via_preprocessed)
399
- .with(hash_including(preprocessed_filepath: custom_preproc))
400
- .and_return(nil)
348
+ # Carrying reads the names kept code uses. GCC and Clang accept '$' in one.
349
+ context "#_statement_references" do
350
+ it "reads names holding '$', past members and tags" do
351
+ expect( @helper._statement_references( "x$1 = h$2( s.m$3, (struct t$4 *)p$5 );" ).to_a ).to contain_exactly( 'x$1', 'h$2', 's', 'p$5' )
352
+ end
353
+ end
401
354
 
402
- @helper.associate_function_line_numbers(name: @name, funcs: [func], filepath: @filepath, fallback: false)
355
+ # A body's own locals shadow a helper of the same name, so they don't count as uses
356
+ context "#_locals" do
357
+ it "reads locals whose names hold '$'" do
358
+ expect( @helper._locals( "{ int h$ = 1; int *q$; struct s$t v; int k; }" ) ).to include( 'h$', 'q$', 'v', 'k' )
403
359
  end
404
360
  end
405
361
 
@@ -422,11 +378,9 @@ describe PartializerHelper do
422
378
  allow(@c_extractor_declarations).to receive(:try_extract_variable)
423
379
  .and_return([false, nil])
424
380
 
425
- expect(@partializer_utils).not_to receive(:replace_declaration_with_noop)
426
- expect(@partializer_utils).not_to receive(:rename_c_identifier)
427
-
428
381
  result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
429
382
  expect(result).to eq([])
383
+ expect(func.code_block).to eq('void simple(void) { return; }')
430
384
  end
431
385
 
432
386
  it "returns empty array when variable is found but is non-static" do
@@ -446,86 +400,11 @@ describe PartializerHelper do
446
400
  allow(@c_extractor_declarations).to receive(:try_extract_variable)
447
401
  .and_return([true, [non_static_var]], [false, nil])
448
402
 
449
- expect(@partializer_utils).not_to receive(:replace_declaration_with_noop)
450
- expect(@partializer_utils).not_to receive(:rename_c_identifier)
451
-
452
403
  result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
453
404
  expect(result).to eq([])
405
+ expect(func.code_block).to eq('void simple(void) { int x; return x; }')
454
406
  end
455
407
 
456
- it "delegates noop and rename calls to utils for a static variable" do
457
- func = OpenStruct.new(
458
- name: 'process',
459
- code_block: 'void process(void) { static int count; count = 0; }',
460
- body: '{ static int count; count = 0; }'
461
- )
462
-
463
- var = OpenStruct.new(
464
- original: 'static int count',
465
- name: 'count',
466
- decorators: ['static'],
467
- text: 'int count;'
468
- )
469
-
470
- allow(@c_extractor_declarations).to receive(:try_extract_variable)
471
- .and_return([true, [var]], [false, nil])
472
-
473
- placeholder = '__CEEDLING_NOOP_PROCESS_COUNT__'
474
- noop_text = "(void)0; /* `#{placeholder}` ... */"
475
-
476
- allow(@partializer_utils).to receive(:replace_declaration_with_noop)
477
- .and_return(noop_text)
478
- allow(@partializer_utils).to receive(:rename_c_identifier)
479
- .and_return('')
480
-
481
- result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
482
-
483
- expect(@partializer_utils).to have_received(:replace_declaration_with_noop).exactly(2).times
484
- expect(@partializer_utils).to have_received(:rename_c_identifier).exactly(3).times
485
- expect(result.first.name).to eq('partial_process_count')
486
- end
487
-
488
- it "delegates compound noop and rename calls to utils for a compound static declaration" do
489
- func = OpenStruct.new(
490
- name: 'calc',
491
- code_block: 'void calc(void) { static int a, b; a = 0; b = 1; }',
492
- body: '{ static int a, b; a = 0; b = 1; }'
493
- )
494
-
495
- shared_original = 'static int a, b;'
496
- var_a = OpenStruct.new(
497
- original: shared_original,
498
- name: 'a',
499
- decorators: ['static'],
500
- text: 'int a;'
501
- )
502
- var_b = OpenStruct.new(
503
- original: shared_original,
504
- name: 'b',
505
- decorators: ['static'],
506
- text: 'int b;'
507
- )
508
-
509
- # Scanner returns both vars in one call, then fails
510
- allow(@c_extractor_declarations).to receive(:try_extract_variable)
511
- .and_return([true, [var_a, var_b]], [false, nil])
512
-
513
- placeholder = '__CEEDLING_NOOP_CALC_A__'
514
- noops = "(void)0; (void)0; /* `#{placeholder}` ... */"
515
-
516
- allow(@partializer_utils).to receive(:replace_compound_declaration_with_noops)
517
- .and_return(noops)
518
- allow(@partializer_utils).to receive(:rename_c_identifier)
519
- .and_return('')
520
-
521
- result = @helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
522
-
523
- expect(@partializer_utils).to have_received(:replace_compound_declaration_with_noops)
524
- .with(anything, shared_original, placeholder, 2)
525
- .exactly(2).times
526
- expect(@partializer_utils).to have_received(:rename_c_identifier).exactly(6).times
527
- expect(result.map(&:name)).to contain_exactly('partial_calc_a', 'partial_calc_b')
528
- end
529
408
  end
530
409
 
531
410
  context "end-to-end happy day tests" do
@@ -542,9 +421,7 @@ describe PartializerHelper do
542
421
  PartializerHelper.new(
543
422
  {
544
423
  :partializer_utils => real_utils,
545
- :c_extractor => double("CExtractor").as_null_object,
546
424
  :c_extractor_declarations => CExtractorDeclarations.new({ c_extractor_code_text: CExtractorCodeText.new() }).tap(&:setup),
547
- :file_path_utils => double("FilePathUtils"),
548
425
  :parsing_parcels => ParsingParcels.new,
549
426
  :loginator => double("Loginator").as_null_object
550
427
  }
@@ -574,6 +451,91 @@ describe PartializerHelper do
574
451
  expect(func.code_block).to include('static int count')
575
452
  end
576
453
 
454
+ # A mocked Partial keeps a helper's promoted statics with the helper, so each knows its function
455
+ it "names the function each promoted variable came from" do
456
+ func = OpenStruct.new(
457
+ name: 'process',
458
+ body: "{\n static int count, total;\n return count + total;\n}",
459
+ code_block: "void process(void) {\n static int count, total;\n return count + total;\n}"
460
+ )
461
+
462
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
463
+
464
+ expect(result.map(&:promoted_from)).to eq(['process', 'process'])
465
+ end
466
+
467
+ # A function pointer's declarator wraps its name, so the new name has to reach it too
468
+ it "promotes a function-scope static function pointer under its new name, declarator and all" do
469
+ func = OpenStruct.new(
470
+ name: 'fire',
471
+ body: "{\n static int (*cache)(int) = 0;\n return cache(1);\n}",
472
+ code_block: "int fire(void) {\n static int (*cache)(int) = 0;\n return cache(1);\n}"
473
+ )
474
+
475
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
476
+
477
+ expect(result.map { |v| [v.name, v.type, v.declarator] }).to eq [['partial_fire_cache', 'int', '(*partial_fire_cache)(int)']]
478
+ expect(result.first.text).to include('(*partial_fire_cache)(int)')
479
+ expect(func.code_block).to include('return partial_fire_cache(1);')
480
+ end
481
+
482
+ it "promotes a function-scope static function pointer whose name sits in redundant parentheses" do
483
+ func = OpenStruct.new(
484
+ name: 'fire',
485
+ body: "{\n static int (*(cache))(int) = 0;\n return cache(1);\n}",
486
+ code_block: "int fire(void) {\n static int (*(cache))(int) = 0;\n return cache(1);\n}"
487
+ )
488
+
489
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
490
+
491
+ expect(result.map { |v| [v.name, v.declarator] }).to eq [['partial_fire_cache', '(*(partial_fire_cache))(int)']]
492
+ end
493
+
494
+ # A macro may declare a static whole, and one the extractor reads no name from stays in place
495
+ it "leaves a function-scope static it can't name in the body" do
496
+ func = OpenStruct.new(
497
+ name: 'tally',
498
+ body: "{\n static ARR_OF(int, hits)[3];\n static int n;\n return n;\n}",
499
+ code_block: "int tally(void) {\n static ARR_OF(int, hits)[3];\n static int n;\n return n;\n}"
500
+ )
501
+
502
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
503
+
504
+ expect(result.map(&:name)).to eq ['partial_tally_n']
505
+ expect(func.code_block).to include('static ARR_OF(int, hits)[3];')
506
+ end
507
+
508
+ # Renaming part of a statement would leave the rest of it unpromoted, so the whole one stays
509
+ it "leaves a compound static whole when it can't name one of its variables" do
510
+ func = OpenStruct.new(
511
+ name: 'tally',
512
+ body: "{\n static ARR_OF(int, hits)[3], n;\n static int m;\n return n + m;\n}",
513
+ code_block: "int tally(void) {\n static ARR_OF(int, hits)[3], n;\n static int m;\n return n + m;\n}"
514
+ )
515
+
516
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
517
+
518
+ expect(result.map(&:name)).to eq ['partial_tally_m']
519
+ expect(func.code_block).to include('static ARR_OF(int, hits)[3], n;', 'return n + partial_tally_m;')
520
+ end
521
+
522
+ it "promotes each function pointer of a compound static and an array of them" do
523
+ func = OpenStruct.new(
524
+ name: 'fire',
525
+ body: "{\n static int (*a)(int), (*b)(int);\n static int (*t[2])(int) = { 0 };\n return a(1) + b(2) + t[0](3);\n}",
526
+ code_block: "int fire(void) {\n static int (*a)(int), (*b)(int);\n static int (*t[2])(int) = { 0 };\n return a(1) + b(2) + t[0](3);\n}"
527
+ )
528
+
529
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
530
+
531
+ expect(result.map { |v| [v.name, v.declarator] }).to eq [
532
+ ['partial_fire_a', '(*partial_fire_a)(int)'],
533
+ ['partial_fire_b', '(*partial_fire_b)(int)'],
534
+ ['partial_fire_t', '(*partial_fire_t[2])(int)']
535
+ ]
536
+ expect(func.code_block).to include('return partial_fire_a(1) + partial_fire_b(2) + partial_fire_t[0](3);')
537
+ end
538
+
577
539
  it "does not modify code_block when function body has only non-static variables" do
578
540
  original_code_block = "void simple(void) {\n int x = 0;\n return x;\n}"
579
541
 
@@ -623,6 +585,148 @@ describe PartializerHelper do
623
585
  # Replacement no-op with (incomplete) comment
624
586
  expect(func.code_block).to include('(void)0; (void)0; /* `static int a, b;` replaced with no-op')
625
587
  end
588
+
589
+ it "promotes each variable of a compound static whose first one has an initializer" do
590
+ func = OpenStruct.new(
591
+ name: 'calc',
592
+ body: "{\n static int x = 0, y;\n y++;\n return x + y;\n}",
593
+ code_block: "int calc(void) {\n static int x = 0, y;\n y++;\n return x + y;\n}"
594
+ )
595
+
596
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
597
+
598
+ expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_x', 'int partial_calc_x = 0;'], ['partial_calc_y', 'int partial_calc_y;']]
599
+ expect(func.code_block.scan('(void)0;').length).to eq(2)
600
+ expect(func.code_block).to include('return partial_calc_x + partial_calc_y;')
601
+ end
602
+
603
+ # One declarator's initializer can name another variable of the same statement
604
+ it "renames every variable of a compound static in each one's text" do
605
+ func = OpenStruct.new(
606
+ name: 'calc',
607
+ body: "{\n static int a = 1, *p = &a;\n return *p;\n}",
608
+ code_block: "int calc(void) {\n static int a = 1, *p = &a;\n return *p;\n}"
609
+ )
610
+
611
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
612
+
613
+ expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_a', 'int partial_calc_a = 1;'], ['partial_calc_p', 'int *partial_calc_p = &partial_calc_a;']]
614
+ end
615
+
616
+ it "renames a promoted static named in another one's array size" do
617
+ func = OpenStruct.new(
618
+ name: 'calc',
619
+ body: "{\n static int n = 4, m[sizeof(n)];\n return m[0];\n}",
620
+ code_block: "int calc(void) {\n static int n = 4, m[sizeof(n)];\n return m[0];\n}"
621
+ )
622
+
623
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
624
+
625
+ expect(result.map { |v| [v.name, v.array_suffix] }).to eq [['partial_calc_n', ''], ['partial_calc_m', '[sizeof(partial_calc_n)]']]
626
+ end
627
+
628
+ # A static's initializer can name one an earlier statement declares
629
+ it "renames a promoted static named by a later statement" do
630
+ func = OpenStruct.new(
631
+ name: 'calc',
632
+ body: "{\n static int a = 1;\n static int *p = &a;\n return *p;\n}",
633
+ code_block: "int calc(void) {\n static int a = 1;\n static int *p = &a;\n return *p;\n}"
634
+ )
635
+
636
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
637
+
638
+ expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_a', 'int partial_calc_a = 1;'], ['partial_calc_p', 'int *partial_calc_p = &partial_calc_a;']]
639
+ expect(func.code_block.scan('(void)0;').length).to eq(2)
640
+ expect(func.code_block).to include('return *partial_calc_p;')
641
+ end
642
+
643
+ # Under fallback preprocessing a code block keeps its comments, while the body blanks them
644
+ it "promotes a static whose statement holds comments" do
645
+ func = OpenStruct.new(
646
+ name: 'calc',
647
+ body: "{\n static int x = 0;\n static int a, b;\n return x + a + b;\n}",
648
+ code_block: "int calc(void) {\n static int x /* count */ = 0;\n static int a, // first\n b;\n return x + a + b;\n}"
649
+ )
650
+
651
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
652
+
653
+ expect(result.map(&:name)).to eq ['partial_calc_x', 'partial_calc_a', 'partial_calc_b']
654
+ expect(func.code_block.scan('(void)0;').length).to eq(3)
655
+ expect(func.code_block).not_to match(/^\s*static int/)
656
+ expect(func.code_block).to include('return partial_calc_x + partial_calc_a + partial_calc_b;')
657
+ end
658
+
659
+ # Each no-op stands where its statement did, and a statement over several lines keeps them,
660
+ # comments included, so coverage lines stay aligned. Line endings pass through as written.
661
+ ["\n", "\r\n"].each do |ending|
662
+ it "keeps a function to its line count with #{ending.inspect} line endings" do
663
+ code = ["int f(void) {", " static struct {", " int n; /* a", " b */", " } st;", " return st.n;", "}"].join( ending )
664
+ func = OpenStruct.new( name: 'f', body: '', code_block: code )
665
+
666
+ real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
667
+
668
+ expect( func.code_block ).to include( 'return partial_f_st.n;' )
669
+ expect( func.code_block.count( "\n" ) ).to eq( code.count( "\n" ) )
670
+ expect( func.code_block.scan( ending ).size ).to eq( code.scan( ending ).size )
671
+ end
672
+ end
673
+
674
+ # The body opens at the first brace outside a literal, and an attribute's string may hold one
675
+ it "promotes a static in a function whose signature holds a brace in a string" do
676
+ func = OpenStruct.new(
677
+ name: 'calc',
678
+ body: "{ static int n = 0; return n; }",
679
+ code_block: "__attribute__((section(\"t{x}\"))) int calc(void) { static int n = 0; return n; }"
680
+ )
681
+
682
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
683
+
684
+ expect(result.map(&:name)).to eq ['partial_calc_n']
685
+ expect(func.code_block).to start_with('__attribute__((section("t{x}"))) int calc(void) { (void)0;')
686
+ expect(func.code_block).to end_with('return partial_calc_n; }')
687
+ end
688
+
689
+ it "promotes a static whose name holds '$'" do
690
+ func = OpenStruct.new(
691
+ name: 'calc',
692
+ body: "{\n static int c$1 = 0;\n int c = c$1;\n return c$1 + c;\n}",
693
+ code_block: "int calc(void) {\n static int c$1 = 0;\n int c = c$1;\n return c$1 + c;\n}"
694
+ )
695
+
696
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
697
+
698
+ expect(result.map { |v| [v.name, v.text] }).to eq [['partial_calc_c$1', 'int partial_calc_c$1 = 0;']]
699
+ expect(func.code_block).to include('int c = partial_calc_c$1;', 'return partial_calc_c$1 + c;')
700
+ end
701
+
702
+ # A tag lives apart from variables, so a static's type keeps a tag another static shares
703
+ it "leaves a struct tag alone when another promoted static shares its name" do
704
+ func = OpenStruct.new(
705
+ name: 'calc',
706
+ body: "{\n static int node = 0;\n static struct node *head = 0;\n return node + (head == 0);\n}",
707
+ code_block: "int calc(void) {\n static int node = 0;\n static struct node *head = 0;\n return node + (head == 0);\n}"
708
+ )
709
+
710
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
711
+
712
+ expect(result.map { |v| [v.name, v.type, v.text] }).to eq [
713
+ ['partial_calc_node', 'int', 'int partial_calc_node = 0;'],
714
+ ['partial_calc_head', 'struct node *', 'struct node *partial_calc_head = 0;']
715
+ ]
716
+ end
717
+
718
+ it "leaves a string literal alone when it renames a promoted static" do
719
+ func = OpenStruct.new(
720
+ name: 'calc',
721
+ body: "{\n static const char *a = \"x\", *b = \"a b\";\n printf(\"a=%s\", a);\n return b[0];\n}",
722
+ code_block: "int calc(void) {\n static const char *a = \"x\", *b = \"a b\";\n printf(\"a=%s\", a);\n return b[0];\n}"
723
+ )
724
+
725
+ result = real_helper.extract_function_scope_static_vars([func], name: 'test', module_name: 'mod', file_type: 'source')
726
+
727
+ expect(result.map(&:text)).to eq ['char *partial_calc_a = "x";', 'char *partial_calc_b = "a b";']
728
+ expect(func.code_block).to include('printf("a=%s", partial_calc_a);')
729
+ end
626
730
  end
627
731
  end
628
732
 
@@ -634,8 +738,8 @@ describe PartializerHelper do
634
738
  OpenStruct.new(name: name, decorators: decorators)
635
739
  end
636
740
 
637
- def make_c_module(funcs)
638
- OpenStruct.new(function_definitions: funcs)
741
+ def make_c_module(funcs, declarations: [])
742
+ OpenStruct.new(function_definitions: funcs, function_declarations: declarations)
639
743
  end
640
744
 
641
745
  def make_pf(type: nil, additions: [], subtractions: [])
@@ -646,6 +750,68 @@ describe PartializerHelper do
646
750
  OpenStruct.new(module: mod, tests: tests, mocks: mocks)
647
751
  end
648
752
 
753
+ ###
754
+ ### validate_function_names_readable()
755
+ ###
756
+
757
+ context "#validate_function_names_readable" do
758
+ def defined(name, signature)
759
+ CExtractorTypes::CFunctionDefinition.new( name: name, signature: signature )
760
+ end
761
+
762
+ it "does not raise when every definition has a name" do
763
+ c_module = CExtractorTypes::CModule.new(
764
+ function_definitions: [defined( 'ticker_get', 'int (*ticker_get(void))(int)' )],
765
+ function_declarations: [CExtractorTypes::CFunctionDeclaration.new( name: 'ticker_count', signature: 'int ticker_count(void);' )]
766
+ )
767
+
768
+ expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }.not_to raise_error
769
+ end
770
+
771
+ it "names the test, the module and the signature of a definition without a name" do
772
+ c_module = CExtractorTypes::CModule.new(
773
+ function_definitions: [defined( 'ticker_count', 'int ticker_count(void)' ), defined( nil, 'int (*ticker_get(void))(int)' )]
774
+ )
775
+
776
+ message = <<~MESSAGE.chomp
777
+ Partial test_ticker::ticker ⏩️ Cannot read the name of the function declared by `int (*ticker_get(void))(int)`.
778
+
779
+ OPTIONS:
780
+ 1. If it returns or takes a function pointer, give that type a name with a typedef and use the name in this declaration.
781
+ 2. If a macro generates the declaration, declare the function directly.
782
+ MESSAGE
783
+
784
+ expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }
785
+ .to raise_error( CeedlingException ) { |error| expect( error.message ).to eq( message ) }
786
+ end
787
+
788
+ # A prototype is written word for word and CMock reads its own name, so neither needs one
789
+ it "leaves a declaration without a name alone" do
790
+ c_module = CExtractorTypes::CModule.new(
791
+ function_declarations: [CExtractorTypes::CFunctionDeclaration.new( name: nil, signature: 'int __count__(void);' )]
792
+ )
793
+
794
+ expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }.not_to raise_error
795
+ end
796
+
797
+ it "collapses whitespace in the signature it shows" do
798
+ c_module = CExtractorTypes::CModule.new( function_definitions: [defined( nil, "int __count__(\n void )" )] )
799
+
800
+ expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }
801
+ .to raise_error( CeedlingException, /declared by `int __count__\( void \)`\./ )
802
+ end
803
+
804
+ # Extraction reads raw bytes, which may hold any character
805
+ it "shows a signature read as raw bytes" do
806
+ signature = "int caf\xC3\xA9$x(void)".b
807
+ c_module = CExtractorTypes::CModule.new( function_definitions: [defined( nil, signature )] )
808
+
809
+ expect( signature.encoding ).to eq( Encoding::BINARY )
810
+ expect { @helper.validate_function_names_readable( c_module, 'test_ticker', 'ticker' ) }
811
+ .to raise_error( CeedlingException, /declared by `int café\$x\(void\)`\./ )
812
+ end
813
+ end
814
+
649
815
  ###
650
816
  ### validate_function_names_exist()
651
817
  ###
@@ -715,6 +881,58 @@ describe PartializerHelper do
715
881
  expect { @helper.validate_function_names_exist(c_module, config, name) }
716
882
  .to raise_error(CeedlingException, /test_mod.*case/)
717
883
  end
884
+
885
+ # A mock of public functions alone reads only the header, which declares functions its
886
+ # source defines (#1427)
887
+ it "does not raise when a mocks name is only declared" do
888
+ name = "test_mod"
889
+ c_module = make_c_module([make_func('helper')], declarations: [make_func('port_read'), make_func('port_write')])
890
+ config = make_config('mod',
891
+ tests: make_pf,
892
+ mocks: make_pf(additions: ['port_read'], subtractions: ['port_write'])
893
+ )
894
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.not_to raise_error
895
+ end
896
+
897
+ it "raises when a mocks name differs only by case from a declared one" do
898
+ name = "test_mod"
899
+ c_module = make_c_module([], declarations: [make_func('port_write')])
900
+ config = make_config('mod', tests: make_pf, mocks: make_pf(subtractions: ['Port_Write']))
901
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /test_mod.*case/)
902
+ end
903
+
904
+ # A Test Partial carries only the functions its module defines
905
+ it "raises when a tests name is only declared" do
906
+ name = "test_mod"
907
+ c_module = make_c_module([], declarations: [make_func('port_write')])
908
+ config = make_config('mod', tests: make_pf(subtractions: ['port_write']), mocks: make_pf)
909
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /test_mod.*port_write/)
910
+ end
911
+
912
+ it "ignores a declaration with no name" do
913
+ name = "test_mod"
914
+ c_module = make_c_module([], declarations: [make_func(nil), make_func('port_write')])
915
+ config = make_config('mod', tests: make_pf, mocks: make_pf(subtractions: ['port_write']))
916
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.not_to raise_error
917
+
918
+ config = make_config('mod', tests: make_pf, mocks: make_pf(subtractions: ['port_nope']))
919
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /port_nope.*does not exist/)
920
+ end
921
+
922
+ # Its body is in another header, which a mock can never replace, so mock selection leaves it out
923
+ it "raises when a mocks name is an inline function the module only declares" do
924
+ name = "test_mod"
925
+ c_module = make_c_module([], declarations: [make_func('port_inl', decorators: ['inline'])])
926
+ config = make_config('mod', tests: make_pf, mocks: make_pf(additions: ['port_inl']))
927
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /port_inl.*does not exist/)
928
+ end
929
+
930
+ it "raises when a mocks name is a declaration whose inline body is elsewhere" do
931
+ name = "test_mod"
932
+ c_module = make_c_module([], declarations: [OpenStruct.new(name: 'port_inl', decorators: [], inline_elsewhere: true)])
933
+ config = make_config('mod', tests: make_pf, mocks: make_pf(additions: ['port_inl']))
934
+ expect { @helper.validate_function_names_exist(c_module, config, name) }.to raise_error(CeedlingException, /port_inl.*does not exist/)
935
+ end
718
936
  end
719
937
 
720
938
  ###
@@ -795,6 +1013,15 @@ describe PartializerHelper do
795
1013
  .not_to raise_error
796
1014
  end
797
1015
 
1016
+ it "checks a PUBLIC mocks subtraction of a function the header only declares" do
1017
+ name = "test_mod"
1018
+ decl = make_func('port_write')
1019
+ c_module = make_c_module([], declarations: [decl])
1020
+ config = make_config('mod', tests: make_pf, mocks: make_pf(type: Partials::PUBLIC, subtractions: ['port_write']))
1021
+ allow(@partializer_utils).to receive(:matches_visibility?).with(decl.decorators, Partials::PUBLIC).and_return(true)
1022
+ expect { @helper.validate_additions_subtractions_visibility(c_module, config, name) }.not_to raise_error
1023
+ end
1024
+
798
1025
  it "raises when PUBLIC subtractions include a private function" do
799
1026
  name = "test_mod"
800
1027
  func = make_func('priv', decorators: ['static'])
@@ -875,10 +1102,6 @@ describe PartializerHelper do
875
1102
  end
876
1103
  end
877
1104
 
878
- ###
879
- ### update_signatures_from_full_expansion()
880
- ###
881
-
882
1105
  context "#validate_fallback_sufficiency" do
883
1106
  # Fallback never runs a compiler, so two module shapes are knowably beyond it. Refusing here
884
1107
  # trades a confusing failure several stages later for a specific one now. Text comes in as a
@@ -983,131 +1206,160 @@ describe PartializerHelper do
983
1206
  end
984
1207
  end
985
1208
 
986
- context "#update_signatures_from_full_expansion" do
1209
+ context "#mark_inline_elsewhere" do
987
1210
  require 'ceedling/c_extractor/c_extractor_types'
988
1211
 
989
- def make_expanded_func(name:, signature:, decorators:, signature_stripped:)
990
- CExtractorTypes::CFunctionDefinition.new(
991
- name: name,
992
- signature: signature,
993
- decorators: decorators,
994
- signature_stripped: signature_stripped
1212
+ def decl(signature)
1213
+ CExtractorTypes::CFunctionDeclaration.new(
1214
+ name: signature[/(\w+)\s*\(/, 1], signature: signature, decorators: signature.start_with?( 'static' ) ? ['static'] : []
995
1215
  )
996
1216
  end
997
1217
 
998
- it "replaces signature fields from expanded function when name matches" do
999
- func = double('func',
1000
- name: 'helper',
1001
- signature: 'MY_STATIC int helper(void)',
1002
- decorators: [],
1003
- signature_stripped: 'int helper(void)'
1004
- )
1005
- allow(func).to receive(:signature=)
1006
- allow(func).to receive(:decorators=)
1007
- allow(func).to receive(:signature_stripped=)
1218
+ # Under C99 the declaring file then holds the external definition
1219
+ it "marks a declaration whose function an included header defines inline" do
1220
+ twice = decl( 'int engine_get_twice(void);' )
1221
+ tick = decl( 'int board_tick(void);' )
1222
+ text = "# 1 \"src/engine_api.h\" 1\nint engine_get(void);\ninline int engine_get_twice(void)\n{\n return 2;\n}\n" \
1223
+ "# 2 \"src/engine.c\" 2\nint engine_get_twice(void);\nint board_tick(void);\n"
1008
1224
 
1009
- expanded_func = make_expanded_func(
1010
- name: 'helper',
1011
- signature: 'static int helper(void)',
1012
- decorators: ['static'],
1013
- signature_stripped: 'int helper(void)'
1014
- )
1015
- expanded_module = CExtractorTypes::CModule.new(function_definitions: [expanded_func])
1016
-
1017
- allow(@c_extractor).to receive(:from_file)
1018
- .with('/build/full_expansion/mod.c')
1019
- .and_return(expanded_module)
1020
-
1021
- expect(func).to receive(:signature=).with('static int helper(void)')
1022
- expect(func).to receive(:decorators=).with(['static'])
1023
- expect(func).to receive(:signature_stripped=).with('int helper(void)')
1024
-
1025
- @helper.update_signatures_from_full_expansion(
1026
- funcs: [func],
1027
- full_expansion_filepath: '/build/full_expansion/mod.c',
1028
- name: 'TestMod',
1029
- module_name: 'mod',
1030
- file_type: 'source'
1031
- )
1225
+ @helper.mark_inline_elsewhere( decls: [twice, tick], text: text )
1226
+
1227
+ expect( twice.inline_elsewhere ).to be(true)
1228
+ expect( tick.inline_elsewhere ).to be(false)
1032
1229
  end
1033
1230
 
1034
- it "leaves function unchanged when name is not found in expanded module" do
1035
- func = double('func',
1036
- name: 'missing',
1037
- signature: 'MACRO int missing(void)',
1038
- decorators: [],
1039
- signature_stripped: 'int missing(void)'
1040
- )
1231
+ it "marks no declaration of a function a header defines static inline" do
1232
+ clamp = decl( 'int clamp(int v);' )
1041
1233
 
1042
- expanded_module = CExtractorTypes::CModule.new(function_definitions: [])
1234
+ @helper.mark_inline_elsewhere( decls: [clamp], text: "static inline int clamp(int v) { return v; }\nint clamp(int v);\n" )
1043
1235
 
1044
- allow(@c_extractor).to receive(:from_file).and_return(expanded_module)
1236
+ expect( clamp.inline_elsewhere ).to be(false)
1237
+ end
1045
1238
 
1046
- expect(func).not_to receive(:signature=)
1047
- expect(func).not_to receive(:decorators=)
1048
- expect(func).not_to receive(:signature_stripped=)
1239
+ it "marks no static declaration" do
1240
+ local = decl( 'static int local(void);' )
1049
1241
 
1050
- @helper.update_signatures_from_full_expansion(
1051
- funcs: [func],
1052
- full_expansion_filepath: '/build/full_expansion/mod.c',
1053
- name: 'TestMod',
1054
- module_name: 'mod',
1055
- file_type: 'source'
1056
- )
1242
+ @helper.mark_inline_elsewhere( decls: [local], text: "inline int local(void) { return 1; }\n" )
1243
+
1244
+ expect( local.inline_elsewhere ).to be(false)
1057
1245
  end
1058
1246
 
1059
- it "updates only matched functions and skips unmatched ones" do
1060
- func_match = double('matched',
1061
- name: 'private_func',
1062
- signature: 'MY_STATIC void private_func(void)',
1063
- decorators: [],
1064
- signature_stripped: 'void private_func(void)'
1065
- )
1066
- allow(func_match).to receive(:signature=)
1067
- allow(func_match).to receive(:decorators=)
1068
- allow(func_match).to receive(:signature_stripped=)
1247
+ it "marks no declaration of a function a header defines without inline" do
1248
+ plain = decl( 'int plain(void);' )
1069
1249
 
1070
- func_no_match = double('unmatched', name: 'orphan')
1250
+ @helper.mark_inline_elsewhere( decls: [plain], text: "int plain(void) { return 1; }\nint plain(void);\n" )
1071
1251
 
1072
- expanded_func = make_expanded_func(
1073
- name: 'private_func',
1074
- signature: 'static void private_func(void)',
1075
- decorators: ['static'],
1076
- signature_stripped: 'void private_func(void)'
1077
- )
1078
- expanded_module = CExtractorTypes::CModule.new(function_definitions: [expanded_func])
1079
-
1080
- allow(@c_extractor).to receive(:from_file).and_return(expanded_module)
1081
-
1082
- expect(func_match).to receive(:signature=).with('static void private_func(void)')
1083
- expect(func_match).to receive(:decorators=).with(['static'])
1084
- expect(func_match).to receive(:signature_stripped=).with('void private_func(void)')
1085
- expect(func_no_match).not_to receive(:signature=)
1086
- expect(func_no_match).not_to receive(:decorators=)
1087
- expect(func_no_match).not_to receive(:signature_stripped=)
1088
-
1089
- @helper.update_signatures_from_full_expansion(
1090
- funcs: [func_match, func_no_match],
1091
- full_expansion_filepath: '/build/full_expansion/mod.c',
1092
- name: 'TestMod',
1093
- module_name: 'mod',
1094
- file_type: 'source'
1095
- )
1252
+ expect( plain.inline_elsewhere ).to be(false)
1096
1253
  end
1097
1254
 
1098
- it "handles an empty funcs list without error" do
1099
- expanded_module = CExtractorTypes::CModule.new(function_definitions: [])
1100
- allow(@c_extractor).to receive(:from_file).and_return(expanded_module)
1255
+ # A directive line between definitions holds no specifier of the definition after it
1256
+ it "reads past a directive line naming static" do
1257
+ twice = decl( 'int twice(void);' )
1101
1258
 
1102
- expect {
1103
- @helper.update_signatures_from_full_expansion(
1104
- funcs: [],
1105
- full_expansion_filepath: '/build/full_expansion/mod.c',
1106
- name: 'TestMod',
1107
- module_name: 'mod',
1108
- file_type: 'source'
1109
- )
1110
- }.not_to raise_error
1259
+ @helper.mark_inline_elsewhere( decls: [twice], text: "int a;\n#define LOCAL static\ninline int twice(void) { return 2; }\n" )
1260
+
1261
+ expect( twice.inline_elsewhere ).to be(true)
1262
+ end
1263
+
1264
+ # A raw copy holds every header the file includes, so the scan has to stay linear in its size.
1265
+ # A long stretch with no statement break ahead of the definition is the costly shape.
1266
+ it "scans a long stretch with no statement break in linear time" do
1267
+ twice = decl( 'int twice(void);' )
1268
+ text = ("#define LIMIT 1\n" * 20_000) + ";\ninline int twice(void) { return 2; }\n"
1269
+
1270
+ Timeout.timeout( 5 ) { @helper.mark_inline_elsewhere( decls: [twice], text: text ) }
1271
+
1272
+ expect( twice.inline_elsewhere ).to be(true)
1273
+ end
1274
+
1275
+ it "marks each of several declarations from one call" do
1276
+ twice = decl( 'int twice(void);' )
1277
+ clamp = decl( 'int clamp(int v);' )
1278
+ plain = decl( 'int plain(void);' )
1279
+ tick = decl( 'int tick(void);' )
1280
+ text = "inline int twice(void) { return 2; }\nstatic inline int clamp(int v) { return v; }\n" \
1281
+ "int plain(void) { return 1; }\n__inline__ int tick(void)\n{\n return twice();\n}\n"
1282
+
1283
+ @helper.mark_inline_elsewhere( decls: [twice, clamp, plain, tick], text: text )
1284
+
1285
+ expect( [twice, clamp, plain, tick].map( &:inline_elsewhere ) ).to eq( [true, false, false, true] )
1286
+ end
1287
+
1288
+ # A header-only Partial of a large API header asks about every function it declares
1289
+ it "marks many declarations in time linear in the text, not in the number of declarations" do
1290
+ decls = (1..5_000).map { |n| decl( "int api_#{n}(void);" ) }
1291
+ text = ("#define API_LIMIT 1\n" * 250_000) + ";\ninline int api_77(void) { return 77; }\n"
1292
+
1293
+ Timeout.timeout( 1 ) { @helper.mark_inline_elsewhere( decls: decls, text: text ) }
1294
+
1295
+ expect( decls.select( &:inline_elsewhere ).map( &:name ) ).to eq( ['api_77'] )
1296
+ end
1297
+
1298
+ # A block of macros holds no `;` or brace, so the whole block and the definition after it are
1299
+ # one stretch of text. Each mention of the name in it is judged by every word ahead of it.
1300
+ it "judges many mentions of a name in one stretch of text in linear time" do
1301
+ twice = decl( 'int twice(void);' )
1302
+ text = (1..16_000).map { |n| "#define WRAP_#{n}(v) twice(v)\n" }.join + "inline int twice(void) { return 2; }\n"
1303
+
1304
+ Timeout.timeout( 2 ) { @helper.mark_inline_elsewhere( decls: [twice], text: text ) }
1305
+
1306
+ expect( twice.inline_elsewhere ).to be(true)
1307
+ end
1308
+
1309
+ # Text read as characters rather than bytes must mark the same
1310
+ it "marks from text holding a multibyte character ahead of the definition" do
1311
+ twice = decl( 'int twice(void);' )
1312
+
1313
+ @helper.mark_inline_elsewhere( decls: [twice], text: "/* é */ inline int twice(void) { return 2; }\n" )
1314
+
1315
+ expect( twice.inline_elsewhere ).to be(true)
1316
+ end
1317
+
1318
+ it "does not take a longer name's inline definition for the declared function's" do
1319
+ twice = decl( 'int twice(void);' )
1320
+
1321
+ @helper.mark_inline_elsewhere( decls: [twice], text: "inline int get_twice(void) { return 2; }\n" )
1322
+
1323
+ expect( twice.inline_elsewhere ).to be(false)
1324
+ end
1325
+
1326
+ # A raw copy is read as bytes, and a vendor header's comments may hold any byte at all
1327
+ it "marks from a raw copy read as bytes, whatever bytes its comments hold" do
1328
+ twice = decl( 'int twice(void);' )
1329
+ text = "/* 10 \xB5s tick \xFF */\ninline int twice(void) { return 2; }\n".b
1330
+
1331
+ @helper.mark_inline_elsewhere( decls: [twice], text: text )
1332
+
1333
+ expect( twice.inline_elsewhere ).to be(true)
1334
+ end
1335
+ end
1336
+
1337
+ context "#associate_declaration_line_numbers" do
1338
+ require 'ceedling/c_extractor/c_extractor_types'
1339
+
1340
+ # One call locates every declaration from the file
1341
+ it "records each declaration's file and its line in that file's own text" do
1342
+ tick = CExtractorTypes::CFunctionDeclaration.new(name: 'tick', signature: 'int tick(void);', line_num: 1)
1343
+ tock = CExtractorTypes::CFunctionDeclaration.new(name: 'tock', signature: 'int tock(void);', line_num: 1)
1344
+ text = "#include \"x.h\"\nint tick(void);\nint tock(void);\n"
1345
+ expect(@partializer_utils).to receive(:locate_declarations_in_text)
1346
+ .with(signatures: ['int tick(void);', 'int tock(void);'], text: text).once.and_return([2, 3])
1347
+
1348
+ @helper.associate_declaration_line_numbers(decls: [tick, tock], filepath: 'src/mod.c', text: text)
1349
+
1350
+ expect([tick, tock].map(&:source_filepath)).to eq(['src/mod.c', 'src/mod.c'])
1351
+ expect([tick, tock].map(&:line_num)).to eq([2, 3])
1352
+ end
1353
+
1354
+ # Without a location the declaration is written without a #line, so nothing is reported
1355
+ it "leaves the line unset when the declaration is not found" do
1356
+ decl = CExtractorTypes::CFunctionDeclaration.new(name: 'tick', signature: 'int tick(void);', line_num: 1)
1357
+ allow(@partializer_utils).to receive(:locate_declarations_in_text).and_return([nil])
1358
+
1359
+ @helper.associate_declaration_line_numbers(decls: [decl], filepath: 'src/mod.c', text: '')
1360
+
1361
+ expect(decl.source_filepath).to eq('src/mod.c')
1362
+ expect(decl.line_num).to be_nil
1111
1363
  end
1112
1364
  end
1113
1365