Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace usage of UnityBegin/UnityEnd with UNITY_BEGIN/UNITY_END #947

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/check-unitybegin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

usage="check-unitybegin - checks UnityBegin() line for all exercises in a given directory
usage="check-unitybegin - checks UNITY_BEGIN() line for all exercises in a given directory
Usage:
check-unitybegin <path-to-exercises>

Expand All @@ -20,8 +20,8 @@ check_exercises () {
for f in "${1}"/*/test_*; do
if [ -f "${f}" ]
then
if ! grep -q UnityBegin\(\""$(basename "$f")"\"\) "$f"; then
echo "$f needs correct UnityBegin line"
if ! grep -q UNITY_BEGIN\(\) "$f"; then
echo "$f needs correct UNITY_BEGIN line"
(( ERROR_COUNT++ ))
fi
else
Expand Down
4 changes: 1 addition & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ If you would like the [`/format`][format-workflow] automated action to work corr
* `checks.yml` runs `shellcheck` on the tool scripts and subsequently runs the following of those tools:
* `./bin/check-unitybegin`
* `./bin/verify-unity-version`
* `./bin/check-unitybegin`
* `./bin/check-include-guards`
* [Lychee link checker][lychee] action
* `configlet.yml` fetches the latest version of configlet from which it then runs the `lint` command on the track
Expand All @@ -150,10 +149,9 @@ If you would like the [`/format`][format-workflow] automated action to work corr
You can see from the [workflows][] that GitHub is instructed to run tools from the [`./bin`][bin] directory.
The work the tools in this directory perform is described as follows:

* `check-unitybegin` ensures that every test file correctly adds the `UnityBegin("{test-file-name}")` line at the start of its `main()` function.
* `check-unitybegin` ensures that every test file correctly adds the `UNITY_BEGIN()` line at the start of its `main()` function.
* `fetch-configlet` fetches the `configlet` tool from its [repository][configlet].
* `verify-unity-version` checks the version of the Unity test framework used by every exercise. The version this file should check for is specified in [`./docs/VERSIONS.md`][versions]
* `check-unitybegin` ensures that every test file correctly adds the `UnityBegin("{test-file-name}")` line at the start of its `main()` function.
* `check-include-guards` checks that the include guards used in each exercises stub and example header are using the correct format, as follows:

```c
Expand Down
9 changes: 4 additions & 5 deletions docs/C_STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,18 @@ static void test_the_third(void)

Last in the file is the `main()` function.
The function body of main follows a particular layout itself.
First a call to `UnityBegin()` followed by an empty line, then the tests.
The last test is followed by another empty line and then a call to `UnityEnd()`, before returning.
First a call to `UNITY_BEGIN()` followed by an empty line, then the tests.
The last test is followed by another empty line before returning the result of `UNITY_END()`.

```c
int main(void)
{
UnityBegin("test/test_file_name.c");
UNITY_BEGIN();

RUN_TEST(test_foo);
RUN_TEST(test_bar);

UnityEnd();
return 0;
return UNITY_END();
}
```

Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/acronym/test_acronym.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static void test_underscore_emphasis(void)

int main(void)
{
UnityBegin("test_acronym.c");
UNITY_BEGIN();

RUN_TEST(test_null_string);
RUN_TEST(test_empty_string);
Expand All @@ -126,5 +126,5 @@ int main(void)
RUN_TEST(test_apostrophes);
RUN_TEST(test_underscore_emphasis);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/all-your-base/test_all_your_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static void test_both_bases_are_negative(void)

int main(void)
{
UnityBegin("test_all_your_base.c");
UNITY_BEGIN();

RUN_TEST(test_single_bit_to_decimal);
RUN_TEST(test_binary_to_single_decimal);
Expand All @@ -231,5 +231,5 @@ int main(void)
RUN_TEST(test_output_base_is_negative);
RUN_TEST(test_both_bases_are_negative);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/allergies/test_allergies.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ static void test_no_allergen_score_parts_without_highest_valid_score(void)

int main(void)
{
UnityBegin("test_allergies.c");
UNITY_BEGIN();

RUN_TEST(test_not_allergic_to_anything_for_eggs);
RUN_TEST(test_allergic_only_to_eggs);
Expand Down Expand Up @@ -459,5 +459,5 @@ int main(void)
RUN_TEST(test_no_allergen_score_parts);
RUN_TEST(test_no_allergen_score_parts_without_highest_valid_score);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/anagram/test_anagram.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ static void test_words_other_than_themselves_can_be_anagrams(void)

int main(void)
{
UnityBegin("test_anagram.c");
UNITY_BEGIN();

RUN_TEST(test_no_matches);
RUN_TEST(test_detect_two_anagrams);
Expand All @@ -294,5 +294,5 @@ int main(void)
test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different);
RUN_TEST(test_words_other_than_themselves_can_be_anagrams);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/armstrong-numbers/test_armstrong_numbers.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void test_seven_digit_number_that_is_not_an_armstrong_number(void)

int main(void)
{
UnityBegin("test_armstrong_numbers.c");
UNITY_BEGIN();

RUN_TEST(test_zero_is_an_armstrong_number);
RUN_TEST(test_single_digit_numbers_are_armstrong_numbers);
Expand All @@ -76,5 +76,5 @@ int main(void)
RUN_TEST(test_seven_digit_number_that_is_an_armstrong_number);
RUN_TEST(test_seven_digit_number_that_is_not_an_armstrong_number);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/atbash-cipher/test_atbash_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void test_decode_with_no_spaces(void)

int main(void)
{
UnityBegin("test_atbash_cipher.c");
UNITY_BEGIN();

RUN_TEST(test_encode_yes);
RUN_TEST(test_encode_no);
Expand All @@ -136,5 +136,5 @@ int main(void)
RUN_TEST(test_decode_with_too_many_spaces);
RUN_TEST(test_decode_with_no_spaces);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/beer-song/test_beer_song.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static void test_all_verses(void)

int main(void)
{
UnityBegin("test_beer_song.c");
UNITY_BEGIN();

RUN_TEST(test_first_generic_verse);
RUN_TEST(test_last_generic_verse);
Expand All @@ -475,5 +475,5 @@ int main(void)
RUN_TEST(test_last_three_verses);
RUN_TEST(test_all_verses);

return UnityEnd();
return UNITY_END();
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static void test_sorted_data_can_sort_complex_tree(void)

int main(void)
{
UnityBegin("test_binary_search_tree.c");
UNITY_BEGIN();

RUN_TEST(test_data_data_is_retained);
RUN_TEST(test_data_smaller_number_at_left_node);
Expand All @@ -205,5 +205,5 @@ int main(void)
RUN_TEST(test_sorted_data_can_sort_if_second_number_is_greater_than_first);
RUN_TEST(test_sorted_data_can_sort_complex_tree);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/binary-search/test_binary_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void test_nothing_is_found_when_the_left_and_right_bounds_cross(void)

int main(void)
{
UnityBegin("test_binary_search.c");
UNITY_BEGIN();

RUN_TEST(test_finds_a_value_in_an_array_with_one_element);
RUN_TEST(test_a_value_in_the_middle_of_an_array);
Expand All @@ -113,5 +113,5 @@ int main(void)
RUN_TEST(test_nothing_is_found_in_an_empty_array);
RUN_TEST(test_nothing_is_found_when_the_left_and_right_bounds_cross);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/binary/test_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void test_a_number_and_a_word_whitespace_separated_is_invalid(void)

int main(void)
{
UnityBegin("test_binary.c");
UNITY_BEGIN();

RUN_TEST(test_binary_0_is_decimal_0);
RUN_TEST(test_binary_1_is_decimal_1);
Expand All @@ -118,5 +118,5 @@ int main(void)
RUN_TEST(test_a_number_with_internal_non_binary_characters_is_invalid);
RUN_TEST(test_a_number_and_a_word_whitespace_separated_is_invalid);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/bob/test_bob.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void test_non_question_ending_with_whitespace(void)

int main(void)
{
UnityBegin("test_bob.c");
UNITY_BEGIN();

RUN_TEST(test_stating_something);
RUN_TEST(test_shouting);
Expand Down Expand Up @@ -201,5 +201,5 @@ int main(void)
RUN_TEST(test_other_whitespace);
RUN_TEST(test_non_question_ending_with_whitespace);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/circular-buffer/test_circular_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static void test_initial_clear_does_not_affect_wrapping(void)

int main(void)
{
UnityBegin("test_circular_buffer.c");
UNITY_BEGIN();

RUN_TEST(test_reading_empty_buffer_fails);
RUN_TEST(test_can_read_item_just_written);
Expand All @@ -278,5 +278,5 @@ int main(void)
RUN_TEST(test_overwrite_replaces_oldest_item_remaining_following_read);
RUN_TEST(test_initial_clear_does_not_affect_wrapping);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/clock/test_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ static void test_compare_full_clock_and_zeroed_clock(void)

int main(void)
{
UnityBegin("test_clock.c");
UNITY_BEGIN();

RUN_TEST(test_on_the_hour);
RUN_TEST(test_past_the_hour);
Expand Down Expand Up @@ -592,5 +592,5 @@ int main(void)
RUN_TEST(test_compare_clocks_with_negative_hours_and_minute_that_wrap);
RUN_TEST(test_compare_full_clock_and_zeroed_clock);

return UnityEnd();
return UNITY_END();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void test_negative_value_is_an_error(void)

int main(void)
{
UnityBegin("test_collatz_conjecture.c");
UNITY_BEGIN();

RUN_TEST(test_zero_steps_for_one);
RUN_TEST(test_divide_if_even);
Expand All @@ -50,5 +50,5 @@ int main(void)
RUN_TEST(test_zero_is_an_error);
RUN_TEST(test_negative_value_is_an_error);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/complex-numbers/test_complex_numbers.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static void test_divide_real_number_by_complex_number(void)

int main(void)
{
UnityBegin("test_complex_numbers.c");
UNITY_BEGIN();

RUN_TEST(test_real_part_of_a_purely_real_number);
RUN_TEST(test_real_part_of_a_purely_imaginary_number);
Expand Down Expand Up @@ -544,5 +544,5 @@ int main(void)
RUN_TEST(test_divide_complex_number_by_real_number);
RUN_TEST(test_divide_real_number_by_complex_number);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/crypto-square/test_crypto_square.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test_54_char_plaintext_gives_7_chunks_last_two_with_trailing_spaces(void)

int main(void)
{
UnityBegin("test_crypto_square.c");
UNITY_BEGIN();

RUN_TEST(test_empty_text_res_in_an_empty_ciphertext);
RUN_TEST(test_lowercase);
Expand All @@ -96,5 +96,5 @@ int main(void)
RUN_TEST(
test_54_char_plaintext_gives_7_chunks_last_two_with_trailing_spaces);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/darts/test_darts.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void test_asymmetric_position_between_the_inner_and_middle_circles(void)

int main(void)
{
UnityBegin("test_darts.c");
UNITY_BEGIN();

RUN_TEST(test_missed_target);
RUN_TEST(test_on_the_outer_circle);
Expand All @@ -143,5 +143,5 @@ int main(void)
RUN_TEST(test_just_outside_the_outer_circle);
RUN_TEST(test_asymmetric_position_between_the_inner_and_middle_circles);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/diamond/test_diamond.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void test_rows_largest_possible_diamond(void)

int main(void)
{
UnityBegin("test_diamond.c");
UNITY_BEGIN();

RUN_TEST(test_rows_degenerate_case_with_a_single_a_row);
RUN_TEST(
Expand All @@ -155,5 +155,5 @@ int main(void)
test_rows_smallest_non_degenerate_case_with_even_diamond_side_length);
RUN_TEST(test_rows_largest_possible_diamond);

return UnityEnd();
return UNITY_END();
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static void test_difference_of_squares_100(void)

int main(void)
{
UnityBegin("test_difference_of_squares.c");
UNITY_BEGIN();

RUN_TEST(test_square_of_sum_1);
RUN_TEST(test_square_of_sum_5);
Expand All @@ -76,5 +76,5 @@ int main(void)
RUN_TEST(test_difference_of_squares_5);
RUN_TEST(test_difference_of_squares_100);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/etl/test_etl.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ static void test_multiple_scores_with_differing_numbers_of_letters(void)

int main(void)
{
UnityBegin("test_etl.c");
UNITY_BEGIN();

RUN_TEST(test_a_single_letter);
RUN_TEST(test_single_score_with_multiple_letters);
RUN_TEST(test_multiple_scores_with_multiple_letters);
RUN_TEST(test_multiple_scores_with_differing_numbers_of_letters);

return UnityEnd();
return UNITY_END();
}
4 changes: 2 additions & 2 deletions exercises/practice/gigasecond/test_gigasecond.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void test_your_birthday(void)

int main(void)
{
UnityBegin("test_gigasecond.c");
UNITY_BEGIN();

RUN_TEST(test_date);
RUN_TEST(test_another_date);
Expand All @@ -114,5 +114,5 @@ int main(void)
RUN_TEST(test_date_and_time_with_day_rollover);
// RUN_TEST(test_your_birthday);

return UnityEnd();
return UNITY_END();
}
Loading