Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "unity.h"

// Two modules sharing the basename `config`, each mocked by directory.
#include "drivers/uart/mock_config.h"
#include "drivers/spi/mock_config.h"

void setUp(void) {}
void tearDown(void) {}

// Each module's own public function is mocked separately, so an expectation set on one
// cannot be satisfied by the other.
void test_each_module_is_mocked_separately(void)
{
uart_config_baud_ExpectAndReturn(7);
spi_config_clock_div_ExpectAndReturn(9);

TEST_ASSERT_EQUAL_INT(7, uart_config_baud());
TEST_ASSERT_EQUAL_INT(9, spi_config_clock_div());
}
31 changes: 31 additions & 0 deletions spec/system/same_named_modules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
## intermediate file, and that is where two same-basename sources in one test can
## collide, so each setting gets its own example.
##
## Mocking both modules in one test is the second subject. Each mock must be
## named by the directory its #include names or the two mocks collide.
##
## Assets: assets/fixtures/same_named_modules/
##

Expand Down Expand Up @@ -83,5 +86,33 @@ def expect_green
end
end

# Mocking is the other half of naming two same-named modules in one test. Each
# needs its own mock, held apart by the directory its #include names.
context "with both same-named modules mocked in one test" do
before do
copy_same_named_modules('uart', 'spi')
in_project do
copy_fixture("same_named_modules/test/test_both_configs_mocked_traditional.c", 'test')
end
end

it "generates a mock per module and keeps their expectations separate" do
# CMock derives a mock's #include guard and its own _Init/_Verify/_Destroy names
# from the mock's filename alone, and Unity's runner calls them by that same name.
# Two same-named mocks therefore share a guard and lifecycle symbols. Closing this
# needs folder-qualified mock naming in both CMock and Unity.
pending 'CMock names a mock by filename alone, so two same-named mocks collide'

in_project do
output = @c.ceedling_build_exec("test:all")

expect(@c.last_exit_status).to eq(0)
expect(output).to match(/TESTED:\s+1/)
expect(output).to match(/PASSED:\s+1/)
expect(output).to match(/FAILED:\s+0/)
end
end
end

end
end
Loading