From 448f1db2d50234f445422a71e770781d793e21fd Mon Sep 17 00:00:00 2001 From: TheRealArthurDent Date: Sat, 30 Mar 2024 08:56:02 +0100 Subject: [PATCH 1/2] feat: Introduce testing with Unity --- .github/workflows/platformio-test-unity.yaml | 46 ++++++++++++++++++++ platformio.ini | 3 ++ test/dummy-test.cpp | 29 ++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 .github/workflows/platformio-test-unity.yaml create mode 100644 test/dummy-test.cpp diff --git a/.github/workflows/platformio-test-unity.yaml b/.github/workflows/platformio-test-unity.yaml new file mode 100644 index 0000000..97a2ca9 --- /dev/null +++ b/.github/workflows/platformio-test-unity.yaml @@ -0,0 +1,46 @@ +name: PlatformIO Test Unity + +on: + push: + branches: + - main + pull_request: + workflow_dispatch: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4.1.1 + + - name: Copy secrets template + run: | + cp secrets.ini.template secrets.ini + + - name: Set up Python + uses: actions/setup-python@v5.1.0 + with: + python-version-file: '.python-version' + + - name: Cache PlatformIO + uses: actions/cache@v4.0.2 + with: + path: | + ~/.cache/pip + ~/.platformio/.cache + key: ${{ runner.os }}-pio-${{ hashFiles('**/requirements.txt') }} + + - name: Install PlatformIO + shell: bash + run: | + #!/bin/bash + pip install --upgrade platformio + + - name: Check PlatformIO + shell: bash + run: | + #!/bin/bash + pio test -e unit_test diff --git a/platformio.ini b/platformio.ini index ad2bcb5..49b7247 100644 --- a/platformio.ini +++ b/platformio.ini @@ -40,3 +40,6 @@ build_type = debug build_flags = -D DEBUG ${common.build_flags} + +[env:unit_test] +platform = native diff --git a/test/dummy-test.cpp b/test/dummy-test.cpp new file mode 100644 index 0000000..a2d9475 --- /dev/null +++ b/test/dummy-test.cpp @@ -0,0 +1,29 @@ +#include + +void setUp(void) +{ + // set stuff up here +} + +void tearDown(void) +{ + // clean stuff up here +} + +void should_always_succeed() +{ + TEST_ASSERT_TRUE(true); +} + +void should_always_fail() +{ + TEST_ASSERT_TRUE(false); +} + +int main(int argc, char **argv) +{ + UNITY_BEGIN(); + RUN_TEST(should_always_succeed); + RUN_TEST(should_always_fail); + UNITY_END(); +} From feea6a38188807386ab410694ccc23312a48eb73 Mon Sep 17 00:00:00 2001 From: TheRealArthurDent Date: Sat, 30 Mar 2024 08:59:11 +0100 Subject: [PATCH 2/2] feat: Make tests pass --- .../{platformio-test-unity.yaml => platformio-test.yaml} | 4 ++-- test/dummy-test.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{platformio-test-unity.yaml => platformio-test.yaml} (93%) diff --git a/.github/workflows/platformio-test-unity.yaml b/.github/workflows/platformio-test.yaml similarity index 93% rename from .github/workflows/platformio-test-unity.yaml rename to .github/workflows/platformio-test.yaml index 97a2ca9..3887193 100644 --- a/.github/workflows/platformio-test-unity.yaml +++ b/.github/workflows/platformio-test.yaml @@ -1,4 +1,4 @@ -name: PlatformIO Test Unity +name: PlatformIO Test on: push: @@ -39,7 +39,7 @@ jobs: #!/bin/bash pip install --upgrade platformio - - name: Check PlatformIO + - name: PlatformIO Test shell: bash run: | #!/bin/bash diff --git a/test/dummy-test.cpp b/test/dummy-test.cpp index a2d9475..8202180 100644 --- a/test/dummy-test.cpp +++ b/test/dummy-test.cpp @@ -24,6 +24,6 @@ int main(int argc, char **argv) { UNITY_BEGIN(); RUN_TEST(should_always_succeed); - RUN_TEST(should_always_fail); + // RUN_TEST(should_always_fail); UNITY_END(); }