ceedling 0.31.0 → 0.31.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/example_file_call.c +6 -0
- data/assets/example_file_call.h +6 -0
- data/assets/test_example_file_with_mock.c +13 -0
- data/bin/ceedling +2 -2
- data/ceedling.gemspec +1 -1
- data/lib/ceedling/configurator.rb +7 -2
- data/lib/ceedling/configurator_plugins.rb +21 -1
- data/lib/ceedling/defaults.rb +1 -0
- data/lib/ceedling/preprocessinator_extractor.rb +2 -0
- data/lib/ceedling/preprocessinator_includes_handler.rb +24 -24
- data/lib/ceedling/version.rb +11 -7
- data/plugins/gcov/config/defaults_gcov.rb +118 -0
- data/plugins/gcov/lib/gcovr_reportinator.rb +1 -1
- data/plugins/gcov/lib/reportgenerator_reportinator.rb +1 -1
- data/plugins/junit_tests_report/lib/junit_tests_report.rb +6 -6
- data/plugins/module_generator/README.md +16 -2
- data/plugins/module_generator/lib/module_generator.rb +1 -0
- data/spec/gcov/gcov_deployment_spec.rb +1 -1
- data/spec/preprocessinator_includes_handler_spec.rb +38 -8
- data/spec/spec_system_helper.rb +19 -0
- data/spec/system/deployment_spec.rb +1 -0
- data/vendor/cmock/lib/cmock_file_writer.rb +2 -3
- data/vendor/cmock/lib/cmock_generator.rb +87 -70
- data/vendor/cmock/lib/cmock_header_parser.rb +29 -27
- data/vendor/cmock/src/cmock.h +1 -1
- data/vendor/cmock/test/unit/cmock_generator_main_test.rb +46 -41
- data/vendor/cmock/test/unit/cmock_header_parser_test.rb +46 -40
- data/vendor/cmock/vendor/c_exception/README.md +6 -4
- data/vendor/cmock/vendor/c_exception/docs/CException.md +2 -2
- data/vendor/cmock/vendor/c_exception/lib/CException.h +1 -1
- data/vendor/cmock/vendor/c_exception/lib/meson.build +2 -2
- data/vendor/cmock/vendor/c_exception/meson.build +36 -2
- data/vendor/cmock/vendor/unity/README.md +77 -71
- data/vendor/cmock/vendor/unity/auto/generate_test_runner.rb +1 -1
- data/vendor/cmock/vendor/unity/docs/ThrowTheSwitchCodingStandard.md +107 -126
- data/vendor/cmock/vendor/unity/docs/UnityAssertionsReference.md +149 -193
- data/vendor/cmock/vendor/unity/docs/UnityConfigurationGuide.md +236 -294
- data/vendor/cmock/vendor/unity/docs/UnityGettingStartedGuide.md +112 -121
- data/vendor/cmock/vendor/unity/docs/UnityHelperScriptsGuide.md +82 -115
- data/vendor/cmock/vendor/unity/extras/fixture/readme.md +16 -19
- data/vendor/cmock/vendor/unity/extras/memory/readme.md +27 -34
- data/vendor/cmock/vendor/unity/src/unity.c +1 -1
- data/vendor/cmock/vendor/unity/src/unity.h +1 -1
- data/vendor/cmock/vendor/unity/src/unity_internals.h +21 -7
- data/vendor/unity/README.md +77 -71
- data/vendor/unity/auto/generate_test_runner.rb +1 -1
- data/vendor/unity/docs/ThrowTheSwitchCodingStandard.md +107 -126
- data/vendor/unity/docs/UnityAssertionsReference.md +149 -193
- data/vendor/unity/docs/UnityConfigurationGuide.md +236 -294
- data/vendor/unity/docs/UnityGettingStartedGuide.md +112 -121
- data/vendor/unity/docs/UnityHelperScriptsGuide.md +82 -115
- data/vendor/unity/extras/fixture/readme.md +16 -19
- data/vendor/unity/extras/memory/readme.md +27 -34
- data/vendor/unity/src/unity.c +1 -1
- data/vendor/unity/src/unity.h +1 -1
- data/vendor/unity/src/unity_internals.h +21 -7
- metadata +14 -5
- data/plugins/gcov/config/defaults.yml +0 -55
@@ -1,5 +1,7 @@
|
|
1
|
-
CException
|
2
|
-
|
1
|
+
CException - Lightweight exception library for C
|
2
|
+
================================================
|
3
|
+
|
4
|
+
[![CException Build Status](https://api.travis-ci.org/ThrowTheSwitch/CException.png?branch=master)](https://travis-ci.org/ThrowTheSwitch/CException)
|
3
5
|
|
4
6
|
_This Documentation Is Released Under a Creative Commons 3.0 Attribution Share-Alike License_
|
5
7
|
|
@@ -125,7 +127,7 @@ location was updated and not just a register unless the variable is marked volat
|
|
125
127
|
### Memory Management
|
126
128
|
|
127
129
|
Memory which is `malloc`'d within a `Try` block is not automatically released when an error is thrown. This
|
128
|
-
will sometimes be desirable, and
|
130
|
+
will sometimes be desirable, and othertimes may not. It will be the responsibility of the code you put in
|
129
131
|
the `Catch` block to perform this kind of cleanup.
|
130
132
|
|
131
133
|
There's just no easy way to track `malloc`'d memory, etc., without replacing or wrapping `malloc`
|
@@ -239,7 +241,7 @@ License
|
|
239
241
|
=======
|
240
242
|
|
241
243
|
*This software is licensed under the MIT License:
|
242
|
-
Copyright (c) 2007-
|
244
|
+
Copyright (c) 2007-2019 Mark VanderVoord*
|
243
245
|
|
244
246
|
*Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
245
247
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.*
|
@@ -145,7 +145,7 @@ to successfully utilize this library:
|
|
145
145
|
|
146
146
|
3. Memory which is `malloc`'d or `new`'d is not automatically released
|
147
147
|
when an error is thrown. This will sometimes be desirable, and
|
148
|
-
|
148
|
+
othertimes may not. It will be the responsibility of the `Catch`
|
149
149
|
block to perform this kind of cleanup.
|
150
150
|
|
151
151
|
*Why?*
|
@@ -311,7 +311,7 @@ LICENSE
|
|
311
311
|
|
312
312
|
This software is licensed under the MIT License
|
313
313
|
|
314
|
-
Copyright (c) 2007-
|
314
|
+
Copyright (c) 2007-2020 Mark VanderVoord
|
315
315
|
|
316
316
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
317
317
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -11,7 +11,7 @@ extern "C"
|
|
11
11
|
|
12
12
|
#define CEXCEPTION_VERSION_MAJOR 1
|
13
13
|
#define CEXCEPTION_VERSION_MINOR 3
|
14
|
-
#define CEXCEPTION_VERSION_BUILD
|
14
|
+
#define CEXCEPTION_VERSION_BUILD 2
|
15
15
|
#define CEXCEPTION_VERSION ((CEXCEPTION_VERSION_MAJOR << 16) | (CEXCEPTION_VERSION_MINOR << 8) | CEXCEPTION_VERSION_BUILD)
|
16
16
|
|
17
17
|
//To Use CException, you have a number of options:
|
@@ -4,11 +4,45 @@
|
|
4
4
|
#
|
5
5
|
# license: MIT
|
6
6
|
#
|
7
|
-
project('
|
7
|
+
project('CException', 'c',
|
8
8
|
license: 'MIT',
|
9
9
|
meson_version: '>=0.53.0',
|
10
|
-
default_options: ['werror=true', 'c_std=c11']
|
10
|
+
default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11']
|
11
11
|
)
|
12
|
+
lang = 'c'
|
13
|
+
cc = meson.get_compiler(lang)
|
12
14
|
|
15
|
+
#
|
16
|
+
# Meson: Add compiler flags
|
17
|
+
if cc.get_id() == 'clang'
|
18
|
+
add_project_arguments(cc.get_supported_arguments(
|
19
|
+
[
|
20
|
+
'-Wexit-time-destructors',
|
21
|
+
'-Wglobal-constructors',
|
22
|
+
'-Wmissing-prototypes',
|
23
|
+
'-Wmissing-noreturn',
|
24
|
+
'-Wno-missing-braces',
|
25
|
+
'-Wold-style-cast', '-Wpointer-arith', '-Wweak-vtables',
|
26
|
+
'-Wcast-align', '-Wconversion', '-Wcast-qual', '-Wshadow'
|
27
|
+
]
|
28
|
+
), language: lang)
|
29
|
+
endif
|
30
|
+
|
31
|
+
if cc.get_argument_syntax() == 'gcc'
|
32
|
+
add_project_arguments(cc.get_supported_arguments(
|
33
|
+
[
|
34
|
+
'-Wformat', '-Waddress', '-Winit-self', '-Wno-multichar',
|
35
|
+
'-Wpointer-arith' , '-Wwrite-strings' ,
|
36
|
+
'-Wno-parentheses' , '-Wno-type-limits' ,
|
37
|
+
'-Wformat-security' , '-Wunreachable-code' ,
|
38
|
+
'-Waggregate-return' , '-Wformat-nonliteral' ,
|
39
|
+
'-Wmissing-declarations', '-Wmissing-include-dirs' ,
|
40
|
+
'-Wno-unused-parameter'
|
41
|
+
]
|
42
|
+
), language: lang)
|
43
|
+
endif
|
44
|
+
|
45
|
+
#
|
46
|
+
# Sub directory to project source code
|
13
47
|
subdir('lib')
|
14
48
|
cexception_dep = declare_dependency(link_with: cexception_lib, include_directories: cexception_dir)
|
@@ -1,29 +1,26 @@
|
|
1
|
-
Unity Test ![CI]
|
2
|
-
|
1
|
+
# Unity Test ![CI][]
|
2
|
+
|
3
3
|
__Copyright (c) 2007 - 2021 Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
|
4
4
|
|
5
|
-
Welcome to the Unity Test Project, one of the main projects of ThrowTheSwitch.org.
|
6
|
-
unit testing framework built for C, with a focus on working with embedded toolchains.
|
5
|
+
Welcome to the Unity Test Project, one of the main projects of ThrowTheSwitch.org.
|
6
|
+
Unity Test is a unit testing framework built for C, with a focus on working with embedded toolchains.
|
7
|
+
|
8
|
+
This project is made to test code targetting microcontrollers big and small.
|
9
|
+
The core project is a single C file and a pair of headers, allowing it to the added to your existing build setup without too much headache.
|
10
|
+
You may use any compiler you wish, and may use most existing build systems including Make, CMake, etc.
|
11
|
+
If you'd like to leave the hard work to us, you might be interested in Ceedling, a build tool also by ThrowTheSwitch.org.
|
7
12
|
|
8
|
-
|
9
|
-
single C file and a pair of headers, allowing it to the added to your existing build setup without
|
10
|
-
too much headache. You may use any compiler you wish, and may use most existing build systems
|
11
|
-
including make, cmake, etc. If you'd like to leave the hard work to us, you might be interested
|
12
|
-
in Ceedling, a build tool also by ThrowTheSwitch.org.
|
13
|
+
If you're new to Unity, we encourage you to tour the [getting started guide][].
|
13
14
|
|
14
|
-
|
15
|
+
## Getting Started
|
15
16
|
|
16
|
-
|
17
|
-
===============
|
18
|
-
The [docs](docs/) folder contains a [getting started guide](docs/UnityGettingStartedGuide.md)
|
19
|
-
and much more tips about using Unity.
|
17
|
+
The [docs][] folder contains a [getting started guide][] and much more tips about using Unity.
|
20
18
|
|
21
|
-
Unity Assertion Summary
|
22
|
-
=======================
|
23
|
-
For the full list, see [UnityAssertionsReference.md](docs/UnityAssertionsReference.md).
|
19
|
+
## Unity Assertion Summary
|
24
20
|
|
25
|
-
|
26
|
-
|
21
|
+
For the full list, see [UnityAssertionsReference.md][].
|
22
|
+
|
23
|
+
### Basic Validity Tests
|
27
24
|
|
28
25
|
TEST_ASSERT_TRUE(condition)
|
29
26
|
|
@@ -44,10 +41,10 @@ Another way of calling `TEST_ASSERT_FALSE`
|
|
44
41
|
TEST_FAIL()
|
45
42
|
TEST_FAIL_MESSAGE(message)
|
46
43
|
|
47
|
-
This test is automatically marked as a failure.
|
44
|
+
This test is automatically marked as a failure.
|
45
|
+
The message is output stating why.
|
48
46
|
|
49
|
-
Numerical Assertions: Integers
|
50
|
-
------------------------------
|
47
|
+
### Numerical Assertions: Integers
|
51
48
|
|
52
49
|
TEST_ASSERT_EQUAL_INT(expected, actual)
|
53
50
|
TEST_ASSERT_EQUAL_INT8(expected, actual)
|
@@ -55,9 +52,9 @@ Numerical Assertions: Integers
|
|
55
52
|
TEST_ASSERT_EQUAL_INT32(expected, actual)
|
56
53
|
TEST_ASSERT_EQUAL_INT64(expected, actual)
|
57
54
|
|
58
|
-
Compare two integers for equality and display errors as signed integers.
|
59
|
-
to your natural integer size so often this can just be used.
|
60
|
-
like when comparing arrays, you can use a specific version:
|
55
|
+
Compare two integers for equality and display errors as signed integers.
|
56
|
+
A cast will be performed to your natural integer size so often this can just be used.
|
57
|
+
When you need to specify the exact size, like when comparing arrays, you can use a specific version:
|
61
58
|
|
62
59
|
TEST_ASSERT_EQUAL_UINT(expected, actual)
|
63
60
|
TEST_ASSERT_EQUAL_UINT8(expected, actual)
|
@@ -65,8 +62,8 @@ like when comparing arrays, you can use a specific version:
|
|
65
62
|
TEST_ASSERT_EQUAL_UINT32(expected, actual)
|
66
63
|
TEST_ASSERT_EQUAL_UINT64(expected, actual)
|
67
64
|
|
68
|
-
Compare two integers for equality and display errors as unsigned integers.
|
69
|
-
variants for different sizes also.
|
65
|
+
Compare two integers for equality and display errors as unsigned integers.
|
66
|
+
Like INT, there are variants for different sizes also.
|
70
67
|
|
71
68
|
TEST_ASSERT_EQUAL_HEX(expected, actual)
|
72
69
|
TEST_ASSERT_EQUAL_HEX8(expected, actual)
|
@@ -74,9 +71,8 @@ variants for different sizes also.
|
|
74
71
|
TEST_ASSERT_EQUAL_HEX32(expected, actual)
|
75
72
|
TEST_ASSERT_EQUAL_HEX64(expected, actual)
|
76
73
|
|
77
|
-
Compares two integers for equality and display errors as hexadecimal.
|
78
|
-
you can specify the size... here the size will also effect how many nibbles are shown (for example, `HEX16`
|
79
|
-
will show 4 nibbles).
|
74
|
+
Compares two integers for equality and display errors as hexadecimal.
|
75
|
+
Like the other integer comparisons, you can specify the size... here the size will also effect how many nibbles are shown (for example, `HEX16` will show 4 nibbles).
|
80
76
|
|
81
77
|
TEST_ASSERT_EQUAL(expected, actual)
|
82
78
|
|
@@ -84,63 +80,66 @@ Another way of calling TEST_ASSERT_EQUAL_INT
|
|
84
80
|
|
85
81
|
TEST_ASSERT_INT_WITHIN(delta, expected, actual)
|
86
82
|
|
87
|
-
Asserts that the actual value is within plus or minus delta of the expected value.
|
88
|
-
size specific variants.
|
89
|
-
|
83
|
+
Asserts that the actual value is within plus or minus delta of the expected value.
|
84
|
+
This also comes in size specific variants.
|
90
85
|
|
91
86
|
TEST_ASSERT_GREATER_THAN(threshold, actual)
|
92
87
|
|
93
|
-
Asserts that the actual value is greater than the threshold.
|
94
|
-
|
88
|
+
Asserts that the actual value is greater than the threshold.
|
89
|
+
This also comes in size specific variants.
|
95
90
|
|
96
91
|
TEST_ASSERT_LESS_THAN(threshold, actual)
|
97
92
|
|
98
|
-
Asserts that the actual value is less than the threshold.
|
99
|
-
|
93
|
+
Asserts that the actual value is less than the threshold.
|
94
|
+
This also comes in size specific variants.
|
100
95
|
|
101
|
-
Arrays
|
102
|
-
------
|
96
|
+
### Arrays
|
103
97
|
|
104
98
|
_ARRAY
|
105
99
|
|
106
|
-
You can append `_ARRAY` to any of these macros to make an array comparison of that type.
|
107
|
-
need to care a bit more about the actual size of the value being checked.
|
108
|
-
additional argument which is the number of elements to compare.
|
100
|
+
You can append `_ARRAY` to any of these macros to make an array comparison of that type.
|
101
|
+
Here you will need to care a bit more about the actual size of the value being checked.
|
102
|
+
You will also specify an additional argument which is the number of elements to compare.
|
103
|
+
For example:
|
109
104
|
|
110
105
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, elements)
|
111
106
|
|
112
107
|
_EACH_EQUAL
|
113
108
|
|
114
|
-
Another array comparison option is to check that EVERY element of an array is equal to a single expected
|
115
|
-
|
109
|
+
Another array comparison option is to check that EVERY element of an array is equal to a single expected value.
|
110
|
+
You do this by specifying the EACH_EQUAL macro.
|
111
|
+
For example:
|
116
112
|
|
117
113
|
TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, elements)
|
118
114
|
|
119
|
-
Numerical Assertions: Bitwise
|
120
|
-
-----------------------------
|
115
|
+
### Numerical Assertions: Bitwise
|
121
116
|
|
122
117
|
TEST_ASSERT_BITS(mask, expected, actual)
|
123
118
|
|
124
|
-
Use an integer mask to specify which bits should be compared between two other integers.
|
119
|
+
Use an integer mask to specify which bits should be compared between two other integers.
|
120
|
+
High bits in the mask are compared, low bits ignored.
|
125
121
|
|
126
122
|
TEST_ASSERT_BITS_HIGH(mask, actual)
|
127
123
|
|
128
|
-
Use an integer mask to specify which bits should be inspected to determine if they are all set high.
|
124
|
+
Use an integer mask to specify which bits should be inspected to determine if they are all set high.
|
125
|
+
High bits in the mask are compared, low bits ignored.
|
129
126
|
|
130
127
|
TEST_ASSERT_BITS_LOW(mask, actual)
|
131
128
|
|
132
|
-
Use an integer mask to specify which bits should be inspected to determine if they are all set low.
|
129
|
+
Use an integer mask to specify which bits should be inspected to determine if they are all set low.
|
130
|
+
High bits in the mask are compared, low bits ignored.
|
133
131
|
|
134
132
|
TEST_ASSERT_BIT_HIGH(bit, actual)
|
135
133
|
|
136
|
-
Test a single bit and verify that it is high.
|
134
|
+
Test a single bit and verify that it is high.
|
135
|
+
The bit is specified 0-31 for a 32-bit integer.
|
137
136
|
|
138
137
|
TEST_ASSERT_BIT_LOW(bit, actual)
|
139
138
|
|
140
|
-
Test a single bit and verify that it is low.
|
139
|
+
Test a single bit and verify that it is low.
|
140
|
+
The bit is specified 0-31 for a 32-bit integer.
|
141
141
|
|
142
|
-
Numerical Assertions: Floats
|
143
|
-
----------------------------
|
142
|
+
### Numerical Assertions: Floats
|
144
143
|
|
145
144
|
TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual)
|
146
145
|
|
@@ -151,29 +150,34 @@ Asserts that the actual value is within plus or minus delta of the expected valu
|
|
151
150
|
|
152
151
|
Asserts that two floating point values are "equal" within a small % delta of the expected value.
|
153
152
|
|
154
|
-
String Assertions
|
155
|
-
-----------------
|
153
|
+
### String Assertions
|
156
154
|
|
157
155
|
TEST_ASSERT_EQUAL_STRING(expected, actual)
|
158
156
|
|
159
|
-
Compare two null-terminate strings.
|
157
|
+
Compare two null-terminate strings.
|
158
|
+
Fail if any character is different or if the lengths are different.
|
160
159
|
|
161
160
|
TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len)
|
162
161
|
|
163
|
-
Compare two strings.
|
162
|
+
Compare two strings.
|
163
|
+
Fail if any character is different, stop comparing after len characters.
|
164
164
|
|
165
165
|
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message)
|
166
166
|
|
167
|
-
Compare two null-terminate strings.
|
167
|
+
Compare two null-terminate strings.
|
168
|
+
Fail if any character is different or if the lengths are different.
|
169
|
+
Output a custom message on failure.
|
168
170
|
|
169
171
|
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message)
|
170
172
|
|
171
|
-
Compare two strings.
|
173
|
+
Compare two strings.
|
174
|
+
Fail if any character is different, stop comparing after len characters.
|
175
|
+
Output a custom message on failure.
|
172
176
|
|
173
|
-
Pointer Assertions
|
174
|
-
------------------
|
177
|
+
### Pointer Assertions
|
175
178
|
|
176
|
-
Most pointer operations can be performed by simply using the integer comparisons above.
|
179
|
+
Most pointer operations can be performed by simply using the integer comparisons above.
|
180
|
+
However, a couple of special cases are added for clarity.
|
177
181
|
|
178
182
|
TEST_ASSERT_NULL(pointer)
|
179
183
|
|
@@ -183,18 +187,20 @@ Fails if the pointer is not equal to NULL
|
|
183
187
|
|
184
188
|
Fails if the pointer is equal to NULL
|
185
189
|
|
186
|
-
Memory Assertions
|
187
|
-
-----------------
|
190
|
+
### Memory Assertions
|
188
191
|
|
189
192
|
TEST_ASSERT_EQUAL_MEMORY(expected, actual, len)
|
190
193
|
|
191
|
-
Compare two blocks of memory.
|
192
|
-
standard types... but since it's a memory compare, you have to be careful that your data types are packed.
|
194
|
+
Compare two blocks of memory.
|
195
|
+
This is a good generic assertion for types that can't be coerced into acting like standard types... but since it's a memory compare, you have to be careful that your data types are packed.
|
193
196
|
|
194
|
-
\_MESSAGE
|
195
|
-
---------
|
197
|
+
### \_MESSAGE
|
196
198
|
|
197
|
-
|
198
|
-
is a string that will be printed at the end of the failure strings.
|
199
|
-
information about the problem.
|
199
|
+
You can append `\_MESSAGE` to any of the macros to make them take an additional argument.
|
200
|
+
This argument is a string that will be printed at the end of the failure strings.
|
201
|
+
This is useful for specifying more information about the problem.
|
200
202
|
|
203
|
+
[CI]: https://github.com/ThrowTheSwitch/Unity/workflows/CI/badge.svg
|
204
|
+
[getting started guide]: docs/UnityGettingStartedGuide.md
|
205
|
+
[docs]: docs/
|
206
|
+
[UnityAssertionsReference.md]: docs/UnityAssertionsReference.md
|
@@ -143,7 +143,7 @@ class UnityTestRunnerGenerator
|
|
143
143
|
arguments.scan(/\s*TEST_CASE\s*\((.*)\)\s*$/) { |a| args << a[0] }
|
144
144
|
|
145
145
|
arguments.scan(/\s*TEST_RANGE\s*\((.*)\)\s*$/).flatten.each do |range_str|
|
146
|
-
args += range_str.scan(/\[(-?\d+.?\d*)
|
146
|
+
args += range_str.scan(/\[\s*(-?\d+.?\d*),\s*(-?\d+.?\d*),\s*(-?\d+.?\d*)\s*\]/).map do |arg_values_str|
|
147
147
|
arg_values_str.map do |arg_value_str|
|
148
148
|
arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i
|
149
149
|
end
|
@@ -1,136 +1,116 @@
|
|
1
1
|
# ThrowTheSwitch.org Coding Standard
|
2
2
|
|
3
|
-
Hi.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
and we'll try to be polite when we notice yours.
|
3
|
+
Hi.
|
4
|
+
Welcome to the coding standard for ThrowTheSwitch.org.
|
5
|
+
For the most part, we try to follow these standards to unify our contributors' code into a cohesive unit (puns intended).
|
6
|
+
You might find places where these standards aren't followed.
|
7
|
+
We're not perfect. Please be polite where you notice these discrepancies and we'll try to be polite when we notice yours.
|
8
8
|
|
9
9
|
;)
|
10
10
|
|
11
|
-
|
12
11
|
## Why Have A Coding Standard?
|
13
12
|
|
14
|
-
Being consistent makes code easier to understand.
|
15
|
-
our standard simple because we also believe that we can only expect someone to
|
16
|
-
|
17
|
-
|
13
|
+
Being consistent makes code easier to understand.
|
14
|
+
We've tried to keep our standard simple because we also believe that we can only expect someone to follow something that is understandable.
|
15
|
+
Please do your best.
|
18
16
|
|
19
17
|
## Our Philosophy
|
20
18
|
|
21
|
-
Before we get into details on syntax, let's take a moment to talk about our
|
22
|
-
|
23
|
-
These tools are great to test any C code, but catering to embedded software
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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.
|
19
|
+
Before we get into details on syntax, let's take a moment to talk about our vision for these tools.
|
20
|
+
We're C developers and embedded software developers.
|
21
|
+
These tools are great to test any C code, but catering to embedded software made us more tolerant of compiler quirks.
|
22
|
+
There are a LOT of quirky compilers out there.
|
23
|
+
By quirky I mean "doesn't follow standards because they feel like they have a license to do as they wish."
|
24
|
+
|
25
|
+
Our philosophy is "support every compiler we can".
|
26
|
+
Most often, this means that we aim for writing C code that is standards compliant (often C89... that seems to be a sweet spot that is almost always compatible).
|
27
|
+
But it also means these tools are tolerant of things that aren't common.
|
28
|
+
Some that aren't even compliant.
|
29
|
+
There are configuration options to override the size of standard types.
|
30
|
+
There are configuration options to force Unity to not use certain standard library functions.
|
31
|
+
A lot of Unity is configurable and we have worked hard to make it not TOO ugly in the process.
|
48
32
|
|
33
|
+
Similarly, our tools that parse C do their best.
|
34
|
+
They aren't full C parsers (yet) and, even if they were, they would still have to accept non-standard additions like gcc extensions or specifying `@0x1000` to force a variable to compile to a particular location.
|
35
|
+
It's just what we do, because we like everything to Just Work™.
|
36
|
+
|
37
|
+
Speaking of having things Just Work™, that's our second philosophy.
|
38
|
+
By that, we mean that we do our best to have EVERY configuration option have a logical default.
|
39
|
+
We believe that if you're working with a simple compiler and target, you shouldn't need to configure very much... we try to make the tools guess as much as they can, but give the user the power to override it when it's wrong.
|
49
40
|
|
50
41
|
## Naming Things
|
51
42
|
|
52
|
-
Let's talk about naming things.
|
53
|
-
|
54
|
-
|
55
|
-
finding *What Something WANTS to be Called*™.
|
43
|
+
Let's talk about naming things.
|
44
|
+
Programming is all about naming things.
|
45
|
+
We name files, functions, variables, and so much more.
|
46
|
+
While we're not always going to find the best name for something, we actually put a bit of effort into finding *What Something WANTS to be Called*™.
|
47
|
+
|
48
|
+
When naming things, we follow this hierarchy, the first being the most important to us (but we do all four when possible):
|
56
49
|
|
57
|
-
When naming things, we follow this hierarchy, the first being the
|
58
|
-
most important to us (but we do all four when possible):
|
59
50
|
1. Readable
|
60
51
|
2. Descriptive
|
61
52
|
3. Consistent
|
62
53
|
4. Memorable
|
63
54
|
|
55
|
+
### Readable
|
64
56
|
|
65
|
-
|
57
|
+
We want to read our code.
|
58
|
+
This means we like names and flow that are more naturally read.
|
59
|
+
We try to avoid double negatives.
|
60
|
+
We try to avoid cryptic abbreviations (sticking to ones we feel are common).
|
66
61
|
|
67
|
-
|
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
|
62
|
+
### Descriptive
|
73
63
|
|
74
64
|
We like descriptive names for things, especially functions and variables.
|
75
|
-
Finding the right name for something is an important
|
76
|
-
from poking around our code that this often results in names that are a little
|
77
|
-
|
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 is to be avoided.
|
65
|
+
Finding the right name for something is an important endeavour.
|
66
|
+
You might notice from poking around our code that this often results in names that are a little longer than the average.
|
67
|
+
Guilty.
|
68
|
+
We're okay with a bit more typing if it means our code is easier to understand.
|
86
69
|
|
87
|
-
|
88
|
-
which is obvious. There's no need, therefore, to get carried away with complex
|
89
|
-
naming. We find i, j, and k are better loop counters than loopCounterVar or
|
90
|
-
whatnot. We only break this rule when we see that more description could improve
|
91
|
-
understanding of an algorithm.
|
70
|
+
There are two exceptions to this rule that we also stick to as religiously as possible:
|
92
71
|
|
72
|
+
First, while we realize hungarian notation (and similar systems for encoding type information into variable names) is providing a more descriptive name, we feel that (for the average developer) it takes away from readability and is to be avoided.
|
93
73
|
|
94
|
-
|
74
|
+
Second, loop counters and other local throw-away variables often have a purpose which is obvious.
|
75
|
+
There's no need, therefore, to get carried away with complex naming.
|
76
|
+
We find i, j, and k are better loop counters than loopCounterVar or whatnot.
|
77
|
+
We only break this rule when we see that more description could improve understanding of an algorithm.
|
95
78
|
|
96
|
-
|
97
|
-
configuration macros in a consistent fashion... you'll notice a repeated use of
|
98
|
-
UNITY_EXCLUDE_BLAH or UNITY_USES_BLAH macros. This helps users avoid having to
|
99
|
-
remember each macro's details.
|
79
|
+
### Consistent
|
100
80
|
|
81
|
+
We like consistency, but we're not really obsessed with it.
|
82
|
+
We try to name our configuration macros in a consistent fashion... you'll notice a repeated use of UNITY_EXCLUDE_BLAH or UNITY_USES_BLAH macros.
|
83
|
+
This helps users avoid having to remember each macro's details.
|
101
84
|
|
102
|
-
|
103
|
-
|
104
|
-
Where ever it doesn't violate the above principles, we try to apply memorable
|
105
|
-
names. Sometimes this means using something that is simply descriptive, but
|
106
|
-
often we strive for descriptive AND unique... we like quirky names that stand
|
107
|
-
out in our memory and are easier to search for. Take a look through the file
|
108
|
-
names in Ceedling and you'll get a good idea of what we are talking about here.
|
109
|
-
Why use preprocess when you can use preprocessinator? Or what better describes a
|
110
|
-
module in charge of invoking tasks during releases than release_invoker? Don't
|
111
|
-
get carried away. The names are still descriptive and fulfill the above
|
112
|
-
requirements, but they don't feel stale.
|
85
|
+
### Memorable
|
113
86
|
|
87
|
+
Where ever it doesn't violate the above principles, we try to apply memorable names.
|
88
|
+
Sometimes this means using something that is simply descriptive, but often we strive for descriptive AND unique... we like quirky names that stand out in our memory and are easier to search for.
|
89
|
+
Take a look through the file names in Ceedling and you'll get a good idea of what we are talking about here.
|
90
|
+
Why use preprocess when you can use preprocessinator?
|
91
|
+
Or what better describes a module in charge of invoking tasks during releases than release_invoker?
|
92
|
+
Don't get carried away.
|
93
|
+
The names are still descriptive and fulfil the above requirements, but they don't feel stale.
|
114
94
|
|
115
95
|
## C and C++ Details
|
116
96
|
|
117
|
-
We don't really want to add to the style battles out there.
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
We've decided on our own style preferences. If you'd like to contribute to these
|
123
|
-
projects (and we hope that you do), then we ask if you do your best to follow
|
124
|
-
the same. It will only hurt a little. We promise.
|
97
|
+
We don't really want to add to the style battles out there.
|
98
|
+
Tabs or spaces?
|
99
|
+
How many spaces?
|
100
|
+
Where do the braces go?
|
101
|
+
These are age-old questions that will never be answered... or at least not answered in a way that will make everyone happy.
|
125
102
|
|
103
|
+
We've decided on our own style preferences.
|
104
|
+
If you'd like to contribute to these projects (and we hope that you do), then we ask if you do your best to follow the same.
|
105
|
+
It will only hurt a little. We promise.
|
126
106
|
|
127
|
-
|
107
|
+
### Whitespace in C/C++
|
128
108
|
|
129
|
-
Our C-style is to use spaces and to use 4 of them per indent level.
|
130
|
-
power-of-2 number that looks decent on a wide-screen.
|
131
|
-
|
132
|
-
|
133
|
-
things up in nice tidy columns.
|
109
|
+
Our C-style is to use spaces and to use 4 of them per indent level.
|
110
|
+
It's a nice power-of-2 number that looks decent on a wide-screen.
|
111
|
+
We have no more reason than that.
|
112
|
+
We break that rule when we have lines that wrap (macros or function arguments or whatnot).
|
113
|
+
When that happens, we like to indent further to line things up in nice tidy columns.
|
134
114
|
|
135
115
|
```C
|
136
116
|
if (stuff_happened)
|
@@ -139,8 +119,7 @@ things up in nice tidy columns.
|
|
139
119
|
}
|
140
120
|
```
|
141
121
|
|
142
|
-
|
143
|
-
#### Case
|
122
|
+
### Case in C/C++
|
144
123
|
|
145
124
|
- Files - all lower case with underscores.
|
146
125
|
- Variables - all lower case with underscores
|
@@ -149,12 +128,12 @@ things up in nice tidy columns.
|
|
149
128
|
- Functions - camel cased. Usually named ModuleName_FuncName
|
150
129
|
- Constants and Globals - camel cased.
|
151
130
|
|
131
|
+
### Braces in C/C++
|
152
132
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
catching an error and you have a one-line, go ahead and to it on the same line.
|
133
|
+
The left brace is on the next line after the declaration.
|
134
|
+
The right brace is directly below that.
|
135
|
+
Everything in between in indented one level.
|
136
|
+
If you're catching an error and you have a one-line, go ahead and to it on the same line.
|
158
137
|
|
159
138
|
```C
|
160
139
|
while (blah)
|
@@ -163,32 +142,32 @@ catching an error and you have a one-line, go ahead and to it on the same line.
|
|
163
142
|
}
|
164
143
|
```
|
165
144
|
|
145
|
+
### Comments in C/C++
|
166
146
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
147
|
+
Do you know what we hate?
|
148
|
+
Old-school C block comments.
|
149
|
+
BUT, we're using them anyway.
|
150
|
+
As we mentioned, our goal is to support every compiler we can, especially embedded compilers.
|
151
|
+
There are STILL C compilers out there that only support old-school block comments.
|
152
|
+
So that is what we're using.
|
153
|
+
We apologize.
|
154
|
+
We think they are ugly too.
|
175
155
|
|
176
156
|
## Ruby Details
|
177
157
|
|
178
|
-
Is there really such thing as a Ruby coding standard?
|
179
|
-
language, it seems almost sacrilegious to suggest that people should comply to
|
180
|
-
|
181
|
-
|
158
|
+
Is there really such thing as a Ruby coding standard?
|
159
|
+
Ruby is such a free form language, it seems almost sacrilegious to suggest that people should comply to one method!
|
160
|
+
We'll keep it really brief!
|
182
161
|
|
183
|
-
|
162
|
+
### Whitespace in Ruby
|
184
163
|
|
185
|
-
Our Ruby style is to use spaces and to use 2 of them per indent level.
|
186
|
-
nice power-of-2 number that really grooves with Ruby's compact style.
|
187
|
-
|
188
|
-
|
164
|
+
Our Ruby style is to use spaces and to use 2 of them per indent level.
|
165
|
+
It's a nice power-of-2 number that really grooves with Ruby's compact style.
|
166
|
+
We have no more reason than that.
|
167
|
+
We break that rule when we have lines that wrap.
|
168
|
+
When that happens, we like to indent further to line things up in nice tidy columns.
|
189
169
|
|
190
|
-
|
191
|
-
#### Case
|
170
|
+
### Case in Ruby
|
192
171
|
|
193
172
|
- Files - all lower case with underscores.
|
194
173
|
- Variables - all lower case with underscores
|
@@ -196,11 +175,13 @@ that happens, we like to indent further to line things up in nice tidy columns.
|
|
196
175
|
- Functions - all lower case with underscores
|
197
176
|
- Constants - all upper case with underscores
|
198
177
|
|
199
|
-
|
200
178
|
## Documentation
|
201
179
|
|
202
|
-
Egad.
|
203
|
-
|
180
|
+
Egad.
|
181
|
+
Really?
|
182
|
+
We use markdown and we like PDF files because they can be made to look nice while still being portable.
|
183
|
+
Good enough?
|
204
184
|
|
185
|
+
*Find The Latest of This And More at [ThrowTheSwitch.org][]*
|
205
186
|
|
206
|
-
|
187
|
+
[ThrowTheSwitch.org]: https://throwtheswitch.org
|