Skip to content

Commit 8500dd2

Browse files
authored
Merge pull request #848 from ThrowTheSwitch/feature/choose-printable-chars
Feature/choose printable chars
2 parents 3a6eb6d + a05a9fb commit 8500dd2

4 files changed

Lines changed: 52 additions & 35 deletions

File tree

auto/generate_test_runner.rb

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -407,43 +407,43 @@ def create_reset(output)
407407
end
408408

409409
def create_run_test(output)
410-
output.puts("/*=======Test Runner Used To Run Each Test=====*/")
411-
output.puts("static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)")
412-
output.puts("{")
413-
output.puts(" Unity.CurrentTestName = name;")
414-
output.puts(" Unity.CurrentTestLineNumber = (UNITY_UINT) line_num;")
415-
output.puts("#ifdef UNITY_USE_COMMAND_LINE_ARGS")
416-
output.puts(" if (!UnityTestMatches())")
417-
output.puts(" return;")
418-
output.puts("#endif")
419-
output.puts(" Unity.NumberOfTests++;")
420-
output.puts(" UNITY_CLR_DETAILS();")
421-
output.puts(" UNITY_EXEC_TIME_START();")
422-
output.puts(" CMock_Init();")
423-
output.puts(" if (TEST_PROTECT())")
424-
output.puts(" {")
410+
output.puts('/*=======Test Runner Used To Run Each Test=====*/')
411+
output.puts('static void run_test(UnityTestFunction func, const char* name, UNITY_LINE_TYPE line_num)')
412+
output.puts('{')
413+
output.puts(' Unity.CurrentTestName = name;')
414+
output.puts(' Unity.CurrentTestLineNumber = (UNITY_UINT) line_num;')
415+
output.puts('#ifdef UNITY_USE_COMMAND_LINE_ARGS')
416+
output.puts(' if (!UnityTestMatches())')
417+
output.puts(' return;')
418+
output.puts('#endif')
419+
output.puts(' Unity.NumberOfTests++;')
420+
output.puts(' UNITY_CLR_DETAILS();')
421+
output.puts(' UNITY_EXEC_TIME_START();')
422+
output.puts(' CMock_Init();')
423+
output.puts(' if (TEST_PROTECT())')
424+
output.puts(' {')
425425
if @options[:plugins].include?(:cexception)
426-
output.puts(" volatile CEXCEPTION_T e;")
427-
output.puts(" Try {")
426+
output.puts(' volatile CEXCEPTION_T e;')
427+
output.puts(' Try {')
428428
output.puts(" #{@options[:setup_name]}();")
429-
output.puts(" func();")
430-
output.puts(" } Catch(e) {")
431-
output.puts(" TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\");")
432-
output.puts(" }")
429+
output.puts(' func();')
430+
output.puts(' } Catch(e) {')
431+
output.puts(' TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!");')
432+
output.puts(' }')
433433
else
434434
output.puts(" #{@options[:setup_name]}();")
435-
output.puts(" func();")
435+
output.puts(' func();')
436436
end
437-
output.puts(" }")
438-
output.puts(" if (TEST_PROTECT())")
439-
output.puts(" {")
437+
output.puts(' }')
438+
output.puts(' if (TEST_PROTECT())')
439+
output.puts(' {')
440440
output.puts(" #{@options[:teardown_name]}();")
441-
output.puts(" CMock_Verify();")
442-
output.puts(" }")
443-
output.puts(" CMock_Destroy();")
444-
output.puts(" UNITY_EXEC_TIME_STOP();")
445-
output.puts(" UnityConcludeTest();")
446-
output.puts("}")
441+
output.puts(' CMock_Verify();')
442+
output.puts(' }')
443+
output.puts(' CMock_Destroy();')
444+
output.puts(' UNITY_EXEC_TIME_STOP();')
445+
output.puts(' UnityConcludeTest();')
446+
output.puts('}')
447447
end
448448

449449
def create_args_wrappers(output, tests)
@@ -465,7 +465,7 @@ def create_args_wrappers(output, tests)
465465
def create_warning_test(output, filename, tests)
466466
if count_tests(tests) == 0
467467
warning_test = {
468-
:test => "test_empty_warning",
468+
:test => 'test_empty_warning',
469469
:line_number => 0
470470
}
471471
output.puts("\n/*=======Warning Test=====*/")
@@ -475,7 +475,7 @@ def create_warning_test(output, filename, tests)
475475
output.puts("}\n")
476476
tests = [warning_test]
477477
end
478-
return tests
478+
tests
479479
end
480480

481481
def create_shuffle_tests(output)

examples/unity_config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,12 @@
250250
*/
251251
/* #define UNITY_INCLUDE_EXEC_TIME */
252252

253+
/* Define this macro to redefine what the UnityPrintChar() function considers
254+
* a printable character.
255+
*
256+
* Example, for printing UTF-8:
257+
* #define UNITY_IS_PRINTABLE_CHAR(c) ((128 <= (c)) && ((c) <= 255))
258+
*/
259+
/* #define UNITY_IS_PRINTABLE_CHAR(c) ((32 <= (c)) && ((c) <= 126)) */
260+
253261
#endif /* UNITY_CONFIG_H */

src/unity.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "unity.h"
99

10+
#include <stdbool.h>
11+
1012
#ifndef UNITY_PROGMEM
1113
#define UNITY_PROGMEM
1214
#endif
@@ -88,8 +90,14 @@ static const char UNITY_PROGMEM UnityStrDetail2Name[] = " " UNITY_DET
8890
/* Local helper function to print characters. */
8991
static void UnityPrintChar(const char* pch)
9092
{
93+
#ifdef UNITY_IS_PRINTABLE_CHAR
94+
const int isPrintable = UNITY_IS_PRINTABLE_CHAR(*pch);
95+
#else
96+
const int isPrintable = ((32 <= *pch) && (*pch <= 126));
97+
#endif
98+
9199
/* printable characters plus CR & LF are printed */
92-
if ((*pch <= 126) && (*pch >= 32))
100+
if (isPrintable)
93101
{
94102
UNITY_OUTPUT_CHAR(*pch);
95103
}

test/rakefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ TEMP_DIRS = [
1919

2020
TEMP_DIRS.each do |dir|
2121
directory(dir)
22+
CLEAN.include(File.join(dir, '*.*'))
2223
CLOBBER.include(dir)
2324
end
2425

@@ -167,7 +168,7 @@ namespace :style do
167168

168169
desc "Attempt to Autocorrect style"
169170
task :auto => ['style:clean'] do
170-
execute("rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml")
171+
execute("rubocop ../auto ../examples ../extras --autocorrect --config .rubocop.yml")
171172
report "Autocorrected What We Could."
172173
end
173174

0 commit comments

Comments
 (0)