ceedling 0.28.2 → 0.28.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (253) hide show
  1. checksums.yaml +4 -4
  2. data/assets/ceedling +3 -0
  3. data/assets/ceedling.cmd +1 -0
  4. data/assets/default_gitignore +5 -0
  5. data/assets/project_with_guts.yml +1 -0
  6. data/assets/project_with_guts_gcov.yml +3 -0
  7. data/assets/test_example_file_verbose.c +12 -0
  8. data/bin/ceedling +30 -6
  9. data/docs/CeedlingPacket.md +135 -23
  10. data/docs/CeedlingPacket.odt +0 -0
  11. data/examples/blinky/rakefile.rb +2 -1
  12. data/lib/ceedling/configurator.rb +7 -5
  13. data/lib/ceedling/configurator_builder.rb +10 -7
  14. data/lib/ceedling/configurator_plugins.rb +29 -24
  15. data/lib/ceedling/configurator_setup.rb +0 -1
  16. data/lib/ceedling/defaults.rb +7 -2
  17. data/lib/ceedling/dependinator.rb +10 -2
  18. data/lib/ceedling/file_finder.rb +57 -49
  19. data/lib/ceedling/file_path_utils.rb +12 -4
  20. data/lib/ceedling/file_wrapper.rb +4 -0
  21. data/lib/ceedling/generator.rb +4 -3
  22. data/lib/ceedling/generator_test_results.rb +15 -13
  23. data/lib/ceedling/plugin_manager.rb +18 -18
  24. data/lib/ceedling/plugin_reportinator.rb +3 -2
  25. data/lib/ceedling/plugin_reportinator_helper.rb +2 -3
  26. data/lib/ceedling/preprocessinator_extractor.rb +2 -2
  27. data/lib/ceedling/preprocessinator_includes_handler.rb +5 -0
  28. data/lib/ceedling/rakefile.rb +1 -0
  29. data/lib/ceedling/release_invoker_helper.rb +5 -2
  30. data/lib/ceedling/rules_release.rake +2 -1
  31. data/lib/ceedling/rules_tests.rake +18 -9
  32. data/lib/ceedling/rules_tests_deep_dependencies.rake +2 -2
  33. data/lib/ceedling/task_invoker.rb +15 -3
  34. data/lib/ceedling/tasks_vendor.rake +3 -3
  35. data/lib/ceedling/test_invoker.rb +39 -12
  36. data/lib/ceedling/test_invoker_helper.rb +5 -1
  37. data/lib/ceedling/tool_executor.rb +8 -4
  38. data/lib/ceedling/version.rb +1 -1
  39. data/out.fail +21 -0
  40. data/plugins/beep/README.md +22 -0
  41. data/plugins/beep/lib/beep.rb +40 -0
  42. data/plugins/bullseye/bullseye.rake +43 -36
  43. data/plugins/bullseye/config/defaults.yml +4 -0
  44. data/plugins/bullseye/lib/bullseye.rb +27 -5
  45. data/plugins/command_hooks/lib/command_hooks.rb +3 -0
  46. data/plugins/gcov/README.md +34 -1
  47. data/plugins/gcov/config/defaults.yml +3 -3
  48. data/plugins/gcov/gcov.rake +7 -5
  49. data/plugins/gcov/lib/gcov.rb +3 -1
  50. data/plugins/gcov/lib/gcov_constants.rb +2 -0
  51. data/plugins/junit_tests_report/lib/junit_tests_report.rb +12 -9
  52. data/plugins/module_generator/lib/module_generator.rb +14 -1
  53. data/plugins/module_generator/module_generator.rake +21 -4
  54. data/plugins/raw_output_report/lib/raw_output_report.rb +41 -0
  55. data/spec/gcov/gcov_deployment_spec.rb +1 -1
  56. data/spec/gcov/gcov_test_cases_spec.rb +2 -2
  57. data/spec/generator_test_results_spec.rb +5 -0
  58. data/spec/preprocessinator_includes_handler_spec.rb +1 -0
  59. data/spec/spec_system_helper.rb +178 -4
  60. data/spec/support/test_example.fail +1 -0
  61. data/spec/support/test_example.pass +1 -0
  62. data/spec/support/test_example_empty.pass +1 -0
  63. data/spec/support/test_example_ignore.pass +1 -0
  64. data/spec/support/test_example_mangled.pass +1 -0
  65. data/spec/support/test_example_with_time.pass +22 -0
  66. data/spec/system/deployment_spec.rb +33 -0
  67. data/vendor/cmock/README.md +4 -3
  68. data/vendor/cmock/docs/CMock_Summary.md +1 -1
  69. data/vendor/cmock/lib/cmock_config.rb +4 -0
  70. data/vendor/cmock/lib/cmock_generator.rb +5 -2
  71. data/vendor/cmock/lib/cmock_generator_plugin_array.rb +4 -4
  72. data/vendor/cmock/lib/cmock_generator_plugin_callback.rb +9 -11
  73. data/vendor/cmock/lib/cmock_generator_plugin_cexception.rb +0 -1
  74. data/vendor/cmock/lib/cmock_generator_plugin_ignore.rb +2 -3
  75. data/vendor/cmock/lib/cmock_generator_plugin_ignore_arg.rb +2 -4
  76. data/vendor/cmock/lib/cmock_generator_plugin_return_thru_ptr.rb +0 -2
  77. data/vendor/cmock/lib/cmock_generator_utils.rb +16 -3
  78. data/vendor/cmock/lib/cmock_header_parser.rb +59 -34
  79. data/vendor/cmock/release/build.info +1 -1
  80. data/vendor/cmock/release/version.info +1 -1
  81. data/vendor/cmock/scripts/create_makefile.rb +17 -2
  82. data/vendor/cmock/src/cmock.c +13 -7
  83. data/vendor/cmock/test/test_helper.rb +11 -10
  84. data/vendor/cmock/test/unit/cmock_config_test.rb +4 -2
  85. data/vendor/cmock/test/unit/cmock_generator_main_test.rb +10 -4
  86. data/vendor/cmock/test/unit/cmock_generator_plugin_array_test.rb +20 -12
  87. data/vendor/cmock/test/unit/cmock_generator_plugin_expect_a_test.rb +2 -2
  88. data/vendor/cmock/test/unit/cmock_generator_plugin_expect_b_test.rb +2 -2
  89. data/vendor/cmock/test/unit/cmock_generator_plugin_ignore_arg_test.rb +3 -3
  90. data/vendor/cmock/test/unit/cmock_generator_plugin_return_thru_ptr_test.rb +8 -6
  91. data/vendor/cmock/test/unit/cmock_generator_utils_test.rb +27 -10
  92. data/vendor/cmock/test/unit/cmock_header_parser_test.rb +108 -20
  93. data/vendor/cmock/vendor/c_exception/Gemfile +4 -0
  94. data/vendor/cmock/vendor/c_exception/Gemfile.lock +12 -0
  95. data/vendor/cmock/vendor/c_exception/LICENSE.txt +30 -0
  96. data/vendor/cmock/vendor/c_exception/README.md +162 -0
  97. data/vendor/cmock/vendor/c_exception/Rakefile +42 -0
  98. data/vendor/cmock/vendor/c_exception/docs/CException.md +292 -0
  99. data/vendor/cmock/vendor/c_exception/docs/ThrowTheSwitchCodingStandard.md +207 -0
  100. data/vendor/cmock/vendor/c_exception/lib/CException.c +46 -0
  101. data/vendor/cmock/vendor/c_exception/lib/CException.h +110 -0
  102. data/vendor/cmock/vendor/c_exception/makefile +24 -0
  103. data/vendor/cmock/vendor/c_exception/release/build.info +2 -0
  104. data/vendor/cmock/vendor/c_exception/release/version.info +2 -0
  105. data/vendor/cmock/vendor/c_exception/test/CExceptionConfig.h +46 -0
  106. data/vendor/cmock/vendor/c_exception/test/TestException.c +391 -0
  107. data/vendor/cmock/vendor/c_exception/test/TestException_Runner.c +67 -0
  108. data/vendor/cmock/vendor/unity/README.md +231 -0
  109. data/vendor/cmock/vendor/unity/auto/colour_prompt.rb +118 -0
  110. data/vendor/cmock/vendor/unity/auto/colour_reporter.rb +39 -0
  111. data/vendor/cmock/vendor/unity/auto/generate_config.yml +36 -0
  112. data/vendor/cmock/vendor/unity/auto/generate_module.rb +308 -0
  113. data/vendor/cmock/vendor/unity/auto/generate_test_runner.rb +457 -0
  114. data/vendor/cmock/vendor/unity/auto/parse_output.rb +323 -0
  115. data/vendor/cmock/vendor/unity/auto/stylize_as_junit.rb +252 -0
  116. data/vendor/cmock/vendor/unity/auto/test_file_filter.rb +25 -0
  117. data/vendor/cmock/vendor/unity/auto/type_sanitizer.rb +6 -0
  118. data/vendor/cmock/vendor/unity/auto/unity_test_summary.py +139 -0
  119. data/vendor/cmock/vendor/unity/auto/unity_test_summary.rb +136 -0
  120. data/vendor/cmock/vendor/unity/auto/unity_to_junit.py +146 -0
  121. data/vendor/cmock/vendor/unity/docs/ThrowTheSwitchCodingStandard.md +206 -0
  122. data/vendor/cmock/vendor/unity/docs/UnityAssertionsCheatSheetSuitableforPrintingandPossiblyFraming.pdf +0 -0
  123. data/vendor/cmock/vendor/unity/docs/UnityAssertionsReference.md +779 -0
  124. data/vendor/cmock/vendor/unity/docs/UnityConfigurationGuide.md +433 -0
  125. data/vendor/cmock/vendor/unity/docs/UnityGettingStartedGuide.md +192 -0
  126. data/vendor/cmock/vendor/unity/docs/UnityHelperScriptsGuide.md +260 -0
  127. data/vendor/cmock/vendor/unity/docs/license.txt +21 -0
  128. data/vendor/cmock/vendor/unity/examples/example_1/makefile +71 -0
  129. data/vendor/cmock/vendor/unity/examples/example_1/readme.txt +5 -0
  130. data/vendor/cmock/vendor/unity/examples/example_1/src/ProductionCode.c +24 -0
  131. data/vendor/cmock/vendor/unity/examples/example_1/src/ProductionCode.h +3 -0
  132. data/vendor/cmock/vendor/unity/examples/example_1/src/ProductionCode2.c +11 -0
  133. data/vendor/cmock/vendor/unity/examples/example_1/src/ProductionCode2.h +2 -0
  134. data/vendor/cmock/vendor/unity/examples/example_1/test/TestProductionCode.c +62 -0
  135. data/vendor/cmock/vendor/unity/examples/example_1/test/TestProductionCode2.c +31 -0
  136. data/vendor/cmock/vendor/unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c +53 -0
  137. data/vendor/cmock/vendor/unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c +57 -0
  138. data/vendor/cmock/vendor/unity/examples/example_2/makefile +70 -0
  139. data/vendor/cmock/vendor/unity/examples/example_2/readme.txt +5 -0
  140. data/vendor/cmock/vendor/unity/examples/example_2/src/ProductionCode.c +24 -0
  141. data/vendor/cmock/vendor/unity/examples/example_2/src/ProductionCode.h +3 -0
  142. data/vendor/cmock/vendor/unity/examples/example_2/src/ProductionCode2.c +11 -0
  143. data/vendor/cmock/vendor/unity/examples/example_2/src/ProductionCode2.h +2 -0
  144. data/vendor/cmock/vendor/unity/examples/example_2/test/TestProductionCode.c +64 -0
  145. data/vendor/cmock/vendor/unity/examples/example_2/test/TestProductionCode2.c +33 -0
  146. data/vendor/cmock/vendor/unity/examples/example_2/test/test_runners/TestProductionCode2_Runner.c +9 -0
  147. data/vendor/cmock/vendor/unity/examples/example_2/test/test_runners/TestProductionCode_Runner.c +11 -0
  148. data/vendor/cmock/vendor/unity/examples/example_2/test/test_runners/all_tests.c +12 -0
  149. data/vendor/cmock/vendor/unity/examples/example_3/helper/UnityHelper.c +10 -0
  150. data/vendor/cmock/vendor/unity/examples/example_3/helper/UnityHelper.h +12 -0
  151. data/vendor/cmock/vendor/unity/examples/example_3/rakefile.rb +43 -0
  152. data/vendor/cmock/vendor/unity/examples/example_3/rakefile_helper.rb +249 -0
  153. data/vendor/cmock/vendor/unity/examples/example_3/readme.txt +13 -0
  154. data/vendor/cmock/vendor/unity/examples/example_3/src/ProductionCode.c +24 -0
  155. data/vendor/cmock/vendor/unity/examples/example_3/src/ProductionCode.h +3 -0
  156. data/vendor/cmock/vendor/unity/examples/example_3/src/ProductionCode2.c +11 -0
  157. data/vendor/cmock/vendor/unity/examples/example_3/src/ProductionCode2.h +2 -0
  158. data/vendor/cmock/vendor/unity/examples/example_3/target_gcc_32.yml +46 -0
  159. data/vendor/cmock/vendor/unity/examples/example_3/test/TestProductionCode.c +62 -0
  160. data/vendor/cmock/vendor/unity/examples/example_3/test/TestProductionCode2.c +31 -0
  161. data/vendor/cmock/vendor/unity/examples/unity_config.h +247 -0
  162. data/vendor/cmock/vendor/unity/extras/eclipse/error_parsers.txt +26 -0
  163. data/vendor/cmock/vendor/unity/extras/fixture/rakefile.rb +48 -0
  164. data/vendor/cmock/vendor/unity/extras/fixture/rakefile_helper.rb +178 -0
  165. data/vendor/cmock/vendor/unity/extras/fixture/readme.txt +9 -0
  166. data/vendor/cmock/vendor/unity/extras/fixture/src/unity_fixture.c +436 -0
  167. data/vendor/cmock/vendor/unity/extras/fixture/src/unity_fixture.h +83 -0
  168. data/vendor/cmock/vendor/unity/extras/fixture/src/unity_fixture_internals.h +51 -0
  169. data/vendor/cmock/vendor/unity/extras/fixture/src/unity_fixture_malloc_overrides.h +47 -0
  170. data/vendor/cmock/vendor/unity/extras/fixture/test/Makefile +75 -0
  171. data/vendor/cmock/vendor/unity/extras/fixture/test/main/AllTests.c +22 -0
  172. data/vendor/cmock/vendor/unity/extras/fixture/test/template_fixture_tests.c +39 -0
  173. data/vendor/cmock/vendor/unity/extras/fixture/test/unity_fixture_Test.c +543 -0
  174. data/vendor/cmock/vendor/unity/extras/fixture/test/unity_fixture_TestRunner.c +57 -0
  175. data/vendor/cmock/vendor/unity/extras/fixture/test/unity_output_Spy.c +57 -0
  176. data/vendor/cmock/vendor/unity/extras/fixture/test/unity_output_Spy.h +17 -0
  177. data/vendor/cmock/vendor/unity/release/build.info +2 -0
  178. data/vendor/cmock/vendor/unity/release/version.info +2 -0
  179. data/vendor/cmock/vendor/unity/src/unity.c +1572 -0
  180. data/vendor/cmock/vendor/unity/src/unity.h +503 -0
  181. data/vendor/cmock/vendor/unity/src/unity_internals.h +924 -0
  182. data/vendor/cmock/vendor/unity/test/Makefile +68 -0
  183. data/vendor/cmock/vendor/unity/test/expectdata/testsample_cmd.c +61 -0
  184. data/vendor/cmock/vendor/unity/test/expectdata/testsample_def.c +57 -0
  185. data/vendor/cmock/vendor/unity/test/expectdata/testsample_head1.c +55 -0
  186. data/vendor/cmock/vendor/unity/test/expectdata/testsample_head1.h +15 -0
  187. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_cmd.c +80 -0
  188. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_def.c +76 -0
  189. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_head1.c +75 -0
  190. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_head1.h +13 -0
  191. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_new1.c +89 -0
  192. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_new2.c +89 -0
  193. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_param.c +77 -0
  194. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_run1.c +89 -0
  195. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_run2.c +89 -0
  196. data/vendor/cmock/vendor/unity/test/expectdata/testsample_mock_yaml.c +90 -0
  197. data/vendor/cmock/vendor/unity/test/expectdata/testsample_new1.c +67 -0
  198. data/vendor/cmock/vendor/unity/test/expectdata/testsample_new2.c +70 -0
  199. data/vendor/cmock/vendor/unity/test/expectdata/testsample_param.c +58 -0
  200. data/vendor/cmock/vendor/unity/test/expectdata/testsample_run1.c +67 -0
  201. data/vendor/cmock/vendor/unity/test/expectdata/testsample_run2.c +70 -0
  202. data/vendor/cmock/vendor/unity/test/expectdata/testsample_yaml.c +71 -0
  203. data/vendor/cmock/vendor/unity/test/rakefile +125 -0
  204. data/vendor/cmock/vendor/unity/test/rakefile_helper.rb +260 -0
  205. data/vendor/cmock/vendor/unity/test/spec/generate_module_existing_file_spec.rb +158 -0
  206. data/vendor/cmock/vendor/unity/test/targets/clang_file.yml +78 -0
  207. data/vendor/cmock/vendor/unity/test/targets/clang_strict.yml +78 -0
  208. data/vendor/cmock/vendor/unity/test/targets/gcc_32.yml +49 -0
  209. data/vendor/cmock/vendor/unity/test/targets/gcc_64.yml +50 -0
  210. data/vendor/cmock/vendor/unity/test/targets/gcc_auto_limits.yml +47 -0
  211. data/vendor/cmock/vendor/unity/test/targets/gcc_auto_stdint.yml +59 -0
  212. data/vendor/cmock/vendor/unity/test/targets/gcc_manual_math.yml +47 -0
  213. data/vendor/cmock/vendor/unity/test/targets/hitech_picc18.yml +101 -0
  214. data/vendor/cmock/vendor/unity/test/targets/iar_arm_v4.yml +90 -0
  215. data/vendor/cmock/vendor/unity/test/targets/iar_arm_v5.yml +80 -0
  216. data/vendor/cmock/vendor/unity/test/targets/iar_arm_v5_3.yml +80 -0
  217. data/vendor/cmock/vendor/unity/test/targets/iar_armcortex_LM3S9B92_v5_4.yml +94 -0
  218. data/vendor/cmock/vendor/unity/test/targets/iar_cortexm3_v5.yml +84 -0
  219. data/vendor/cmock/vendor/unity/test/targets/iar_msp430.yml +95 -0
  220. data/vendor/cmock/vendor/unity/test/targets/iar_sh2a_v6.yml +86 -0
  221. data/vendor/cmock/vendor/unity/test/testdata/CException.h +11 -0
  222. data/vendor/cmock/vendor/unity/test/testdata/Defs.h +8 -0
  223. data/vendor/cmock/vendor/unity/test/testdata/cmock.h +14 -0
  224. data/vendor/cmock/vendor/unity/test/testdata/mockMock.h +13 -0
  225. data/vendor/cmock/vendor/unity/test/testdata/testRunnerGenerator.c +186 -0
  226. data/vendor/cmock/vendor/unity/test/testdata/testRunnerGeneratorSmall.c +70 -0
  227. data/vendor/cmock/vendor/unity/test/testdata/testRunnerGeneratorWithMocks.c +195 -0
  228. data/vendor/cmock/vendor/unity/test/tests/test_generate_test_runner.rb +1252 -0
  229. data/vendor/cmock/vendor/unity/test/tests/testparameterized.c +113 -0
  230. data/vendor/cmock/vendor/unity/test/tests/testunity.c +5371 -0
  231. data/vendor/unity/auto/generate_test_runner.rb +30 -10
  232. data/vendor/unity/auto/parse_output.rb +212 -109
  233. data/vendor/unity/docs/ThrowTheSwitchCodingStandard.md +9 -10
  234. data/vendor/unity/docs/UnityAssertionsReference.md +11 -2
  235. data/vendor/unity/docs/UnityConfigurationGuide.md +90 -55
  236. data/vendor/unity/docs/UnityGettingStartedGuide.md +6 -5
  237. data/vendor/unity/docs/UnityHelperScriptsGuide.md +23 -5
  238. data/vendor/unity/examples/unity_config.h +8 -0
  239. data/vendor/unity/extras/fixture/src/unity_fixture.c +4 -0
  240. data/vendor/unity/extras/fixture/src/unity_fixture.h +1 -1
  241. data/vendor/unity/extras/fixture/src/unity_fixture_internals.h +2 -2
  242. data/vendor/unity/release/build.info +1 -1
  243. data/vendor/unity/release/version.info +1 -1
  244. data/vendor/unity/src/unity.c +64 -57
  245. data/vendor/unity/src/unity.h +111 -7
  246. data/vendor/unity/src/unity_internals.h +173 -73
  247. data/vendor/unity/test/Makefile +5 -1
  248. data/vendor/unity/test/testdata/testRunnerGenerator.c +4 -1
  249. data/vendor/unity/test/testdata/testRunnerGeneratorSmall.c +4 -1
  250. data/vendor/unity/test/testdata/testRunnerGeneratorWithMocks.c +4 -1
  251. data/vendor/unity/test/tests/testparameterized.c +5 -2
  252. data/vendor/unity/test/tests/testunity.c +34 -0
  253. metadata +150 -2
@@ -0,0 +1,207 @@
1
+ # ThrowTheSwitch.org Coding Standard
2
+
3
+ Hi. Welcome to the coding standard for ThrowTheSwitch.org. For the most part,
4
+ we try to follow these standards to unify our contributors' code into a cohesive
5
+ unit (puns intended). You might find places where these standards aren't
6
+ followed. We're not perfect. Please be polite where you notice these discrepancies
7
+ and we'll try to be polite when we notice yours.
8
+
9
+ ;)
10
+
11
+
12
+ ## Why Have A Coding Standard?
13
+
14
+ Being consistent makes code easier to understand. We've made an attempt to keep
15
+ our standard simple because we also believe that we can only expect someone to
16
+ follow something that is understandable. Please do your best.
17
+
18
+
19
+ ## Our Philosophy
20
+
21
+ Before we get into details on syntax, let's take a moment to talk about our
22
+ vision for these tools. We're C developers and embedded software developers.
23
+ These tools are great to test any C code, but catering to embedded software has
24
+ made us more tolerant of compiler quirks. There are a LOT of quirky compilers
25
+ out there. By quirky I mean "doesn't follow standards because they feel like
26
+ they have a license to do as they wish."
27
+
28
+ Our philosophy is "support every compiler we can". Most often, this means that
29
+ we aim for writing C code that is standards compliant (often C89... that seems
30
+ to be a sweet spot that is almost always compatible). But it also means these
31
+ tools are tolerant of things that aren't common. Some that aren't even
32
+ compliant. There are configuration options to override the size of standard
33
+ types. There are configuration options to force Unity to not use certain
34
+ standard library functions. A lot of Unity is configurable and we have worked
35
+ hard to make it not TOO ugly in the process.
36
+
37
+ Similarly, our tools that parse C do their best. They aren't full C parsers
38
+ (yet) and, even if they were, they would still have to accept non-standard
39
+ additions like gcc extensions or specifying `@0x1000` to force a variable to
40
+ compile to a particular location. It's just what we do, because we like
41
+ everything to Just Work™.
42
+
43
+ Speaking of having things Just Work™, that's our second philosophy. By that, we
44
+ mean that we do our best to have EVERY configuration option have a logical
45
+ default. We believe that if you're working with a simple compiler and target,
46
+ you shouldn't need to configure very much... we try to make the tools guess as
47
+ much as they can, but give the user the power to override it when it's wrong.
48
+
49
+
50
+ ## Naming Things
51
+
52
+ Let's talk about naming things. Programming is all about naming things. We name
53
+ files, functions, variables, and so much more. While we're not always going to
54
+ find the best name for something, we actually put quite a bit of effort into
55
+ finding *What Something WANTS to be Called*™.
56
+
57
+ When naming things, we more or less follow this hierarchy, the first being the
58
+ most important to us (but we do all four whenever possible):
59
+ 1. Readable
60
+ 2. Descriptive
61
+ 3. Consistent
62
+ 4. Memorable
63
+
64
+
65
+ #### Readable
66
+
67
+ We want to read our code. This means we like names and flow that are more
68
+ naturally read. We try to avoid double negatives. We try to avoid cryptic
69
+ abbreviations (sticking to ones we feel are common).
70
+
71
+
72
+ #### Descriptive
73
+
74
+ We like descriptive names for things, especially functions and variables.
75
+ Finding the right name for something is an important endeavor. You might notice
76
+ from poking around our code that this often results in names that are a little
77
+ longer than the average. Guilty. We're okay with a tiny bit more typing if it
78
+ means our code is easier to understand.
79
+
80
+ There are two exceptions to this rule that we also stick to as religiously as
81
+ possible:
82
+
83
+ First, while we realize hungarian notation (and similar systems for encoding
84
+ type information into variable names) is providing a more descriptive name, we
85
+ feel that (for the average developer) it takes away from readability and
86
+ therefore is to be avoided.
87
+
88
+ Second, loop counters and other local throw-away variables often have a purpose
89
+ which is obvious. There's no need, therefore, to get carried away with complex
90
+ naming. We find i, j, and k are better loop counters than loopCounterVar or
91
+ whatnot. We only break this rule when we see that more description could improve
92
+ understanding of an algorithm.
93
+
94
+
95
+ #### Consistent
96
+
97
+ We like consistency, but we're not really obsessed with it. We try to name our
98
+ configuration macros in a consistent fashion... you'll notice a repeated use of
99
+ UNITY_EXCLUDE_BLAH or UNITY_USES_BLAH macros. This helps users avoid having to
100
+ remember each macro's details.
101
+
102
+
103
+ #### Memorable
104
+
105
+ Where ever it doesn't violate the above principles, we try to apply memorable
106
+ names. Sometimes this means using something that is simply descriptive, but
107
+ often we strive for descriptive AND unique... we like quirky names that stand
108
+ out in our memory and are easier to search for. Take a look through the file
109
+ names in Ceedling and you'll get a good idea of what we are talking about here.
110
+ Why use preprocess when you can use preprocessinator? Or what better describes a
111
+ module in charge of invoking tasks during releases than release_invoker? Don't
112
+ get carried away. The names are still descriptive and fulfill the above
113
+ requirements, but they don't feel stale.
114
+
115
+
116
+ ## C and C++ Details
117
+
118
+ We don't really want to add to the style battles out there. Tabs or spaces?
119
+ How many spaces? Where do the braces go? These are age-old questions that will
120
+ never be answered... or at least not answered in a way that will make everyone
121
+ happy.
122
+
123
+ We've decided on our own style preferences. If you'd like to contribute to these
124
+ projects (and we hope that you do), then we ask if you do your best to follow
125
+ the same. It will only hurt a little. We promise.
126
+
127
+
128
+ #### Whitespace
129
+
130
+ Our C-style is to use spaces and to use 4 of them per indent level. It's a nice
131
+ power-of-2 number that looks decent on a wide screen. We have no more reason
132
+ than that. We break that rule when we have lines that wrap (macros or function
133
+ arguments or whatnot). When that happens, we like to indent further to line
134
+ things up in nice tidy columns.
135
+
136
+ ```C
137
+ if (stuff_happened)
138
+ {
139
+ do_something();
140
+ }
141
+ ```
142
+
143
+
144
+ #### Case
145
+
146
+ - Files - all lower case with underscores.
147
+ - Variables - all lower case with underscores
148
+ - Macros - all caps with underscores.
149
+ - Typedefs - all caps with underscores. (also ends with _T).
150
+ - Functions - camel cased. Usually named ModuleName_FuncName
151
+ - Constants and Globals - camel cased.
152
+
153
+
154
+ #### Braces
155
+
156
+ The left brace is on the next line after the declaration. The right brace is
157
+ directly below that. Everything in between in indented one level. If you're
158
+ catching an error and you have a one-line, go ahead and to it on the same line.
159
+
160
+ ```C
161
+ while (blah)
162
+ {
163
+ //Like so. Even if only one line, we use braces.
164
+ }
165
+ ```
166
+
167
+
168
+ #### Comments
169
+
170
+ Do you know what we hate? Old-school C block comments. BUT, we're using them
171
+ anyway. As we mentioned, our goal is to support every compiler we can,
172
+ especially embedded compilers. There are STILL C compilers out there that only
173
+ support old-school block comments. So that is what we're using. We apologize. We
174
+ think they are ugly too.
175
+
176
+
177
+ ## Ruby Details
178
+
179
+ Is there really such thing as a Ruby coding standard? Ruby is such a free form
180
+ language, it seems almost sacrilegious to suggest that people should comply to
181
+ one method! We'll keep it really brief!
182
+
183
+
184
+ #### Whitespace
185
+
186
+ Our Ruby style is to use spaces and to use 2 of them per indent level. It's a
187
+ nice power-of-2 number that really grooves with Ruby's compact style. We have no
188
+ more reason than that. We break that rule when we have lines that wrap. When
189
+ that happens, we like to indent further to line things up in nice tidy columns.
190
+
191
+
192
+ #### Case
193
+
194
+ - Files - all lower case with underscores.
195
+ - Variables - all lower case with underscores
196
+ - Classes, Modules, etc - Camel cased.
197
+ - Functions - all lower case with underscores
198
+ - Constants - all upper case with underscores
199
+
200
+
201
+ ## Documentation
202
+
203
+ Egad. Really? We use markdown and we like pdf files because they can be made to
204
+ look nice while still being portable. Good enough?
205
+
206
+
207
+ *Find The Latest of This And More at [ThrowTheSwitch.org](https://throwtheswitch.org)*
@@ -0,0 +1,46 @@
1
+ #include "CException.h"
2
+
3
+ #pragma GCC diagnostic push
4
+ #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
5
+ volatile CEXCEPTION_FRAME_T CExceptionFrames[CEXCEPTION_NUM_ID] = {{ 0 }};
6
+ #pragma GCC diagnostic pop
7
+
8
+ //------------------------------------------------------------------------------------------
9
+ // Throw
10
+ //------------------------------------------------------------------------------------------
11
+ void Throw(CEXCEPTION_T ExceptionID)
12
+ {
13
+ unsigned int MY_ID = CEXCEPTION_GET_ID;
14
+ CExceptionFrames[MY_ID].Exception = ExceptionID;
15
+ if (CExceptionFrames[MY_ID].pFrame)
16
+ {
17
+ longjmp(*CExceptionFrames[MY_ID].pFrame, 1);
18
+ }
19
+ CEXCEPTION_NO_CATCH_HANDLER(ExceptionID);
20
+ }
21
+
22
+ //------------------------------------------------------------------------------------------
23
+ // Explanation of what it's all for:
24
+ //------------------------------------------------------------------------------------------
25
+ /*
26
+ #define Try
27
+ { <- give us some local scope. most compilers are happy with this
28
+ jmp_buf *PrevFrame, NewFrame; <- prev frame points to the last try block's frame. new frame gets created on stack for this Try block
29
+ unsigned int MY_ID = CEXCEPTION_GET_ID; <- look up this task's id for use in frame array. always 0 if single-tasking
30
+ PrevFrame = CExceptionFrames[CEXCEPTION_GET_ID].pFrame; <- set pointer to point at old frame (which array is currently pointing at)
31
+ CExceptionFrames[MY_ID].pFrame = &NewFrame; <- set array to point at my new frame instead, now
32
+ CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- initialize my exception id to be NONE
33
+ if (setjmp(NewFrame) == 0) { <- do setjmp. it returns 1 if longjump called, otherwise 0
34
+ if (&PrevFrame) <- this is here to force proper scoping. it requires braces or a single line to be but after Try, otherwise won't compile. This is always true at this point.
35
+
36
+ #define Catch(e)
37
+ else { } <- this also forces proper scoping. Without this they could stick their own 'else' in and it would get ugly
38
+ CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; <- no errors happened, so just set the exception id to NONE (in case it was corrupted)
39
+ }
40
+ else <- an exception occurred
41
+ { e = CExceptionFrames[MY_ID].Exception; e=e;} <- assign the caught exception id to the variable passed in.
42
+ CExceptionFrames[MY_ID].pFrame = PrevFrame; <- make the pointer in the array point at the previous frame again, as if NewFrame never existed.
43
+ } <- finish off that local scope we created to have our own variables
44
+ if (CExceptionFrames[CEXCEPTION_GET_ID].Exception != CEXCEPTION_NONE) <- start the actual 'catch' processing if we have an exception id saved away
45
+ */
46
+
@@ -0,0 +1,110 @@
1
+ #ifndef _CEXCEPTION_H
2
+ #define _CEXCEPTION_H
3
+
4
+ #include <setjmp.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C"
8
+ {
9
+ #endif
10
+
11
+
12
+ //To Use CException, you have a number of options:
13
+ //1. Just include it and run with the defaults
14
+ //2. Define any of the following symbols at the command line to override them
15
+ //3. Include a header file before CException.h everywhere which defines any of these
16
+ //4. Create an Exception.h in your path, and just define EXCEPTION_USE_CONFIG_FILE first
17
+
18
+ #ifdef CEXCEPTION_USE_CONFIG_FILE
19
+ #include "CExceptionConfig.h"
20
+ #endif
21
+
22
+ //This is the value to assign when there isn't an exception
23
+ #ifndef CEXCEPTION_NONE
24
+ #define CEXCEPTION_NONE (0x5A5A5A5A)
25
+ #endif
26
+
27
+ //This is number of exception stacks to keep track of (one per task)
28
+ #ifndef CEXCEPTION_NUM_ID
29
+ #define CEXCEPTION_NUM_ID (1) //there is only the one stack by default
30
+ #endif
31
+
32
+ //This is the method of getting the current exception stack index (0 if only one stack)
33
+ #ifndef CEXCEPTION_GET_ID
34
+ #define CEXCEPTION_GET_ID (0) //use the first index always because there is only one anyway
35
+ #endif
36
+
37
+ //The type to use to store the exception values.
38
+ #ifndef CEXCEPTION_T
39
+ #define CEXCEPTION_T unsigned int
40
+ #endif
41
+
42
+ //This is an optional special handler for when there is no global Catch
43
+ #ifndef CEXCEPTION_NO_CATCH_HANDLER
44
+ #define CEXCEPTION_NO_CATCH_HANDLER(id)
45
+ #endif
46
+
47
+ //These hooks allow you to inject custom code into places, particularly useful for saving and restoring additional state
48
+ #ifndef CEXCEPTION_HOOK_START_TRY
49
+ #define CEXCEPTION_HOOK_START_TRY
50
+ #endif
51
+ #ifndef CEXCEPTION_HOOK_HAPPY_TRY
52
+ #define CEXCEPTION_HOOK_HAPPY_TRY
53
+ #endif
54
+ #ifndef CEXCEPTION_HOOK_AFTER_TRY
55
+ #define CEXCEPTION_HOOK_AFTER_TRY
56
+ #endif
57
+ #ifndef CEXCEPTION_HOOK_START_CATCH
58
+ #define CEXCEPTION_HOOK_START_CATCH
59
+ #endif
60
+
61
+ //exception frame structures
62
+ typedef struct {
63
+ jmp_buf* pFrame;
64
+ CEXCEPTION_T volatile Exception;
65
+ } CEXCEPTION_FRAME_T;
66
+
67
+ //actual root frame storage (only one if single-tasking)
68
+ extern volatile CEXCEPTION_FRAME_T CExceptionFrames[];
69
+
70
+ //Try (see C file for explanation)
71
+ #define Try \
72
+ { \
73
+ jmp_buf *PrevFrame, NewFrame; \
74
+ unsigned int MY_ID = CEXCEPTION_GET_ID; \
75
+ PrevFrame = CExceptionFrames[MY_ID].pFrame; \
76
+ CExceptionFrames[MY_ID].pFrame = (jmp_buf*)(&NewFrame); \
77
+ CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; \
78
+ CEXCEPTION_HOOK_START_TRY; \
79
+ if (setjmp(NewFrame) == 0) { \
80
+ if (1)
81
+
82
+ //Catch (see C file for explanation)
83
+ #define Catch(e) \
84
+ else { } \
85
+ CExceptionFrames[MY_ID].Exception = CEXCEPTION_NONE; \
86
+ CEXCEPTION_HOOK_HAPPY_TRY; \
87
+ } \
88
+ else \
89
+ { \
90
+ e = CExceptionFrames[MY_ID].Exception; \
91
+ (void)e; \
92
+ CEXCEPTION_HOOK_START_CATCH; \
93
+ } \
94
+ CExceptionFrames[MY_ID].pFrame = PrevFrame; \
95
+ CEXCEPTION_HOOK_AFTER_TRY; \
96
+ } \
97
+ if (CExceptionFrames[CEXCEPTION_GET_ID].Exception != CEXCEPTION_NONE)
98
+
99
+ //Throw an Error
100
+ void Throw(CEXCEPTION_T ExceptionID);
101
+
102
+ //Just exit the Try block and skip the Catch.
103
+ #define ExitTry() Throw(CEXCEPTION_NONE)
104
+
105
+ #ifdef __cplusplus
106
+ } // extern "C"
107
+ #endif
108
+
109
+
110
+ #endif // _CEXCEPTION_H
@@ -0,0 +1,24 @@
1
+ #Tool and Lib Locations
2
+ C_COMPILER=gcc
3
+ C_LIBS=C:/MinGW/lib
4
+ UNITY_DIR=vendor/unity/src
5
+
6
+ #Test File To Be Created
7
+ OUT_FILE=test_cexceptions
8
+ ifeq ($(OS),Windows_NT)
9
+ OUT_EXTENSION=.exe
10
+ else
11
+ OUT_EXTENSION=.out
12
+ endif
13
+
14
+ #Options
15
+ SRC_FILES=lib/CException.c test/TestException.c test/TestException_Runner.c $(UNITY_DIR)/unity.c
16
+ INC_DIRS=-Ilib -Itest -I$(UNITY_DIR)
17
+ LIB_DIRS=-L$(C_LIBS)
18
+ SYMBOLS=-DTEST -DCEXCEPTION_USE_CONFIG_FILE
19
+
20
+ #Default Task: Compile And Run Tests
21
+ default:
22
+ $(C_COMPILER) $(INC_DIRS) $(LIB_DIRS) $(SYMBOLS) $(SRC_FILES) -o $(OUT_FILE)$(OUT_EXTENSION)
23
+ $(OUT_FILE)$(OUT_EXTENSION)
24
+
@@ -0,0 +1,46 @@
1
+ #ifndef _EXCEPTION_H
2
+ #define _EXCEPTION_H
3
+
4
+ #include "unity.h"
5
+
6
+ extern volatile int TestingTheFallback;
7
+ extern volatile int TestingTheFallbackId;
8
+
9
+ //Optionally define the exception type (something like an int which can be directly assigned)
10
+ #define CEXCEPTION_T int
11
+
12
+ // Optionally define the reserved value representing NO EXCEPTION
13
+ #define CEXCEPTION_NONE (1234)
14
+
15
+ // Optionally define a special handler for unhandled exceptions
16
+ #define CEXCEPTION_NO_CATCH_HANDLER(id) \
17
+ { \
18
+ if (!TestingTheFallback) \
19
+ { \
20
+ TEST_FAIL_MESSAGE("Unexpected Exception!"); \
21
+ } \
22
+ else \
23
+ { \
24
+ TestingTheFallbackId = id; \
25
+ TestingTheFallback--; \
26
+ } \
27
+ }
28
+
29
+ // Multi-Tasking environments will need a couple of macros defined to make this library
30
+ // properly handle multiple exception stacks. You will need to include and required
31
+ // definitions, then define the following macros:
32
+ // EXCEPTION_GET_ID - returns the id of the current task indexed 0 to (numtasks - 1)
33
+ // EXCEPTION_NUM_ID - returns the number of tasks that might be returned
34
+ //
35
+ // For example, Quadros might include the following implementation:
36
+ #ifndef TEST
37
+ #include "OSAPI.h"
38
+ #define CEXCEPTION_GET_ID (KS_GetTaskID())
39
+ #define CEXCEPTION_NUM_ID (NTASKS + 1)
40
+ #endif
41
+
42
+ //This could be a good place to define/include some error ID's:
43
+ #define ERROR_ID_EVERYTHING_IS_BROKEN (0x88)
44
+ #define ERROR_ID_ONLY_THIS_IS_BROKEN (0x77)
45
+
46
+ #endif // _EXCEPTION_H
@@ -0,0 +1,391 @@
1
+ #include "unity.h"
2
+ #include "CException.h"
3
+
4
+ volatile int TestingTheFallback;
5
+ volatile int TestingTheFallbackId;
6
+
7
+ void setUp(void)
8
+ {
9
+ CExceptionFrames[0].pFrame = NULL;
10
+ TestingTheFallback = 0;
11
+ }
12
+
13
+ void tearDown(void)
14
+ {
15
+ }
16
+
17
+ void test_BasicTryDoesNothingIfNoThrow(void)
18
+ {
19
+ int i = 0;
20
+ CEXCEPTION_T e = 0x5a;
21
+
22
+ Try
23
+ {
24
+ i += 1;
25
+ }
26
+ Catch(e)
27
+ {
28
+ TEST_FAIL_MESSAGE("Should Not Enter Catch If Not Thrown");
29
+ }
30
+
31
+ //verify that e was untouched
32
+ TEST_ASSERT_EQUAL(0x5a, e);
33
+
34
+ // verify that i was incremented once
35
+ TEST_ASSERT_EQUAL(1, i);
36
+ }
37
+
38
+ void test_BasicThrowAndCatch(void)
39
+ {
40
+ CEXCEPTION_T e;
41
+
42
+ Try
43
+ {
44
+ Throw(0xBE);
45
+ TEST_FAIL_MESSAGE("Should Have Thrown An Error");
46
+ }
47
+ Catch(e)
48
+ {
49
+ //verify that e has the right data
50
+ TEST_ASSERT_EQUAL(0xBE, e);
51
+ }
52
+
53
+ //verify that e STILL has the right data
54
+ TEST_ASSERT_EQUAL(0xBE, e);
55
+ }
56
+
57
+ void test_BasicThrowAndCatch_WithMiniSyntax(void)
58
+ {
59
+ CEXCEPTION_T e;
60
+
61
+ //Mini Throw and Catch
62
+ Try
63
+ Throw(0xEF);
64
+ Catch(e)
65
+ TEST_ASSERT_EQUAL(0xEF, e);
66
+ TEST_ASSERT_EQUAL(0xEF, e);
67
+
68
+ //Mini Passthrough
69
+ Try
70
+ e = 0;
71
+ Catch(e)
72
+ TEST_FAIL_MESSAGE("I shouldn't be caught because there was no throw");
73
+
74
+ TEST_ASSERT_EQUAL(0, e);
75
+ }
76
+
77
+ void test_VerifyVolatilesSurviveThrowAndCatch(void)
78
+ {
79
+ volatile unsigned int VolVal = 0;
80
+ CEXCEPTION_T e;
81
+
82
+ Try
83
+ {
84
+ VolVal = 2;
85
+ Throw(0xBF);
86
+ TEST_FAIL_MESSAGE("Should Have Thrown An Error");
87
+ }
88
+ Catch(e)
89
+ {
90
+ VolVal += 2;
91
+ TEST_ASSERT_EQUAL(0xBF, e);
92
+ }
93
+
94
+ TEST_ASSERT_EQUAL(4, VolVal);
95
+ TEST_ASSERT_EQUAL(0xBF, e);
96
+ }
97
+
98
+ void HappyExceptionThrower(unsigned int ID)
99
+ {
100
+ if (ID != 0)
101
+ {
102
+ Throw(ID);
103
+ }
104
+ }
105
+
106
+ void test_ThrowFromASubFunctionAndCatchInRootFunc(void)
107
+ {
108
+ volatile unsigned int ID = 0;
109
+ CEXCEPTION_T e;
110
+
111
+ Try
112
+ {
113
+
114
+ HappyExceptionThrower(0xBA);
115
+ TEST_FAIL_MESSAGE("Should Have Thrown An Exception");
116
+ }
117
+ Catch(e)
118
+ {
119
+ ID = e;
120
+ }
121
+
122
+ //verify that I can pass that value to something else
123
+ TEST_ASSERT_EQUAL(0xBA, e);
124
+ //verify that ID and e have the same value
125
+ TEST_ASSERT_EQUAL(ID, e);
126
+ }
127
+
128
+ void HappyExceptionRethrower(unsigned int ID)
129
+ {
130
+ CEXCEPTION_T e;
131
+
132
+ Try
133
+ {
134
+ Throw(ID);
135
+ }
136
+ Catch(e)
137
+ {
138
+ switch (e)
139
+ {
140
+ case 0xBD:
141
+ Throw(0xBF);
142
+ break;
143
+ default:
144
+ break;
145
+ }
146
+ }
147
+ }
148
+
149
+ void test_ThrowAndCatchFromASubFunctionAndRethrowToCatchInRootFunc(void)
150
+ {
151
+ volatile unsigned int ID = 0;
152
+ CEXCEPTION_T e;
153
+
154
+ Try
155
+ {
156
+ HappyExceptionRethrower(0xBD);
157
+ TEST_FAIL_MESSAGE("Should Have Rethrown Exception");
158
+ }
159
+ Catch(e)
160
+ {
161
+ ID = 1;
162
+ }
163
+
164
+ TEST_ASSERT_EQUAL(0xBF, e);
165
+ TEST_ASSERT_EQUAL(1, ID);
166
+ }
167
+
168
+ void test_ThrowAndCatchFromASubFunctionAndNoRethrowToCatchInRootFunc(void)
169
+ {
170
+ CEXCEPTION_T e = 3;
171
+
172
+ Try
173
+ {
174
+ HappyExceptionRethrower(0xBF);
175
+ }
176
+ Catch(e)
177
+ {
178
+ TEST_FAIL_MESSAGE("Should Not Have Re-thrown Error (it should have already been caught)");
179
+ }
180
+
181
+ //verify that THIS e is still untouched, even though subfunction was touched
182
+ TEST_ASSERT_EQUAL(3, e);
183
+ }
184
+
185
+ void test_ThrowAnErrorThenEnterATryBlockFromWithinCatch_VerifyThisDoesntCorruptExceptionId(void)
186
+ {
187
+ CEXCEPTION_T e;
188
+
189
+ Try
190
+ {
191
+ HappyExceptionThrower(0xBF);
192
+ TEST_FAIL_MESSAGE("Should Have Thrown Exception");
193
+ }
194
+ Catch(e)
195
+ {
196
+ TEST_ASSERT_EQUAL(0xBF, e);
197
+ HappyExceptionRethrower(0x12);
198
+ TEST_ASSERT_EQUAL(0xBF, e);
199
+ }
200
+ TEST_ASSERT_EQUAL(0xBF, e);
201
+ }
202
+
203
+ void test_ThrowAnErrorThenEnterATryBlockFromWithinCatch_VerifyThatEachExceptionIdIndependent(void)
204
+ {
205
+ CEXCEPTION_T e1, e2;
206
+
207
+ Try
208
+ {
209
+ HappyExceptionThrower(0xBF);
210
+ TEST_FAIL_MESSAGE("Should Have Thrown Exception");
211
+ }
212
+ Catch(e1)
213
+ {
214
+ TEST_ASSERT_EQUAL(0xBF, e1);
215
+ Try
216
+ {
217
+ HappyExceptionThrower(0x12);
218
+ }
219
+ Catch(e2)
220
+ {
221
+ TEST_ASSERT_EQUAL(0x12, e2);
222
+ }
223
+ TEST_ASSERT_EQUAL(0x12, e2);
224
+ TEST_ASSERT_EQUAL(0xBF, e1);
225
+ }
226
+ TEST_ASSERT_EQUAL(0x12, e2);
227
+ TEST_ASSERT_EQUAL(0xBF, e1);
228
+ }
229
+
230
+ void test_CanHaveMultipleTryBlocksInASingleFunction(void)
231
+ {
232
+ CEXCEPTION_T e;
233
+
234
+ Try
235
+ {
236
+ HappyExceptionThrower(0x01);
237
+ TEST_FAIL_MESSAGE("Should Have Thrown Exception");
238
+ }
239
+ Catch(e)
240
+ {
241
+ TEST_ASSERT_EQUAL(0x01, e);
242
+ }
243
+
244
+ Try
245
+ {
246
+ HappyExceptionThrower(0xF0);
247
+ TEST_FAIL_MESSAGE("Should Have Thrown Exception");
248
+ }
249
+ Catch(e)
250
+ {
251
+ TEST_ASSERT_EQUAL(0xF0, e);
252
+ }
253
+ }
254
+
255
+ void test_CanHaveNestedTryBlocksInASingleFunction_ThrowInside(void)
256
+ {
257
+ int i = 0;
258
+ CEXCEPTION_T e;
259
+
260
+ Try
261
+ {
262
+ Try
263
+ {
264
+ HappyExceptionThrower(0x01);
265
+ i = 1;
266
+ TEST_FAIL_MESSAGE("Should Have Rethrown Exception");
267
+ }
268
+ Catch(e)
269
+ {
270
+ TEST_ASSERT_EQUAL(0x01, e);
271
+ }
272
+ }
273
+ Catch(e)
274
+ {
275
+ TEST_FAIL_MESSAGE("Should Have Been Caught By Inside Catch");
276
+ }
277
+
278
+ // verify that i is still zero
279
+ TEST_ASSERT_EQUAL(0, i);
280
+ }
281
+
282
+ void test_CanHaveNestedTryBlocksInASingleFunction_ThrowOutside(void)
283
+ {
284
+ int i = 0;
285
+ CEXCEPTION_T e;
286
+
287
+ Try
288
+ {
289
+ Try
290
+ {
291
+ i = 2;
292
+ }
293
+ Catch(e)
294
+ {
295
+ TEST_FAIL_MESSAGE("Should Not Be Caught Here");
296
+ }
297
+ HappyExceptionThrower(0x01);
298
+ TEST_FAIL_MESSAGE("Should Have Rethrown Exception");
299
+ }
300
+ Catch(e)
301
+ {
302
+ TEST_ASSERT_EQUAL(0x01, e);
303
+ }
304
+
305
+ // verify that i is 2
306
+ TEST_ASSERT_EQUAL(2, i);
307
+ }
308
+
309
+ void test_AThrowWithoutATryCatchWillUseDefaultHandlerIfSpecified(void)
310
+ {
311
+ //Let the fallback handler know we're expecting it to get called this time, so don't fail
312
+ TestingTheFallback = 1;
313
+
314
+ Throw(0xBE);
315
+
316
+ //We know the fallback was run because it decrements the counter above
317
+ TEST_ASSERT_FALSE(TestingTheFallback);
318
+ TEST_ASSERT_EQUAL(0xBE, TestingTheFallbackId);
319
+ }
320
+
321
+ void test_AThrowWithoutOutsideATryCatchWillUseDefaultHandlerEvenAfterTryCatch(void)
322
+ {
323
+ CEXCEPTION_T e;
324
+
325
+ Try
326
+ {
327
+ //It's not really important that we do anything here.
328
+ }
329
+ Catch(e)
330
+ {
331
+ //The entire purpose here is just to make sure things get set back to using the default handler when done
332
+ }
333
+
334
+ //Let the fallback handler know we're expecting it to get called this time, so don't fail
335
+ TestingTheFallback = 1;
336
+
337
+ Throw(0xBE);
338
+
339
+ //We know the fallback was run because it decrements the counter above
340
+ TEST_ASSERT_FALSE(TestingTheFallback);
341
+ TEST_ASSERT_EQUAL(0xBE, TestingTheFallbackId);
342
+ }
343
+
344
+ void test_AbilityToExitTryWithoutThrowingAnError(void)
345
+ {
346
+ int i=0;
347
+ CEXCEPTION_T e;
348
+
349
+ Try
350
+ {
351
+ ExitTry();
352
+ i = 1;
353
+ TEST_FAIL_MESSAGE("Should Have Exited Try Before This");
354
+ }
355
+ Catch(e)
356
+ {
357
+ i = 2;
358
+ TEST_FAIL_MESSAGE("Should Not Have Been Caught");
359
+ }
360
+
361
+ // verify that i is still zero
362
+ TEST_ASSERT_EQUAL(0, i);
363
+ }
364
+
365
+ void test_AbilityToExitTryWillOnlyExitOneLevel(void)
366
+ {
367
+ int i=0;
368
+ CEXCEPTION_T e;
369
+ CEXCEPTION_T e2;
370
+
371
+ Try
372
+ {
373
+ Try
374
+ {
375
+ ExitTry();
376
+ TEST_FAIL_MESSAGE("Should Have Exited Try Before This");
377
+ }
378
+ Catch(e)
379
+ {
380
+ TEST_FAIL_MESSAGE("Should Not Have Been Caught By Inside");
381
+ }
382
+ i = 1;
383
+ }
384
+ Catch(e2)
385
+ {
386
+ TEST_FAIL_MESSAGE("Should Not Have Been Caught By Outside");
387
+ }
388
+
389
+ // verify that we picked up and ran after first Try
390
+ TEST_ASSERT_EQUAL(1, i);
391
+ }