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
@@ -0,0 +1,1083 @@
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_system_helper'
9
+
10
+ ##
11
+ ## Headers Found Through Search Paths as the Compiler Finds Them
12
+ ## =============================================================
13
+ ##
14
+ ## A test's #include names a header by its path below a search path, and the compiler
15
+ ## joins each search path with that path in turn. Ceedling finds a mock's header, and
16
+ ## checks a test's plain #includes, the same way, so a search path need not list every
17
+ ## directory below it.
18
+ ##
19
+
20
+ HEADER_SEARCH_PREAMBLE = "#include \"unity.h\"\nvoid setUp(void) {}\nvoid tearDown(void) {}\n"
21
+
22
+ # A header below a search path that doesn't list its directory
23
+ HEADER_SEARCH_DRIVERS_FOO = "#ifndef FOO_H\n#define FOO_H\ntypedef int foo_t;\nint foo_read(void);\n#endif\n"
24
+
25
+ ceedling_system_tests do
26
+ include_context "a fresh ceedling gem project", "header_search"
27
+
28
+ def write(path, content)
29
+ FileUtils.mkdir_p( File.dirname( path ) )
30
+ File.write( path, content )
31
+ end
32
+
33
+ # Merging adds to a list, so the new project's own include paths are removed first
34
+ def configure(include_paths, preprocessor, extra = {})
35
+ @c.remove_project_yml_option_for_test( :paths, :include )
36
+ @c.merge_project_yml_for_test( { :project => { :use_test_preprocessor => preprocessor }, :paths => { :include => include_paths } }.merge( extra ) )
37
+ end
38
+
39
+ def build_passes
40
+ output = @c.ceedling_build_exec( "test:all" )
41
+
42
+ expect(@c.last_exit_status).to eq(0), output
43
+ expect(output).to match(/PASSED:\s+1/)
44
+ return output
45
+ end
46
+
47
+ [:none, :mocks, :all].each do |preprocessor|
48
+ context "with :use_test_preprocessor #{preprocessor}" do
49
+ it "mocks a header named by its directory below a search path that doesn't list that directory" do
50
+ in_project do
51
+ write( 'src/drivers/foo.h', "int foo_read(void);\n" )
52
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
53
+ "void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
54
+
55
+ configure( ['src'], preprocessor )
56
+ build_passes
57
+ end
58
+ end
59
+
60
+ it "includes a header named by its directory below a search path that doesn't list that directory" do
61
+ in_project do
62
+ write( 'src/drivers/foo.h', "#define FOO_MAGIC 7\n" )
63
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n" \
64
+ "void test_magic(void) { TEST_ASSERT_EQUAL_INT(7, FOO_MAGIC); }\n" )
65
+
66
+ configure( ['src'], preprocessor )
67
+ build_passes
68
+ end
69
+ end
70
+
71
+ it "includes the header below the first search path holding the path, as the compiler does" do
72
+ in_project do
73
+ write( 'a/drivers/foo.h', "#define FOO_MAGIC 1\n" )
74
+ write( 'b/drivers/foo.h', "#define FOO_MAGIC 2\n" )
75
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n" \
76
+ "void test_magic(void) { TEST_ASSERT_EQUAL_INT(1, FOO_MAGIC); }\n" )
77
+
78
+ configure( ['a', 'b'], preprocessor )
79
+ output = build_passes
80
+
81
+ # A preprocessed test file's #include names the header GCC already chose
82
+ expect(output).to include( "Multiple files matched 'drivers/foo.h' but chose 'a/drivers/foo.h'" ) unless preprocessor == :all
83
+ end
84
+ end
85
+
86
+ it "mocks the header below the search path TEST_INCLUDE_PATH() puts first" do
87
+ in_project do
88
+ write( 'a/drivers/foo.h', "int a_read(void);\n" )
89
+ write( 'b/drivers/foo.h', "int b_read(void);\n" )
90
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "TEST_INCLUDE_PATH(\"b\")\n#include \"drivers/mock_foo.h\"\n" \
91
+ "void test_reads(void) { b_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, b_read()); }\n" )
92
+
93
+ configure( ['a', 'b'], preprocessor )
94
+ build_passes
95
+ end
96
+ end
97
+ end
98
+ end
99
+
100
+ # A preprocessed test's mock keeps the #include the test wrote. A header of the path its
101
+ # mirrored place would name, below an earlier search path, is a different header.
102
+ it "mocks and includes the header a preprocessed test's #include names, not one of its mirrored path in an earlier search path" do
103
+ in_project do
104
+ write( 'test/support/hal/foo.h', "int fake_read(void);\n" )
105
+ write( 'inc/hal/foo.h', "int foo_read(void);\n" )
106
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_foo.h\"\n" \
107
+ "void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
108
+ configure( ['inc/**'], :all, { :paths => { :include => ['inc/**'], :support => ['test/support'] } } )
109
+
110
+ build_passes
111
+ expect(File.read( 'build/test/mocks/test/test_c/_t_/hal/mock_foo.h' )).to include( 'foo_read' )
112
+ end
113
+ end
114
+
115
+ # The compiler joins a mock's #include with each search path in order, under test
116
+ # preprocessing as without it
117
+ [:none, :all].each do |preprocessor|
118
+ it "mocks the header a mock's folder joins to first under :use_test_preprocessor #{preprocessor}" do
119
+ in_project do
120
+ write( 'test/support/hal/foo.h', "int fake_read(void);\n" )
121
+ write( 'inc/hal/foo.h', "int foo_read(void);\n" )
122
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"hal/mock_foo.h\"\n" \
123
+ "void test_reads(void) { fake_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, fake_read()); }\n" )
124
+ configure( ['inc/**'], preprocessor, { :paths => { :include => ['inc/**'], :support => ['test/support'] } } )
125
+
126
+ build_passes
127
+ end
128
+ end
129
+ end
130
+
131
+ it "mocks a header by a folder below a search path without naming the mock by it" do
132
+ in_project do
133
+ write( 'src/drivers/foo.h', "int foo_read(void);\n" )
134
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
135
+ "void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
136
+
137
+ configure( ['src'], :none, { :cmock => { :mock_name_include_folder => false } } )
138
+ expect(build_passes).to include( "Added search path 'src/drivers'" )
139
+ end
140
+ end
141
+
142
+ # A header only :files ↳ :include supplies sits in no search path's directory. The
143
+ # directory a test's #include implies for it joins that test's search paths, last.
144
+ describe "a header only :files supplies" do
145
+ SENSOR_TEST = "void test_reads(void) { sensor_read_ExpectAndReturn(42); TEST_ASSERT_EQUAL_INT(42, sensor_read()); }\n"
146
+
147
+ def sensor_project(include_line, include_paths: ['.'], files: ['+:src/**/*.h'], preprocessor: :none, treat_inlines: :exclude)
148
+ write( 'src/path/to/sensor.h', "int sensor_read(void);\n" )
149
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + include_line + "\n" + SENSOR_TEST )
150
+ configure( include_paths, preprocessor, { :files => { :include => files }, :cmock => { :treat_inlines => treat_inlines } } )
151
+ end
152
+
153
+ [:none, :mocks, :all].each do |preprocessor|
154
+ [:exclude, :include].each do |treat_inlines|
155
+ context "with :use_test_preprocessor #{preprocessor} and :treat_inlines #{treat_inlines}" do
156
+ it "mocks it through the folder its #include names below a search path" do
157
+ in_project do
158
+ sensor_project( '#include "src/path/to/mock_sensor.h"', preprocessor: preprocessor, treat_inlines: treat_inlines )
159
+ expect(build_passes).to_not include( 'Added search path' )
160
+ end
161
+ end
162
+
163
+ it "mocks it by its bare name through the directory its #include implies" do
164
+ in_project do
165
+ sensor_project( '#include "mock_sensor.h"', preprocessor: preprocessor, treat_inlines: treat_inlines )
166
+ expect(build_passes).to include(
167
+ "Added search path 'src/path/to' for test/test_c.c after every configured search path, so \"sensor.h\" reaches src/path/to/sensor.h."
168
+ )
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ it "mocks it through its folder when no search path reaches that folder, through the directory it is measured from" do
176
+ in_project do
177
+ write( 'inc/other.h', "int other(void);\n" )
178
+ sensor_project( '#include "src/path/to/mock_sensor.h"', include_paths: ['inc'] )
179
+ expect(build_passes).to include( "Added search path '.' for test/test_c.c" )
180
+ end
181
+ end
182
+
183
+ it "mocks it through a folder that starts at a search path, through the directory that folder is measured from" do
184
+ in_project do
185
+ sensor_project( '#include "src/path/to/mock_sensor.h"', include_paths: ['src'] )
186
+ expect(build_passes).to include( "Added search path '.' for test/test_c.c" )
187
+ end
188
+ end
189
+
190
+ it "includes it in the runner through the directory its #include implies" do
191
+ in_project do
192
+ write( 'src/path/to/sensor_types.h', "typedef int sensor_value_t;\n" )
193
+ sensor_project( "#include \"sensor_types.h\"\n#include \"mock_sensor.h\"\nvoid test_type(void) { sensor_value_t v = 3; TEST_ASSERT_EQUAL_INT(3, v); }",
194
+ files: ['+:src/**/*.h'] )
195
+
196
+ output = @c.ceedling_build_exec( "test:all" )
197
+ expect(@c.last_exit_status).to eq(0), output
198
+ expect(output).to match(/PASSED:\s+2/)
199
+ end
200
+ end
201
+
202
+ it "never lets the directory it adds shadow a configured header" do
203
+ in_project do
204
+ write( 'inc/config.h', "#define CONFIG_MAGIC 1\n" )
205
+ write( 'src/path/to/config.h', "#define CONFIG_MAGIC 2\n" )
206
+ sensor_project( "#include \"config.h\"\n#include \"mock_sensor.h\"\nvoid test_config(void) { TEST_ASSERT_EQUAL_INT(1, CONFIG_MAGIC); }",
207
+ include_paths: ['inc'], files: ['+:src/path/to/sensor.h'] )
208
+
209
+ output = @c.ceedling_build_exec( "test:all" )
210
+ expect(@c.last_exit_status).to eq(0), output
211
+ expect(output).to match(/PASSED:\s+2/)
212
+ end
213
+ end
214
+
215
+ it "can't be mocked once a subtractive entry removes it" do
216
+ in_project do
217
+ sensor_project( '#include "mock_sensor.h"', files: ['+:src/**/*.h', '-:src/path/to/sensor.h'] )
218
+
219
+ output = @c.ceedling_build_exec( "test:all" )
220
+ expect(@c.last_exit_status).to_not eq(0)
221
+ expect(output).to include( 'Found no file `sensor.h` in search paths.' )
222
+ end
223
+ end
224
+
225
+ # The compiler rejects such an #include, and so does the build
226
+ it "adds no search path for an #include that spells a search path's own directory into it" do
227
+ in_project do
228
+ write( 'src/x.h', "#define X_MAGIC 3\n" )
229
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"src/x.h\"\nvoid test_x(void) { TEST_ASSERT_EQUAL_INT(3, X_MAGIC); }\n" )
230
+ configure( ['src'], :none )
231
+
232
+ output = @c.ceedling_build_exec( "test:all" )
233
+ expect(@c.last_exit_status).to_not eq(0)
234
+ expect(output).to_not include( 'Added search path' )
235
+ end
236
+ end
237
+ end
238
+
239
+ # glibc's socket.h sits in a multiarch directory of forwarding headers that GCC searches
240
+ # on its own
241
+ describe "a system header below a multiarch directory" do
242
+ before(:each) do
243
+ multiarch = `gcc -print-multiarch 2>#{File::NULL}`.strip
244
+ @multiarch_dir = "/usr/include/#{multiarch}"
245
+ skip "no glibc sys/socket.h below a multiarch directory" if multiarch.empty? or !File.exist?( File.join( @multiarch_dir, 'sys/socket.h' ) )
246
+ end
247
+
248
+ SOCKET_TEST = "void test_socket(void) { socket_ExpectAndReturn(1, 2, 3, 4); TEST_ASSERT_EQUAL_INT(4, socket(1, 2, 3)); }\n"
249
+
250
+ def socket_project(include_line, include_paths:, files: [], preprocessor: :all, cmock: {})
251
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include <errno.h>\n" + include_line + "\n" + SOCKET_TEST )
252
+ configure( include_paths, preprocessor, { :files => { :include => files }, :cmock => { :treat_externs => :include }.merge( cmock ) } )
253
+ end
254
+
255
+ def socket_header
256
+ return File.join( @multiarch_dir, 'sys/socket.h' )
257
+ end
258
+
259
+ it "mocks it by its subdirectory below the multiarch directory a search path lists" do
260
+ in_project do
261
+ socket_project( '#include "sys/mock_socket.h"', include_paths: [@multiarch_dir] )
262
+ build_passes
263
+ end
264
+ end
265
+
266
+ it "mocks it by its subdirectory through the directory its #include implies, when only :files lists it" do
267
+ in_project do
268
+ socket_project( '#include "sys/mock_socket.h"', include_paths: ['test'], files: [File.join( @multiarch_dir, 'sys/socket.h' )] )
269
+ # Ceedling spells a path outside the project from the working directory
270
+ expect(build_passes).to match( /Added search path '[^']*#{Regexp.escape( @multiarch_dir )}' for test\/test_c\.c/ )
271
+ end
272
+ end
273
+
274
+ # A failed lookup stops the build in stage 2 without test preprocessing, and later with it
275
+ [:none, :all].each do |preprocessor|
276
+ it "adds no search path for its bare name, and its error at :use_test_preprocessor #{preprocessor} names the #include that reaches it" do
277
+ in_project do
278
+ socket_project( '#include "mock_socket.h"', include_paths: ['test'], files: [socket_header], preprocessor: preprocessor )
279
+
280
+ output = @c.ceedling_build_exec( "test:all" )
281
+ expect(@c.last_exit_status).to_not eq(0)
282
+ expect(output).to include(
283
+ "Found no file `socket.h` in search paths. `#include \"mock_socket.h\"` in test/test_c.c needs search path '#{@multiarch_dir}/sys'. " \
284
+ "Because this search path is outside the working directory and could cause shadowing of other headers, " \
285
+ "Ceedling won't add the full search path. Instead, reference the parent folder, as in `#include \"sys/mock_socket.h\"`."
286
+ )
287
+ expect(output).to_not include( 'Added search path' )
288
+ end
289
+ end
290
+ end
291
+
292
+ # Captured output loses the option's arrow under a locale without UTF-8
293
+ def naming_option(text)
294
+ return Regexp.new( Regexp.escape( text ).gsub( Regexp.escape( ':cmock ↳ ' ) ) { ':cmock\s*\S*\s*' } )
295
+ end
296
+
297
+ it "names the option a mock without its folder needs in its error" do
298
+ in_project do
299
+ socket_project( '#include "sys/mock_socket.h"', include_paths: ['test'], files: [socket_header], cmock: { :mock_name_include_folder => false } )
300
+
301
+ output = @c.ceedling_build_exec( "test:all" )
302
+ expect(@c.last_exit_status).to_not eq(0)
303
+ expect(output).to match( naming_option(
304
+ "Found no file `sys/socket.h` in search paths. `#include \"sys/mock_socket.h\"` in test/test_c.c needs search path '#{@multiarch_dir}/sys', " \
305
+ "since its mock writes `#include \"socket.h\"` with :cmock ↳ :mock_name_include_folder disabled."
306
+ ) )
307
+ expect(output).to match( naming_option( 'Instead, enable :cmock ↳ :mock_name_include_folder and reference the parent folder' ) )
308
+ end
309
+ end
310
+
311
+ # The lookup tries each header extension, and its error names the last
312
+ it "explains a plain #include's bare name in its error with more than one header extension" do
313
+ in_project do
314
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"socket.h\"\nvoid test_nothing(void) { TEST_ASSERT_EQUAL_INT(1, 1); }\n" )
315
+ configure( ['test'], :none, { :files => { :include => [socket_header] }, :extension => { :header => ['.h', '.hpp'] } } )
316
+
317
+ output = @c.ceedling_build_exec( "test:all" )
318
+ expect(@c.last_exit_status).to_not eq(0)
319
+ expect(output).to include(
320
+ "Found no file `socket.hpp` in search paths. `#include \"socket.h\"` in test/test_c.c needs search path '#{@multiarch_dir}/sys'."
321
+ )
322
+ end
323
+ end
324
+
325
+ # Stage 2 reads the #include from the file's text, and only a failed lookup reports it
326
+ it "says nothing of a bare name test preprocessing removes" do
327
+ in_project do
328
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#ifdef NEVER_DEFINED\n#include \"mock_socket.h\"\n#endif\n" \
329
+ "void test_nothing(void) { TEST_ASSERT_EQUAL_INT(1, 1); }\n" )
330
+ configure( ['test'], :all, { :files => { :include => [socket_header] } } )
331
+
332
+ expect(build_passes).to_not include( 'needs search path' )
333
+ end
334
+ end
335
+
336
+ it "can't mock it by its subdirectory through /usr/include alone" do
337
+ skip "this system links sys/socket.h into /usr/include itself" if File.exist?( '/usr/include/sys/socket.h' )
338
+
339
+ in_project do
340
+ socket_project( '#include "sys/mock_socket.h"', include_paths: ['/usr/include'] )
341
+
342
+ output = @c.ceedling_build_exec( "test:all" )
343
+ expect(@c.last_exit_status).to_not eq(0)
344
+ expect(output).to include( 'Found no file `sys/socket.h` in search paths.' )
345
+ end
346
+ end
347
+ end
348
+
349
+ # A generated file carries a header's #includes. Each names the header as the test's search
350
+ # paths reach it, so a header below a non-recursive search path is found from there too.
351
+ describe "a generated file's #includes" do
352
+ [:none, :mocks, :all].each do |preprocessor|
353
+ it "reach a header below the search path from a Partial under :use_test_preprocessor #{preprocessor}" do
354
+ in_project do
355
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
356
+ write( 'src/sensor.h', "#ifndef SENSOR_H\n#define SENSOR_H\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void);\n#endif\n" )
357
+ write( 'src/sensor.c', "#include \"sensor.h\"\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void) { return 3; }\n" )
358
+ write( 'test/test_sensor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
359
+ "#include TEST_PARTIAL_ALL_MODULE(sensor)\nvoid test_get(void) { TEST_ASSERT_EQUAL_INT(3, sensor_get()); }\n" )
360
+
361
+ configure( ['src'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
362
+ build_passes
363
+ end
364
+ end
365
+
366
+ it "reach a header below the search path from a mocked Partial under :use_test_preprocessor #{preprocessor}" do
367
+ in_project do
368
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
369
+ write( 'src/sensor.h', "#ifndef SENSOR_H\n#define SENSOR_H\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void);\n#endif\n" )
370
+ write( 'test/test_sensor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
371
+ "#include MOCK_PARTIAL_PUBLIC_MODULE(sensor)\n" \
372
+ "void test_get(void) { sensor_get_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, sensor_get()); }\n" )
373
+
374
+ configure( ['src'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
375
+ build_passes
376
+ end
377
+ end
378
+ end
379
+
380
+ [:mocks, :all].each do |preprocessor|
381
+ it "reach a header below the search path from CMock's copy under :use_test_preprocessor #{preprocessor}" do
382
+ in_project do
383
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
384
+ write( 'src/sensor.h', "#ifndef SENSOR_H\n#define SENSOR_H\n#include \"drivers/foo.h\"\nfoo_t sensor_get(void);\n#endif\n" )
385
+ write( 'test/test_sensor.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_sensor.h\"\n" \
386
+ "void test_get(void) { sensor_get_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, sensor_get()); }\n" )
387
+
388
+ configure( ['src'], preprocessor, { :cmock => { :treat_inlines => :include } } )
389
+ build_passes
390
+ end
391
+ end
392
+ end
393
+
394
+ # A Partial's module includes a header beside it, which an earlier search path shadows with a
395
+ # header of the same name. The generated Partial's #include reaches the one beside the module.
396
+ [:mocks, :all].product( [false, true] ).each do |preprocessor, fallback|
397
+ it "reach a header beside a Partial's module that an earlier search path shadows, under :use_test_preprocessor #{preprocessor}#{fallback ? ' with fallback' : ''}" do
398
+ in_project do
399
+ write( 'src/hw/config.h', "#ifndef HW_CONFIG_H\n#define HW_CONFIG_H\ntypedef int hw_t;\n#endif\n" )
400
+ write( 'lib/config.h', "#ifndef LIB_CONFIG_H\n#define LIB_CONFIG_H\n#define LIB_K 1\ntypedef int lib_t;\n#endif\n" )
401
+ write( 'lib/motor.h', "#ifndef MOTOR_H\n#define MOTOR_H\n#include \"config.h\"\nint motor_run(int a);\n#endif\n" )
402
+ write( 'lib/motor.c', "#include \"motor.h\"\nstatic int twice(int a) { return 2 * a + LIB_K; }\nint motor_run(int a) { return twice( a ); }\n" )
403
+ write( 'lib/port.h', "#ifndef PORT_H\n#define PORT_H\n#include \"config.h\"\nlib_t port_read(void);\n#endif\n" )
404
+ write( 'lib/port.c', "#include \"port.h\"\nlib_t port_read(void) { return 0; }\n" )
405
+ write( 'test/test_motor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
406
+ "#include TEST_PARTIAL_ALL_MODULE(motor)\nvoid test_twice(void) { TEST_ASSERT_EQUAL_INT(7, twice( 3 )); }\n" )
407
+ write( 'test/test_port.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
408
+ "#include MOCK_PARTIAL_PUBLIC_MODULE(port)\n" \
409
+ "void test_read(void) { port_read_ExpectAndReturn( 3 ); TEST_ASSERT_EQUAL_INT(3, port_read()); }\n" )
410
+
411
+ configure( ['src/hw/', 'lib/'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
412
+ @c.merge_project_yml_for_test( { :paths => { :source => ['lib/'] } } )
413
+ @c.merge_project_yml_for_test( { :test_build => { :preprocess_force_fallback => true } } ) if fallback
414
+
415
+ output = @c.ceedling_build_exec( "test:all" )
416
+ expect(@c.last_exit_status).to eq(0), output
417
+ expect(output).to match(/PASSED:\s+2/)
418
+ end
419
+ end
420
+ end
421
+
422
+ # A preprocessor names each #include by the path it found the header by. A later search path
423
+ # joined with that path can name another header, which must never take its place.
424
+ it "include the header the compiler found, never one a later search path joins its path to" do
425
+ in_project do
426
+ write( 'include/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define GAIN 3\n#endif\n" )
427
+ write( 'third_party/mylib/include/config.h', "#ifndef MYLIB_CONFIG_H\n#define MYLIB_CONFIG_H\n#define GAIN 99\n#endif\n" )
428
+ write( 'include/motor.h', "#ifndef MOTOR_H\n#define MOTOR_H\n#include \"config.h\"\nint motor_run(void);\n" \
429
+ "static inline int motor_peek(void) { return GAIN; }\n#endif\n" )
430
+ write( 'src/motor.c', "#include \"motor.h\"\nint motor_run(void) { return GAIN; }\n" )
431
+ write( 'test/test_motor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
432
+ "#include TEST_PARTIAL_PUBLIC_MODULE(motor)\nvoid test_run(void) { TEST_ASSERT_EQUAL_INT(3, motor_run()); }\n" )
433
+ write( 'test/test_cm.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_motor.h\"\nvoid test_gain(void) { TEST_ASSERT_EQUAL_INT(3, GAIN); }\n" )
434
+
435
+ configure( ['include/**', 'third_party/**'], :all, { :project => { :use_test_preprocessor => :all, :use_partials => true },
436
+ :cmock => { :treat_inlines => :include } } )
437
+ output = @c.ceedling_build_exec( "test:all" )
438
+
439
+ expect(@c.last_exit_status).to eq(0), output
440
+ expect(output).to match(/PASSED:\s+2/)
441
+ end
442
+ end
443
+
444
+ it "include in the runner the header the compiler found, never one a later search path joins its path to" do
445
+ in_project do
446
+ write( 'include/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define GAIN 3\n#endif\n" )
447
+ write( 'third_party/mylib/include/config.h', "#error The library's config.h reached the runner\n" )
448
+ write( 'test/test_gain.c', HEADER_SEARCH_PREAMBLE + "#include \"config.h\"\nvoid test_gain(void) { TEST_ASSERT_EQUAL_INT(3, GAIN); }\n" )
449
+
450
+ configure( ['include/**', 'third_party/**'], :all )
451
+ build_passes
452
+ end
453
+ end
454
+
455
+ # The compiler joins an #include with each search path. A header directly in a search path
456
+ # isn't reached through the directory that path names.
457
+ it "include in the runner by a text the compiler joins, never one only a header's trailing path matches" do
458
+ in_project do
459
+ write( 'test/hw/config.h', "#ifndef HW_CONFIG_H\n#define HW_CONFIG_H\n#define HW_GAIN 3\n#endif\n" )
460
+ write( 'lib/app/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define APP_GAIN 5\n#endif\n" )
461
+ write( 'test/test_gain.c', HEADER_SEARCH_PREAMBLE + "#include \"hw/config.h\"\n#include \"app/config.h\"\n" \
462
+ "void test_gain(void) { TEST_ASSERT_EQUAL_INT(15, HW_GAIN * APP_GAIN); }\n" )
463
+
464
+ configure( ['lib/'], :all )
465
+ build_passes
466
+ end
467
+ end
468
+
469
+ # A quoted #include looks beside the test file first, and the test's own compile finds that
470
+ # header. A header there that no search path reaches is another header than the search paths'
471
+ # of the same name, so the runner includes it by its absolute path.
472
+ it "include in the runner the header beside the test, never one of its name a search path finds" do
473
+ in_project do
474
+ write( 'test/drivers/foo.h', "#ifndef TFOO_H\n#define TFOO_H\n#define WHICH 1\n#endif\n" )
475
+ write( 'src/drivers/foo.h', "#ifndef SFOO_H\n#define SFOO_H\n#define WHICH 2\n#endif\n" )
476
+ write( 'src/other.h', "int other_read(void);\n" )
477
+ write( 'test/test_b.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n#include \"mock_other.h\"\n" \
478
+ "void test_b(void) { TEST_ASSERT_EQUAL_INT(1, WHICH); }\n" )
479
+
480
+ configure( ['src/'], :none )
481
+ @c.remove_project_yml_option_for_test( :paths, :test )
482
+ @c.merge_project_yml_for_test( { :paths => { :test => ['test/'] } } )
483
+ build_passes
484
+
485
+ runner = File.readlines( Dir.glob( 'build/test/runners/**/test_b_runner.c' ).first ).select { |line| line.include?( 'foo.h' ) }
486
+ expect(runner).to eq( ["#include \"#{File.expand_path( 'test/drivers/foo.h' )}\"\n"] )
487
+ end
488
+ end
489
+
490
+ # Ceedling generates a Partial's header into the build root, where the compiler's -I reaches
491
+ # it by its filename. The runner names it so, never by its absolute path.
492
+ [:none, :mocks, :all].each do |preprocessor|
493
+ it "include in the runner a Partial's generated header by its filename under :use_test_preprocessor #{preprocessor}" do
494
+ in_project do
495
+ write( 'src/calc.h', "#ifndef CALC_H\n#define CALC_H\nint calc(int a);\n#endif\n" )
496
+ write( 'src/calc.c', "#include \"calc.h\"\nstatic int twice(int a) { return 2 * a; }\nint calc(int a) { return twice( a ) + 1; }\n" )
497
+ write( 'test/test_calc.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
498
+ "#include TEST_PARTIAL_ALL_MODULE(calc)\nvoid test_twice(void) { TEST_ASSERT_EQUAL_INT(6, twice( 3 )); }\n" )
499
+
500
+ configure( ['src'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true } } )
501
+ build_passes
502
+
503
+ runner = File.readlines( Dir.glob( 'build/test/runners/**/test_calc_runner.c' ).first ).select { |line| line.include?( 'ceedling_partial_calc_impl.h' ) }
504
+ expect(runner).to eq( ["#include \"ceedling_partial_calc_impl.h\"\n"] )
505
+ end
506
+ end
507
+ end
508
+
509
+ # Reconciliation spells two same-named headers apart. A directory searched ahead of the
510
+ # project's, such as the one holding CMock's copy of one of them, must never capture the other.
511
+ it "keep the paths that tell two same-named headers apart" do
512
+ in_project do
513
+ write( 'src/hw/config.h', "#ifndef HW_CONFIG_H\n#define HW_CONFIG_H\ntypedef int hw_t;\n" \
514
+ "static inline int hw_peek(void) { return -1; }\nint hw_read(void);\n#endif\n" )
515
+ write( 'src/app/config.h', "#ifndef APP_CONFIG_H\n#define APP_CONFIG_H\n#define APP_GAIN 5\ntypedef int app_t;\n#endif\n" )
516
+ write( 'src/motor.h', "#ifndef MOTOR_H\n#define MOTOR_H\n#include \"hw/config.h\"\n#include \"app/config.h\"\nhw_t motor_run(app_t a);\n#endif\n" )
517
+ write( 'src/motor.c', "#include \"motor.h\"\n#include \"hw/config.h\"\n#include \"app/config.h\"\n" \
518
+ "hw_t motor_run(app_t a) { return APP_GAIN * a * hw_read(); }\n" )
519
+ write( 'test/test_motor.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
520
+ "#include TEST_PARTIAL_PUBLIC_MODULE(motor)\n#include \"hw/mock_config.h\"\n" \
521
+ "void test_run(void) { hw_read_ExpectAndReturn(1); TEST_ASSERT_EQUAL_INT(5, motor_run(1)); }\n" )
522
+
523
+ configure( ['src/**'], :all, { :project => { :use_test_preprocessor => :all, :use_partials => true },
524
+ :cmock => { :treat_inlines => :include } } )
525
+ build_passes
526
+ end
527
+ end
528
+
529
+ # A mock includes its header through the folder the test named it by. A search path listing
530
+ # only the header's own directory joins no such folder.
531
+ [[:none, ['fff']], [:all, ['fff']], [:none, []]].each do |preprocessor, plugins|
532
+ kind = plugins.empty? ? 'a mock' : 'an FFF fake'
533
+
534
+ it "reach a header from #{kind} through its folder where a search path lists only the header's own directory under :use_test_preprocessor #{preprocessor}" do
535
+ in_project do
536
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
537
+ body = plugins.empty? ? 'foo_read_ExpectAndReturn(5);' : 'foo_read_fake.return_val = 5;'
538
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
539
+ "void test_reads(void) { #{body} TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
540
+
541
+ configure( ['src/drivers/**'], preprocessor, { :plugins => { :enabled => plugins } } )
542
+ build_passes
543
+ end
544
+ end
545
+ end
546
+
547
+ # A mock includes its header by the text the listed directory reaches it by. A directory
548
+ # added for the folder's parent would hold the project's string.h, shadowing the system's.
549
+ [[:mocks, [], :include], [:all, [], :include], [:none, ['fff'], :exclude]].each do |preprocessor, plugins, treat_inlines|
550
+ kind = plugins.empty? ? "a mock under :treat_inlines #{treat_inlines}" : 'an FFF fake'
551
+
552
+ it "keep a project header named like a system one out of reach of #{kind} through its folder under :use_test_preprocessor #{preprocessor}" do
553
+ in_project do
554
+ write( 'src/drivers/foo.h', "#ifndef FOO_H\n#define FOO_H\ntypedef int foo_t;\n" \
555
+ "static inline foo_t foo_peek(void) { return -1000; }\nfoo_t foo_read(void);\n#endif\n" )
556
+ write( 'src/string.h', "#error \"src/string.h shadowed <string.h>\"\n" )
557
+ body = plugins.empty? ? 'foo_read_ExpectAndReturn(5);' : 'foo_read_fake.return_val = 5;'
558
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include <string.h>\n#include \"drivers/mock_foo.h\"\n" \
559
+ "void test_reads(void) { #{body} TEST_ASSERT_EQUAL_INT(5, foo_read()); " \
560
+ "TEST_ASSERT_EQUAL_INT(0, (int)strlen(\"\")); }\n" )
561
+
562
+ configure( [plugins.empty? ? 'src/drivers/**' : 'src/drivers/'], preprocessor,
563
+ { :plugins => { :enabled => plugins }, :cmock => { :treat_inlines => treat_inlines } } )
564
+ build_passes
565
+ end
566
+ end
567
+ end
568
+
569
+ # The compiler includes the header a mock's own #include reaches, even where the mock was
570
+ # located by a same-named header's trailing path
571
+ [:tests, :all].each do |preprocessor|
572
+ it "include in a mock the same-named header its folder reaches under :use_test_preprocessor #{preprocessor}" do
573
+ in_project do
574
+ write( 'src/drivers/foo.h', "#ifndef SDFOO_H\n#define SDFOO_H\ntypedef int foo_t;\n#define FOO_WHICH 1\nfoo_t foo_read(void);\n#endif\n" )
575
+ write( 'src/app/drivers/foo.h', "#ifndef ADFOO_H\n#define ADFOO_H\ntypedef int foo_t;\n#define FOO_WHICH 2\nfoo_t foo_read(void);\n#endif\n" )
576
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
577
+ "void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); " \
578
+ "TEST_ASSERT_EQUAL_INT(1, FOO_WHICH); }\n" )
579
+
580
+ configure( ['src/', 'src/app/drivers/'], preprocessor )
581
+ build_passes
582
+ end
583
+ end
584
+ end
585
+
586
+ # A format writing more than the text between quotes keeps the text CMock gives it
587
+ it "include in a mock its header through a project's :orig_header_include_fmt around the folder" do
588
+ in_project do
589
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
590
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
591
+ "void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
592
+
593
+ configure( ['src/drivers/'], :none, { :cmock => { :orig_header_include_fmt => '#include "../%s"' } } )
594
+ build_passes
595
+ end
596
+ end
597
+
598
+ # A fake writes no format, so the text a format keeps for CMock never reaches it
599
+ [:none, :all].each do |preprocessor|
600
+ it "reach a header through its search path from an FFF fake under a project's :orig_header_include_fmt around the folder, under :use_test_preprocessor #{preprocessor}" do
601
+ in_project do
602
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
603
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
604
+ "void test_reads(void) { foo_read_fake.return_val = 5; TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
605
+
606
+ configure( ['src/drivers/'], preprocessor, { :cmock => { :orig_header_include_fmt => '#include "../%s"' }, :plugins => { :enabled => ['fff'] } } )
607
+ build_passes
608
+ end
609
+ end
610
+ end
611
+
612
+ [:none, :all].each do |preprocessor|
613
+ it "reach a header below the search path from an FFF fake under :use_test_preprocessor #{preprocessor}" do
614
+ in_project do
615
+ write( 'src/drivers/foo.h', HEADER_SEARCH_DRIVERS_FOO )
616
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
617
+ "void test_reads(void) { foo_read_fake.return_val = 5; TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
618
+
619
+ configure( ['src'], preprocessor, { :plugins => { :enabled => ['fff'] } } )
620
+ build_passes
621
+ end
622
+ end
623
+ end
624
+ end
625
+
626
+ # CMock writes its copy of a header beside the mock with :treat_inlines :include. The mock
627
+ # directory is a search path, but never one a real header is found through.
628
+ it "mocks a header from the project, never from CMock's copy of it, on later builds" do
629
+ in_project do
630
+ write( 'src/foo.h', "int foo_read(void);\n" )
631
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_foo.h\"\n" \
632
+ "void test_reads(void) { foo_read_ExpectAndReturn(5); TEST_ASSERT_EQUAL_INT(5, foo_read()); }\n" )
633
+
634
+ configure( ['src'], :none, { :cmock => { :treat_inlines => :include } } )
635
+ build_passes
636
+ expect(build_passes).to_not include( 'Multiple files matched' )
637
+
638
+ write( 'src/foo.h', "int foo_read(void);\nint foo_more(void);\n" )
639
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_foo.h\"\n" \
640
+ "void test_reads(void) { foo_more_ExpectAndReturn(6); TEST_ASSERT_EQUAL_INT(6, foo_more()); }\n" )
641
+ build_passes
642
+ end
643
+ end
644
+
645
+ # CMock's copy of a header outlives a switch to :exclude unless it is removed
646
+ it "sees an edit to a mocked header after :treat_inlines changes from :include to :exclude" do
647
+ in_project do
648
+ header = ->(k) { "#ifndef FOO_H\n#define FOO_H\n#define FOO_K #{k}\nstatic inline int foo_peek(void) { return FOO_K; }\nint foo_read(void);\n#endif\n" }
649
+ test = ->(k) { HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\nvoid test_k(void) { TEST_ASSERT_EQUAL_INT(#{k}, FOO_K); }\n" }
650
+
651
+ write( 'src/drivers/foo.h', header.( 1 ) )
652
+ write( 'test/test_c.c', test.( 1 ) )
653
+ configure( ['src/**'], :mocks, { :cmock => { :treat_inlines => :include } } )
654
+ build_passes
655
+
656
+ configure( ['src/**'], :mocks, { :cmock => { :treat_inlines => :exclude } } )
657
+ build_passes
658
+ expect(Dir.glob( 'build/test/mocks/**/foo.h' )).to be_empty
659
+
660
+ write( 'src/drivers/foo.h', header.( 2 ) )
661
+ write( 'test/test_c.c', test.( 2 ) )
662
+ build_passes
663
+ end
664
+ end
665
+
666
+ # A fake of a header's inline function would collide with the header's own definition. Under
667
+ # :treat_inlines :include a fake includes the header's inline-free copy beside it, as a mock does.
668
+ describe "an FFF fake under :treat_inlines :include" do
669
+ header = "#ifndef FOO_H\n#define FOO_H\nstatic inline int foo_peek(void) { return 7; }\nint foo_read(void);\n#endif\n"
670
+ test = HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n" \
671
+ "void test_reads(void) { foo_read_fake.return_val = 3; foo_peek_fake.return_val = 9; " \
672
+ "TEST_ASSERT_EQUAL_INT(3, foo_read()); TEST_ASSERT_EQUAL_INT(9, foo_peek()); }\n"
673
+
674
+ [:none, :mocks].each do |preprocessor|
675
+ it "fakes a header's inline function under :use_test_preprocessor #{preprocessor}" do
676
+ in_project do
677
+ write( 'src/drivers/foo.h', header )
678
+ write( 'test/test_c.c', test )
679
+
680
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :plugins => { :enabled => ['fff'] } } )
681
+ build_passes
682
+ end
683
+ end
684
+
685
+ # A search path listing only the header's own directory reaches it by its filename alone
686
+ it "fakes the inline function of a header its search path reaches by its filename under :use_test_preprocessor #{preprocessor}" do
687
+ in_project do
688
+ write( 'src/drivers/foo.h', header )
689
+ write( 'test/test_c.c', test )
690
+
691
+ configure( ['src/drivers/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :plugins => { :enabled => ['fff'] } } )
692
+ build_passes
693
+ end
694
+ end
695
+ end
696
+ end
697
+
698
+ # A test's mock root stays on its search path. A copy of a header the test no longer mocks
699
+ # would shadow the header from there.
700
+ describe "a header a test stops mocking under :treat_inlines :include" do
701
+ header = ->(k) { "#ifndef FOO_H\n#define FOO_H\n#define FOO_K #{k}\nint foo_read(void);\n#endif\n" }
702
+ test = ->(k, includes) { HEADER_SEARCH_PREAMBLE + includes.map { |name| "#include \"#{name}\"\n" }.join +
703
+ "void test_k(void) { TEST_ASSERT_EQUAL_INT(#{k}, FOO_K); }\n" }
704
+
705
+ [[:none, [], ['drivers/mock_bar.h']], [:mocks, [], ['drivers/mock_bar.h']], [:tests, [], ['drivers/mock_bar.h']],
706
+ [:all, [], ['drivers/mock_bar.h']], [:none, [], []], [:all, [], []],
707
+ [:none, ['fff'], ['drivers/mock_bar.h']], [:all, ['fff'], ['drivers/mock_bar.h']]].each do |preprocessor, plugins, kept|
708
+ remaining = kept.empty? ? 'no mock' : (plugins.empty? ? 'another mock' : 'another FFF fake')
709
+
710
+ it "sees an edit to the header beside #{remaining} under :use_test_preprocessor #{preprocessor}" do
711
+ in_project do
712
+ write( 'src/drivers/foo.h', header.( 1 ) )
713
+ write( 'src/drivers/bar.h', "int bar_read(void);\n" )
714
+ write( 'test/test_c.c', test.( 1, ['drivers/mock_foo.h', 'drivers/mock_bar.h'] ) )
715
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :plugins => { :enabled => plugins } } )
716
+ build_passes
717
+
718
+ write( 'src/drivers/foo.h', header.( 2 ) )
719
+ write( 'test/test_c.c', test.( 2, ['drivers/foo.h'] + kept ) )
720
+ build_passes
721
+ end
722
+ end
723
+ end
724
+
725
+ # CMock names a mock and its copy with the header's own extension
726
+ [:none, :all].each do |preprocessor|
727
+ it "sees an edit to a header with another extension under :use_test_preprocessor #{preprocessor}" do
728
+ in_project do
729
+ write( 'src/drivers/foox.hpp', header.( 1 ) )
730
+ write( 'src/drivers/bar.h', "int bar_read(void);\n" )
731
+ write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp', 'drivers/mock_bar.h'] ) )
732
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :extension => { :header => ['.h', '.hpp'] } } )
733
+ build_passes
734
+ expect(build_passes).to_not include( 'Generating mock for' )
735
+
736
+ write( 'src/drivers/foox.hpp', header.( 2 ) )
737
+ write( 'test/test_c.c', test.( 2, ['drivers/foox.hpp', 'drivers/mock_bar.h'] ) )
738
+ build_passes
739
+ end
740
+ end
741
+ end
742
+
743
+ # An FFF fake names its files as CMock names a mock's, with the header's own extension
744
+ [:none, :all].each do |preprocessor|
745
+ it "sees an edit to a header with another extension beside an FFF fake under :use_test_preprocessor #{preprocessor}" do
746
+ in_project do
747
+ write( 'src/drivers/foox.hpp', header.( 1 ) )
748
+ write( 'src/drivers/bar.h', "int bar_read(void);\n" )
749
+ write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp', 'drivers/mock_bar.h'] ) )
750
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include }, :extension => { :header => ['.h', '.hpp'] }, :plugins => { :enabled => ['fff'] } } )
751
+ build_passes
752
+ expect(build_passes).to_not include( 'Generating mock for' )
753
+
754
+ write( 'src/drivers/foox.hpp', header.( 2 ) )
755
+ write( 'test/test_c.c', test.( 2, ['drivers/foox.hpp', 'drivers/mock_bar.h'] ) )
756
+ build_passes
757
+ end
758
+ end
759
+ end
760
+
761
+ # A mock of foox.hpp stands in for that header only. The source of foox.h still links.
762
+ [:none, :tests].each do |preprocessor|
763
+ it "links the source of a header the test includes beside a mock of a header with another extension under :use_test_preprocessor #{preprocessor}" do
764
+ in_project do
765
+ write( 'src/drivers/foox.hpp', "#ifndef FOOX_H\n#define FOOX_H\n#define FOOX_K 1\nint foox_read(void);\n#endif\n" )
766
+ write( 'src/drivers/foox.h', "#ifndef FOOX_C_H\n#define FOOX_C_H\nint foox_c_api(void);\n#endif\n" )
767
+ write( 'src/drivers/foox.c', "#include \"foox.h\"\nint foox_c_api(void) { return 5; }\n" )
768
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foox.h\"\n#include \"drivers/mock_foox.hpp\"\n" \
769
+ "void test_k(void) { TEST_ASSERT_EQUAL_INT(1, FOOX_K); TEST_ASSERT_EQUAL_INT(5, foox_c_api()); }\n" )
770
+ configure( ['src/**'], preprocessor, { :extension => { :header => ['.h', '.hpp'] } } )
771
+ build_passes
772
+ end
773
+ end
774
+ end
775
+
776
+ # A mock of foox.h stands in for the header foox.c implements, though the test includes foox.hpp
777
+ [:none, :tests].each do |preprocessor|
778
+ it "links no source for a mocked header beside a real header with another extension under :use_test_preprocessor #{preprocessor}" do
779
+ in_project do
780
+ write( 'src/drivers/foox.hpp', "#ifndef FOOX_HPP\n#define FOOX_HPP\n#define FOOX_K 1\n#endif\n" )
781
+ write( 'src/drivers/foox.h', "#ifndef FOOX_H\n#define FOOX_H\nint foox_c_api(void);\n#endif\n" )
782
+ write( 'src/drivers/foox.c', "#include \"foox.h\"\nint foox_c_api(void) { return 5; }\n" )
783
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foox.hpp\"\n#include \"drivers/mock_foox.h\"\n" \
784
+ "void test_k(void) { foox_c_api_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(1, FOOX_K); TEST_ASSERT_EQUAL_INT(3, foox_c_api()); }\n" )
785
+ configure( ['src/**'], preprocessor, { :extension => { :header => ['.h', '.hpp'] } } )
786
+ build_passes
787
+ end
788
+ end
789
+ end
790
+
791
+ # A mock of a header with another extension leaves the same-named source in place, however
792
+ # the test reaches the .h header that source implements
793
+ it "links a named source beside a mock of a header with another extension whose stem another header shares" do
794
+ in_project do
795
+ write( 'src/drivers/foox.hpp', "#ifndef FOOX_HPP\n#define FOOX_HPP\n#define FOOX_K 1\nint foox_read(void);\n#endif\n" )
796
+ write( 'src/drivers/foox.h', "#ifndef FOOX_H\n#define FOOX_H\nint foox_c_api(void);\n#endif\n" )
797
+ write( 'src/drivers/foox.c', "#include \"foox.h\"\nint foox_c_api(void) { return 5; }\n" )
798
+ write( 'src/drivers/bar.h', "#ifndef BAR_H\n#define BAR_H\n#include \"foox.h\"\n#endif\n" )
799
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/bar.h\"\n#include \"drivers/mock_foox.hpp\"\n" \
800
+ "TEST_SOURCE_FILE(\"src/drivers/foox.c\")\n" \
801
+ "void test_k(void) { TEST_ASSERT_EQUAL_INT(1, FOOX_K); TEST_ASSERT_EQUAL_INT(5, foox_c_api()); }\n" )
802
+ configure( ['src/**'], :none, { :extension => { :header => ['.h', '.hpp'] } } )
803
+ build_passes
804
+ end
805
+ end
806
+
807
+ # The source of a header the test both includes and mocks stays out of the link
808
+ it "links no source for a header the test includes and mocks under :use_test_preprocessor none" do
809
+ in_project do
810
+ write( 'src/drivers/foo.h', "int foo_read(void);\n" )
811
+ write( 'src/drivers/foo.c', "#include \"foo.h\"\nint foo_read(void) { return 5; }\n" )
812
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n#include \"drivers/mock_foo.h\"\n" \
813
+ "void test_k(void) { foo_read_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, foo_read()); }\n" )
814
+ configure( ['src/**'], :none )
815
+ build_passes
816
+ end
817
+ end
818
+
819
+ # Stage 4 places a stand-in for the mock under the extension the test's #include names
820
+ it "places a stand-in for a mock of a header with another extension that the preprocessor reads under :use_test_preprocessor tests" do
821
+ in_project do
822
+ write( 'src/drivers/foox.hpp', header.( 1 ) )
823
+ write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp'] ) )
824
+ configure( ['src/**'], :tests, { :extension => { :header => ['.h', '.hpp'] } } )
825
+ expect(build_passes).to_not include( 'Failed to generate directive-only' )
826
+
827
+ write( 'test/test_c.c', test.( 1, ['drivers/mock_foox.hpp'] ) + "// edited\n" )
828
+ expect(build_passes).to_not include( 'Failed to generate directive-only' )
829
+ end
830
+ end
831
+
832
+ # Stage 4 sees the test's #includes before any mock is planned. A rebuild generates nothing.
833
+ it "generates no mock again on a rebuild after the test stops mocking a header under :use_test_preprocessor all" do
834
+ in_project do
835
+ write( 'src/drivers/foo.h', header.( 1 ) )
836
+ write( 'src/drivers/bar.h', "int bar_read(void);\n" )
837
+ write( 'test/test_c.c', test.( 1, ['drivers/mock_foo.h', 'drivers/mock_bar.h'] ) )
838
+ configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
839
+ build_passes
840
+
841
+ write( 'test/test_c.c', test.( 1, ['drivers/foo.h', 'drivers/mock_bar.h'] ) )
842
+ build_passes
843
+ expect(build_passes).to_not include( 'Generating mock for' )
844
+ end
845
+ end
846
+
847
+ # Only the preprocessor names a mock whose #include a macro computes
848
+ it "generates no mock again on a rebuild for a mock only the preprocessor names under :use_test_preprocessor all" do
849
+ in_project do
850
+ write( 'src/drivers/widget.h', "#ifndef WIDGET_H\n#define WIDGET_H\nint widget_read(void);\n#endif\n" )
851
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#define WIDGET_MOCK \"drivers/mock_widget.h\"\n#include WIDGET_MOCK\n" \
852
+ "void test_w(void) { widget_read_ExpectAndReturn(7); TEST_ASSERT_EQUAL_INT(7, widget_read()); }\n" )
853
+ configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
854
+ build_passes
855
+
856
+ expect(build_passes).to_not include( 'Generating mock for' )
857
+ end
858
+ end
859
+
860
+ # A same-named mock in another folder names no copy but its own
861
+ it "sees an edit to a header the test stops mocking beside a same-named mock under :use_test_preprocessor all" do
862
+ in_project do
863
+ write( 'src/a/drivers/foo.h', "#ifndef AFOO_H\n#define AFOO_H\nint fa_read(void);\n#endif\n" )
864
+ write( 'src/b/drivers/foo.h', header.( 1 ) )
865
+ write( 'test/test_c.c', test.( 1, ['a/drivers/mock_foo.h', 'b/drivers/mock_foo.h'] ) )
866
+ configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
867
+ build_passes
868
+
869
+ write( 'src/b/drivers/foo.h', header.( 2 ) )
870
+ write( 'test/test_c.c', test.( 2, ['a/drivers/mock_foo.h', 'b/drivers/foo.h'] ) )
871
+ build_passes
872
+ end
873
+ end
874
+
875
+ # The text names a mock the preprocessor no longer reaches
876
+ it "sees an edit to a header a test's conditional #include stops mocking under :use_test_preprocessor all" do
877
+ in_project do
878
+ write( 'src/cfg.h', "#ifndef CFG_H\n#define CFG_H\n#define USE_MOCK 1\n#endif\n" )
879
+ write( 'src/drivers/foo.h', header.( 1 ) )
880
+ write( 'src/drivers/bar.h', "int bar_read(void);\n" )
881
+ conditional = ->(k) { HEADER_SEARCH_PREAMBLE + "#include \"cfg.h\"\n#include \"drivers/mock_bar.h\"\n#if USE_MOCK\n" \
882
+ "#include \"drivers/mock_foo.h\"\n#else\n#include \"drivers/foo.h\"\n#endif\n" \
883
+ "void test_k(void) { TEST_ASSERT_EQUAL_INT(#{k}, FOO_K); }\n" }
884
+ write( 'test/test_c.c', conditional.( 1 ) )
885
+ configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
886
+ build_passes
887
+
888
+ write( 'src/cfg.h', "#ifndef CFG_H\n#define CFG_H\n#define USE_MOCK 0\n#endif\n" )
889
+ write( 'src/drivers/foo.h', header.( 2 ) )
890
+ write( 'test/test_c.c', conditional.( 2 ) )
891
+ build_passes
892
+ end
893
+ end
894
+
895
+ # CMock's own #include text reaches only its copy where a search path lists only the header's
896
+ # own directory. Stage 4 reads a stand-in for the mock while its copy is set aside.
897
+ [:tests, :all].each do |preprocessor|
898
+ it "collects a rebuilt test's #includes through a mock whose header only its copy reaches by CMock's text under :use_test_preprocessor #{preprocessor}" do
899
+ in_project do
900
+ write( 'src/drivers/foo.h', "#ifndef FOO_H\n#define FOO_H\n#define FOO_K 1\nstatic inline int foo_peek(void) { return 7; }\nint foo_read(void);\n#endif\n" )
901
+ test_file = HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n#if FOO_K == 2\nTEST_SOURCE_FILE(\"nothere.c\")\n#endif\n" \
902
+ "void test_r(void) { foo_read_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, foo_read()); }\n"
903
+ write( 'test/test_c.c', test_file )
904
+ configure( ['src/drivers/**'], preprocessor, { :cmock => { :treat_inlines => :include } } )
905
+ build_passes
906
+
907
+ write( 'test/test_c.c', test_file + "// edited\n" )
908
+ expect(build_passes).to_not include( 'Failed to generate directive-only' )
909
+ end
910
+ end
911
+ end
912
+
913
+ # A mocked header decides which other mocks the test needs, as stage 4 reads it
914
+ it "sees an edit to a mocked header that decides the test's other mocks under :use_test_preprocessor all" do
915
+ in_project do
916
+ cfg = ->(on) { "#ifndef CFG_H\n#define CFG_H\n#{on ? '' : '//'}#define TWO_ON\nint cfg_read(void);\n#endif\n" }
917
+ write( 'src/cfg.h', cfg.( false ) )
918
+ write( 'src/two.h', "int two_read(void);\n" )
919
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"mock_cfg.h\"\n#ifdef TWO_ON\n#include \"mock_two.h\"\n#endif\n" \
920
+ "void test_t(void) {\n#ifdef TWO_ON\n two_read_ExpectAndReturn(4); TEST_ASSERT_EQUAL_INT(4, two_read());\n#endif\n}\n" )
921
+ configure( ['src/**'], :all, { :cmock => { :treat_inlines => :include } } )
922
+ build_passes
923
+
924
+ write( 'src/cfg.h', cfg.( true ) )
925
+ build_passes
926
+ end
927
+ end
928
+
929
+ # A header named with the mock prefix is reached through another header, since the test's
930
+ # own #include of it would name a mock
931
+ it "sees an edit to a header whose name starts with the mock prefix" do
932
+ in_project do
933
+ motor = ->(k) { "#ifndef MOTOR_H\n#define MOTOR_H\n#define MOTOR_K #{k}\nint motor_read(void);\n#endif\n" }
934
+
935
+ write( 'src/drivers/motor.h', motor.( 1 ) )
936
+ write( 'src/drivers/bar.h', "int bar_read(void);\n" )
937
+ write( 'src/app/wrap.h', "#include \"drivers/motor.h\"\n" )
938
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mmotor.h\"\n#include \"drivers/mbar.h\"\n" \
939
+ "void test_k(void) { TEST_ASSERT_EQUAL_INT(1, MOTOR_K); }\n" )
940
+ configure( ['src/**'], :none, { :cmock => { :mock_prefix => 'm', :treat_inlines => :include } } )
941
+ build_passes
942
+
943
+ write( 'src/drivers/motor.h', motor.( 2 ) )
944
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"app/wrap.h\"\n#include \"drivers/mbar.h\"\n" \
945
+ "void test_k(void) { TEST_ASSERT_EQUAL_INT(2, MOTOR_K); }\n" )
946
+ build_passes
947
+ end
948
+ end
949
+
950
+ # Mock preprocessing reaches the header through the mock root too
951
+ it "preprocesses a remaining mock's header with the edited header it includes under :use_test_preprocessor mocks" do
952
+ in_project do
953
+ bar = "#ifndef BAR_H\n#define BAR_H\n#include \"drivers/foo.h\"\n#if FOO_K == 1\nint bar_one(void);\n#else\nint bar_two(void);\n#endif\n"
954
+ call = ->(fn, k) { "void test_k(void) { #{fn}_ExpectAndReturn(#{k}); TEST_ASSERT_EQUAL_INT(#{k}, #{fn}()); }\n" }
955
+
956
+ write( 'src/drivers/foo.h', header.( 1 ) )
957
+ write( 'src/drivers/bar.h', bar + "#endif\n" )
958
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/mock_foo.h\"\n#include \"drivers/mock_bar.h\"\n" + call.( 'bar_one', 1 ) )
959
+ configure( ['src/**'], :mocks, { :cmock => { :treat_inlines => :include } } )
960
+ build_passes
961
+
962
+ write( 'src/drivers/foo.h', header.( 2 ) )
963
+ write( 'src/drivers/bar.h', bar + "int bar_more(void);\n#endif\n" )
964
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE + "#include \"drivers/foo.h\"\n#include \"drivers/mock_bar.h\"\n" + call.( 'bar_two', 2 ) )
965
+ build_passes
966
+ end
967
+ end
968
+ end
969
+
970
+ # Mock preprocessing reads a mocked header's own #includes as the compiler does, through the
971
+ # project's headers. An edit to one of those headers alone changes what the mock declares.
972
+ describe "a header a mocked header includes" do
973
+ foo = ->(k) { "#ifndef FOO_H\n#define FOO_H\n#define FOO_K #{k}\nint foo_read(void);\n#endif\n" }
974
+ bar = ->(extra) { "#ifndef BAR_H\n#define BAR_H\n#include \"drivers/foo.h\"\n#if FOO_K == 1\nint bar_one(void);\n#else\nint bar_two(void);\n#endif\n" \
975
+ "#{extra}#endif\n" }
976
+ test = ->(mocks, fn, k) { HEADER_SEARCH_PREAMBLE + mocks.map { |name| "#include \"drivers/#{name}\"\n" }.join +
977
+ "void test_k(void) { #{fn}_ExpectAndReturn(#{k}); TEST_ASSERT_EQUAL_INT(#{k}, #{fn}()); }\n" }
978
+
979
+ # A rebuild with nothing changed preprocesses and generates no mock
980
+ def rebuild_skips_mocks(count)
981
+ output = build_passes
982
+ expect(output).to_not include( 'Generating mock for' )
983
+ expect(output).to include( "Skipping mock preprocessing for #{count} #{count == 1 ? 'mock' : 'mocks'} (nothing changed)" )
984
+ end
985
+
986
+ [:mocks, :all].product( [:include, :exclude] ).each do |preprocessor, treat_inlines|
987
+ it "regenerates a mock after an edit to that header alone under :use_test_preprocessor #{preprocessor} and :treat_inlines #{treat_inlines}" do
988
+ in_project do
989
+ write( 'src/drivers/foo.h', foo.( 1 ) )
990
+ write( 'src/drivers/bar.h', bar.( '' ) )
991
+ write( 'test/test_c.c', test.( ['mock_bar.h'], 'bar_one', 1 ) )
992
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => treat_inlines } } )
993
+ build_passes
994
+
995
+ write( 'src/drivers/foo.h', foo.( 2 ) )
996
+ write( 'test/test_c.c', test.( ['mock_bar.h'], 'bar_two', 2 ) )
997
+ build_passes
998
+ rebuild_skips_mocks( 1 )
999
+ end
1000
+ end
1001
+ end
1002
+
1003
+ # A build records the headers its mock preprocessing entered, so the build after it finds each mock current
1004
+ [:mocks, :all].each do |preprocessor|
1005
+ it "preprocesses no mock in the first rebuild after a fresh build under :use_test_preprocessor #{preprocessor}" do
1006
+ in_project do
1007
+ write( 'src/drivers/foo.h', foo.( 1 ) )
1008
+ write( 'src/drivers/bar.h', bar.( '' ) )
1009
+ write( 'test/test_c.c', test.( ['mock_bar.h'], 'bar_one', 1 ) )
1010
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include } } )
1011
+ build_passes
1012
+
1013
+ output = build_passes
1014
+ expect(output).to_not include( 'Preprocessing header file for follow-on mock handling' )
1015
+ expect(output).to include( 'Skipping mock preprocessing for 1 mock (nothing changed)' )
1016
+ end
1017
+ end
1018
+ end
1019
+
1020
+ # CMock writes its copy of a mocked header beside the mock. A mock generated after stage 9
1021
+ # puts its copy in step with the header.
1022
+ [:mocks, :all].each do |preprocessor|
1023
+ it "regenerates a mock from that header, never another mock's copy of it, under :use_test_preprocessor #{preprocessor}" do
1024
+ in_project do
1025
+ write( 'src/drivers/foo.h', foo.( 1 ) )
1026
+ write( 'src/drivers/bar.h', bar.( '' ) )
1027
+ write( 'test/test_c.c', test.( ['mock_foo.h', 'mock_bar.h'], 'bar_one', 1 ) )
1028
+ configure( ['src/**'], preprocessor, { :cmock => { :treat_inlines => :include } } )
1029
+ build_passes
1030
+
1031
+ write( 'src/drivers/foo.h', foo.( 2 ) )
1032
+ write( 'src/drivers/bar.h', bar.( "int bar_extra(void);\n" ) )
1033
+ write( 'test/test_c.c', test.( ['mock_foo.h', 'mock_bar.h'], 'bar_two', 2 ) )
1034
+ build_passes
1035
+ rebuild_skips_mocks( 2 )
1036
+ end
1037
+ end
1038
+ end
1039
+ end
1040
+
1041
+ # Partials are generated before mocks are preprocessed, so a mocked header can include one
1042
+ # as the compiler finds it.
1043
+ describe "a Partial header a mocked header includes" do
1044
+ [:mocks, :all].product( [:include, :exclude] ).each do |preprocessor, treat_inlines|
1045
+ it "is found by mock preprocessing under :use_test_preprocessor #{preprocessor} and :treat_inlines #{treat_inlines}" do
1046
+ in_project do
1047
+ write( 'src/drivers/foo.h', "int foo_read(void);\n" )
1048
+ write( 'src/drivers/foo.c', "#include \"foo.h\"\nint foo_read(void) { return 1; }\n" )
1049
+ write( 'src/drivers/bar.h', "#ifndef BAR_H\n#define BAR_H\n#include \"ceedling_partial_foo_impl.h\"\nint bar_one(void);\n#endif\n" )
1050
+ write( 'test/test_c.c', HEADER_SEARCH_PREAMBLE.sub( "\n", "\n#include \"ceedling.h\"\n" ) +
1051
+ "#include TEST_PARTIAL_PUBLIC_MODULE(foo)\n#include \"drivers/mock_bar.h\"\n" \
1052
+ "void test_a(void) { bar_one_ExpectAndReturn(1); TEST_ASSERT_EQUAL_INT(1, bar_one()); TEST_ASSERT_EQUAL_INT(1, foo_read()); }\n" )
1053
+
1054
+ configure( ['src/**'], preprocessor, { :project => { :use_test_preprocessor => preprocessor, :use_partials => true },
1055
+ :cmock => { :treat_inlines => treat_inlines } } )
1056
+ build_passes
1057
+ end
1058
+ end
1059
+ end
1060
+ end
1061
+
1062
+ # FFF replaces CMock, writing a different file from the same configuration
1063
+ it "regenerates a mock when the FFF plugin is turned on or off" do
1064
+ in_project do
1065
+ cmock_test = HEADER_SEARCH_PREAMBLE + "#include \"mock_led.h\"\nvoid test_level(void) { led_level_ExpectAndReturn(3); TEST_ASSERT_EQUAL_INT(3, led_level()); }\n"
1066
+ fff_test = HEADER_SEARCH_PREAMBLE + "#include \"mock_led.h\"\nvoid test_level(void) { led_level_fake.return_val = 3; TEST_ASSERT_EQUAL_INT(3, led_level()); }\n"
1067
+
1068
+ write( 'src/led.h', "int led_level(void);\n" )
1069
+ write( 'test/test_c.c', cmock_test )
1070
+ configure( ['src'], :none )
1071
+ build_passes
1072
+ without_fff = File.read( 'project.yml' )
1073
+
1074
+ write( 'test/test_c.c', fff_test )
1075
+ @c.merge_project_yml_for_test( { :plugins => { :enabled => ['fff'] } } )
1076
+ build_passes
1077
+
1078
+ write( 'test/test_c.c', cmock_test )
1079
+ File.write( 'project.yml', without_fff )
1080
+ build_passes
1081
+ end
1082
+ end
1083
+ end