Skip to content

Commit

Permalink
Update examples to more explicit assertions.
Browse files Browse the repository at this point in the history
Further fixing wording in gcov tests.
  • Loading branch information
mvandervoord committed Dec 12, 2023
1 parent 0b644f6 commit 20c551e
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 68 deletions.
4 changes: 2 additions & 2 deletions assets/test_example_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ void setUp(void) {}
void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
TEST_ASSERT_EQUAL(2, add_numbers(1,1));
TEST_ASSERT_EQUAL_INT(2, add_numbers(1,1));
}

void test_add_numbers_will_fail(void) {
TEST_ASSERT_EQUAL(2, add_numbers(2,2));
TEST_ASSERT_EQUAL_INT(2, add_numbers(2,2));
}
4 changes: 2 additions & 2 deletions assets/test_example_file_boom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ void setUp(void) {}
void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
TEST_ASSERT_EQUAL(2, add_numbers(1,1) //Removed semicolon & parenthesis to make a compile error.
TEST_ASSERT_EQUAL_INT(2, add_numbers(1,1) //Removed semicolon & parenthesis to make a compile error.
}

void test_add_numbers_will_fail(void) {
TEST_ASSERT_EQUAL(2, add_numbers(2,2));
TEST_ASSERT_EQUAL_INT(2, add_numbers(2,2));
}
4 changes: 2 additions & 2 deletions assets/test_example_file_sigsegv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ void setUp(void) {}
void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
TEST_ASSERT_EQUAL(2, add_numbers(1,1));
TEST_ASSERT_EQUAL_INT(2, add_numbers(1,1));
}

void test_add_numbers_will_fail(void) {
raise(SIGSEGV);
TEST_ASSERT_EQUAL(2, add_numbers(2,2));
TEST_ASSERT_EQUAL_INT(2, add_numbers(2,2));
}
4 changes: 2 additions & 2 deletions assets/test_example_file_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ void setUp(void) {}
void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
TEST_ASSERT_EQUAL(2, add_numbers(1,1));
TEST_ASSERT_EQUAL_INT(2, add_numbers(1,1));
}

void test_add_numbers_will_fail_but_is_ignored_for_now(void) {
TEST_IGNORE();
TEST_ASSERT_EQUAL(2, add_numbers(2,2));
TEST_ASSERT_EQUAL_INT(2, add_numbers(2,2));
}
2 changes: 1 addition & 1 deletion assets/test_example_file_unity_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
TEST_PRINTF("1 + 1 =%d", 1 + 1);
TEST_ASSERT_EQUAL(2, add_numbers(1,1));
TEST_ASSERT_EQUAL_INT(2, add_numbers(1,1));
}

2 changes: 1 addition & 1 deletion assets/test_example_file_verbose.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
printf("1 + 1 = 2\n");
TEST_ASSERT_EQUAL(2, add_numbers(1,1));
TEST_ASSERT_EQUAL_INT(2, add_numbers(1,1));
}

2 changes: 1 addition & 1 deletion assets/test_example_file_with_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ void tearDown(void) {}

void test_add_numbers_adds_numbers(void) {
add_numbers_ExpectAndReturn(1, 1, 2);
TEST_ASSERT_EQUAL(2, call_add_numbers(1, 1));
TEST_ASSERT_EQUAL_INT(2, call_add_numbers(1, 1));
}
4 changes: 2 additions & 2 deletions examples/blinky/test/test_BlinkTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void test_BlinkTask_should_toggle_led(void)
BlinkTask();

/* Verify test results */
TEST_ASSERT_EQUAL(0x20, PORTB);
TEST_ASSERT_EQUAL_HEX8(0x20, PORTB);
}
void test_BlinkTask_should_toggle_led_LOW(void)
{
Expand All @@ -38,5 +38,5 @@ void test_BlinkTask_should_toggle_led_LOW(void)
BlinkTask();

/* Verify test results */
TEST_ASSERT_EQUAL(0, PORTB);
TEST_ASSERT_EQUAL_HEX8(0, PORTB);
}
6 changes: 3 additions & 3 deletions examples/blinky/test/test_Configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void test_Configure_should_setup_timer_and_port(void)
Configure();

/* Verify test results */
TEST_ASSERT_EQUAL(3, TCCR0B);
TEST_ASSERT_EQUAL(1, TIMSK0);
TEST_ASSERT_EQUAL(0x20, DDRB);
TEST_ASSERT_EQUAL_INT(3, TCCR0B);
TEST_ASSERT_EQUAL_INT(1, TIMSK0);
TEST_ASSERT_EQUAL_INT(0x20, DDRB);
}
10 changes: 5 additions & 5 deletions examples/blinky/test/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void test_AppMain_should_call_configure(void)
AppMain();

/* Verify test results */
TEST_ASSERT_EQUAL(0, BlinkTaskReady);
TEST_ASSERT_EQUAL_INT(0, BlinkTaskReady);
}
void test_AppMain_should_call_configure_and_BlinkTask(void)
{
Expand All @@ -31,7 +31,7 @@ void test_AppMain_should_call_configure_and_BlinkTask(void)
AppMain();

/* Verify test results */
TEST_ASSERT_EQUAL(0, BlinkTaskReady);
TEST_ASSERT_EQUAL_INT(0, BlinkTaskReady);
}
void test_ISR_should_increment_tick(void)
{
Expand All @@ -43,7 +43,7 @@ void test_ISR_should_increment_tick(void)
ISR();

/* Verify test results */
TEST_ASSERT_EQUAL(1, tick);
TEST_ASSERT_EQUAL_INT(1, tick);
}
void test_ISR_should_set_blinkReady_increment_tick(void)
{
Expand All @@ -55,6 +55,6 @@ void test_ISR_should_set_blinkReady_increment_tick(void)
ISR();

/* Verify test results */
TEST_ASSERT_EQUAL(1, tick);
TEST_ASSERT_EQUAL(1, BlinkTaskReady);
TEST_ASSERT_EQUAL_INT(1, tick);
TEST_ASSERT_EQUAL_INT(1, BlinkTaskReady);
}
2 changes: 1 addition & 1 deletion examples/temp_sensor/test/TestAdcHardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ void testGetSampleShouldDelegateToAdcTemperatureSensor(void)
Adc_ReadTemperatureSensor_ExpectAndReturn(847);

sample = AdcHardware_GetSample();
TEST_ASSERT_EQUAL(847, sample);
TEST_ASSERT_EQUAL_INT(847, sample);
}
4 changes: 2 additions & 2 deletions examples/temp_sensor/test/TestAdcModel.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ void tearDown(void)
void testDoGetSampleShouldReturn_FALSE_WhenTaskSchedulerReturns_FALSE(void)
{
TaskScheduler_DoAdc_ExpectAndReturn(FALSE);
TEST_ASSERT_EQUAL(FALSE, AdcModel_DoGetSample());
TEST_ASSERT_FALSE(AdcModel_DoGetSample());
}

void testDoGetSampleShouldReturn_TRUE_WhenTaskSchedulerReturns_TRUE(void)
{
TaskScheduler_DoAdc_ExpectAndReturn(TRUE);
TEST_ASSERT_EQUAL(TRUE, AdcModel_DoGetSample());
TEST_ASSERT_TRUE(AdcModel_DoGetSample());
}

void testProcessInputShouldDelegateToTemperatureCalculatorAndPassResultToFilter(void)
Expand Down
2 changes: 1 addition & 1 deletion examples/temp_sensor/test/TestExecutor.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ void testRunShouldCallRunForEachConductorAndReturnTrueAlways(void)
TimerConductor_Run_Expect();
AdcConductor_Run_Expect();

TEST_ASSERT_EQUAL(TRUE, Executor_Run());
TEST_ASSERT_TRUE(Executor_Run());
}
60 changes: 30 additions & 30 deletions examples/temp_sensor/test/TestTaskScheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,92 +13,92 @@ void tearDown(void)

void testShouldScheduleUsartTaskAfter1000ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());

TaskScheduler_Update(999);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());

TaskScheduler_Update(1000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());
}

void testShouldClearUsartDoFlagAfterReported(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());
TaskScheduler_Update(1000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());
}

void testShouldScheduleUsartTaskEvery1000ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());

TaskScheduler_Update(1300);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());

TaskScheduler_Update(2000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());

TaskScheduler_Update(3100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());
}

void testShouldScheduleUsartTaskOnlyOncePerPeriod(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());
TaskScheduler_Update(1000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());
TaskScheduler_Update(1001);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());
TaskScheduler_Update(1999);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
TEST_ASSERT_FALSE(TaskScheduler_DoUsart());
TaskScheduler_Update(2000);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
TEST_ASSERT_TRUE(TaskScheduler_DoUsart());
}

void testShouldScheduleAdcTaskAfter100ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());

TaskScheduler_Update(99);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());

TaskScheduler_Update(100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());
}

void testShouldClearAdcDoFlagAfterReported(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());
TaskScheduler_Update(100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());
}

void testShouldScheduleAdcTaskEvery100ms(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());

TaskScheduler_Update(121);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());

TaskScheduler_Update(200);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());

TaskScheduler_Update(356);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());
}

void testShouldScheduleAdcTaskOnlyOncePerPeriod(void)
{
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());
TaskScheduler_Update(100);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());
TaskScheduler_Update(101);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());
TaskScheduler_Update(199);
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
TEST_ASSERT_FALSE(TaskScheduler_DoAdc());
TaskScheduler_Update(200);
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
TEST_ASSERT_TRUE(TaskScheduler_DoAdc());
}
10 changes: 5 additions & 5 deletions examples/temp_sensor/test/TestUsartBaudRateRegisterCalculator.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ void tearDown(void)
void testCalculateBaudRateRegisterSettingShouldCalculateRegisterSettingAppropriately(void)
{
// BaudRate = MCK / (CD x 16) - per datasheet section 30.6.1.2 "Baud Rate Calculation Example"
TEST_ASSERT_EQUAL(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
TEST_ASSERT_EQUAL(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
TEST_ASSERT_EQUAL(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
TEST_ASSERT_EQUAL(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
TEST_ASSERT_EQUAL(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
TEST_ASSERT_EQUAL_INT(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
TEST_ASSERT_EQUAL_INT(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
TEST_ASSERT_EQUAL_INT(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
TEST_ASSERT_EQUAL_INT(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
TEST_ASSERT_EQUAL_INT(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
}
2 changes: 1 addition & 1 deletion examples/temp_sensor/test/TestUsartModel.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void testGetBaudRateRegisterSettingShouldReturnAppropriateBaudRateRegisterSettin
uint8 dummyRegisterSetting = 17;
UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, dummyRegisterSetting);

TEST_ASSERT_EQUAL(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
TEST_ASSERT_EQUAL_UINT8(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
}

void testGetFormattedTemperatureFormatsTemperatureFromCalculatorAppropriately(void)
Expand Down
11 changes: 7 additions & 4 deletions spec/gcov/gcov_test_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def can_create_gcov_html_report_from_crashing_test_runner_with_enabled_debug_and
expect(output).to match(/IGNORED:\s+0/)
expect(output).to match(/example_file.c \| Lines executed:50.00% of 4/)

expect(output).to match(/Creating HTML coverage report\(s\) with gcovr in 'build\/artifacts\/gcov'\.\.\. Done/)
expect(output).to match(/Creating HTML coverage report\(s\) with gcovr in 'build\/artifacts\/gcov'\.\.\./)
expect(output).to.match(/Done/)
expect(File.exist?('build/artifacts/gcov/GcovCoverageResults.html')).to eq true
end
end
Expand Down Expand Up @@ -246,7 +247,8 @@ def can_create_gcov_html_report_from_crashing_test_runner_with_enabled_debug_and
expect(output).to match(/IGNORED:\s+0/)
expect(output).to match(/example_file.c \| Lines executed:0.00% of 4/)

expect(output).to match(/Creating HTML coverage report\(s\) with gcovr in 'build\/artifacts\/gcov'\.\.\. Done/)
expect(output).to match(/Creating HTML coverage report\(s\) with gcovr in 'build\/artifacts\/gcov'\.\.\./)
expect(output).to.match(/Done/)
expect(File.exist?('build/artifacts/gcov/GcovCoverageResults.html')).to eq true
end
end
Expand All @@ -264,7 +266,7 @@ def can_create_gcov_html_report_from_test_runner_with_enabled_debug_and_cmd_args

add_test_case = "\nvoid test_difference_between_two_numbers(void)\n"\
"{\n" \
" TEST_ASSERT_EQUAL(0, difference_between_numbers(1,1));\n" \
" TEST_ASSERT_EQUAL_INT(0, difference_between_numbers(1,1));\n" \
"}\n"

updated_test_file = File.read('test/test_example_file_sigsegv.c').split("\n")
Expand All @@ -280,7 +282,8 @@ def can_create_gcov_html_report_from_test_runner_with_enabled_debug_and_cmd_args
expect(output).to match(/IGNORED:\s+0/)
expect(output).to match(/example_file.c \| Lines executed:100.00% of 4/)

expect(output).to match(/Creating HTML coverage report\(s\) with gcovr in 'build\/artifacts\/gcov'\.\.\. Done/)
expect(output).to match(/Creating HTML coverage report\(s\) with gcovr in 'build\/artifacts\/gcov'\.\.\./)
expect(output).to.match(/Done/)
expect(File.exist?('build/artifacts/gcov/GcovCoverageResults.html')).to eq true
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_system_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def can_test_projects_with_test_name_replaced_defines_with_success
add_project_settings("project.yml", settings)

output = `bundle exec ruby -S ceedling 2>&1`
expect($?.exitstatus).to match(0) # Since a test either pass or are ignored, we return success here
expect($?.exitstatus).to match(0) # Since a test either passes or is ignored, we return success here
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
Expand Down Expand Up @@ -496,7 +496,7 @@ def can_test_projects_with_both_mock_and_real_header
FileUtils.cp test_asset_path("test_example_file_with_mock.c"), 'test/'

output = `bundle exec ruby -S ceedling 2>&1`
expect($?.exitstatus).to match(0) # Since a test either pass or are ignored, we return success here
expect($?.exitstatus).to match(0) # Since a test either passed or was ignored, we return success here
expect(output).to match(/TESTED:\s+\d/)
expect(output).to match(/PASSED:\s+\d/)
expect(output).to match(/FAILED:\s+\d/)
Expand Down Expand Up @@ -549,7 +549,7 @@ def can_fetch_project_help
expect(output).to match(/ceedling summary/i)
expect(output).to match(/ceedling test:\*/i)
expect(output).to match(/ceedling test:all/i)
expect(output).to match(/ceedling test:delta/i)
#expect(output).to match(/ceedling test:delta/i) #feature temporarily removed
expect(output).to match(/ceedling version/i)
end
end
Expand Down

0 comments on commit 20c551e

Please sign in to comment.