Skip to content

Commit

Permalink
Clean up the project structure (#23)
Browse files Browse the repository at this point in the history
* Move source files to `src` directory

* Create a lib directory, move a header into it

* Set up a test directory, with a sample test

* Add test action

* Fix check command; update badge list in README
  • Loading branch information
floatplane authored Jan 26, 2024
1 parent 9819622 commit 6ac1227
Show file tree
Hide file tree
Showing 25 changed files with 77 additions and 7 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Run tests
run: |
pio test -e native
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ Use MQTT and ESP8266/ESP32 module to control Mitsubishi HVAC unit.
It use SwiCago libraries: https://github.com/SwiCago/HeatPump

[![.github/workflows/build.yml](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/build.yml/badge.svg)](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/build.yml)
[![.github/workflows/clangformat.yml](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/clangformat.yml/badge.svg)](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/clangformat.yml)
[![.github/workflows/test.yml](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/test.yml/badge.svg)](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/test.yml)
[![.github/workflows/static_analysis.yml](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/static_analysis.yml/badge.svg)](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/static_analysis.yml)
[![.github/workflows/clangformat.yml](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/clangformat.yml/badge.svg)](https://github.com/floatplane/mitsubishi2MQTT/actions/workflows/clangformat.yml)

***
Features:
Expand Down
5 changes: 5 additions & 0 deletions lib/factorial/include/factorial.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

// TODO: delete this after some other tests are set up
// NOLINTNEXTLINE(misc-no-recursion)
inline int factorial(int number) { return number <= 1 ? 1 : factorial(number - 1) * number; }
File renamed without changes.
17 changes: 12 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
src_dir = src/mitsubishi2mqtt
src_dir = src
default_envs =

[env]
framework = arduino
lib_deps =
bblanchon/ArduinoJson @ ^6.21.3
knolleary/PubSubClient @ ^2.8
Expand All @@ -22,9 +21,9 @@ lib_deps =
check_tool = clangtidy, cppcheck
check_flags =
clangtidy: --checks '-*,bugprone-*,clang-analyzer-*,misc-*,performance-*,portability-*,readability-*,-readability-magic-numbers,google-*'
cppcheck: --enable=all --inline-suppr --std=c++20 --suppress=*:*/.pio/* --suppress=missingIncludeSystem
cppcheck: --enable=all --inline-suppr --std=c++20 --suppress=*:*/.pio/* --suppress=unmatchedSuppression:*/.pio/* --suppress=missingIncludeSystem
check_skip_packages = yes
check_src_filters = +<**/*>
check_src_filters = +<src/*> +<lib/*>
build_flags = -Wall
build_src_flags =
!echo '-D COMMIT_HASH=\\"'$(git rev-parse --short HEAD)'\\"'
Expand All @@ -33,21 +32,28 @@ platform_packages =
platformio/tool-clangtidy@^1.150005.0
platformio/tool-cppcheck@^1.21100.230717

[env:native]
platform = native
test_framework = doctest

[env:ESP8266-ESP01]
board = esp01_1m
platform = espressif8266
framework = arduino
board = esp01_1m
monitor_speed = 115200
board_build.ldscript = eagle.flash.1m64.ld

[env:WEMOS_D1_Mini]
platform = espressif8266
framework = arduino
board = d1_mini
monitor_speed = 115200
upload_speed = 460800
board_build.ldscript = eagle.flash.4m2m.ld

[env:WEMOS_D1_Mini_Testing]
platform = ${env:WEMOS_D1_Mini.platform}
framework = ${env:WEMOS_D1_Mini.framework}
board = ${env:WEMOS_D1_Mini.board}
monitor_speed = ${env:WEMOS_D1_Mini.monitor_speed}
upload_speed = ${env:WEMOS_D1_Mini.upload_speed}
Expand All @@ -57,6 +63,7 @@ build_flags = ${env:WEMOS_D1_Mini.build_flags} -D ENABLE_LOGGING

[env:ESP32DEV]
platform = espressif32
framework = arduino
board = esp32dev
lib_deps =
ArduinoJson @6.20.0
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ESP8266WebServer server(80); // ESP8266 web
#include <math.h> // for rounding to Fahrenheit values
// #include <Ticker.h> // for LED status (Using a Wemos D1-Mini)

#include "HeatpumpSettings.hpp"
#include <HeatpumpSettings.hpp>
// #include "config.hpp" // config file
#include "html_common.hpp" // common code HTML (like header, footer)
#include "html_init.hpp" // code html for initial config
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions test/native/test_factorial/factorial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#define DOCTEST_CONFIG_IMPLEMENT // REQUIRED: Enable custom main()
#include <doctest.h>

#include <factorial.hpp>

TEST_CASE("testing the factorial function") {
CHECK(factorial(0) == 1);
CHECK(factorial(1) == 1);
CHECK(factorial(2) == 2);
CHECK(factorial(3) == 6);
CHECK(factorial(10) == 3628800);
}

int main(int argc, char **argv) {
doctest::Context context;

// BEGIN:: PLATFORMIO REQUIRED OPTIONS
context.setOption("success", true); // Report successful tests
context.setOption("no-exitcode", true); // Do not return non-zero code on failed test case
// END:: PLATFORMIO REQUIRED OPTIONS

// YOUR CUSTOM DOCTEST OPTIONS

context.applyCommandLine(argc, argv);
return context.run();
}

0 comments on commit 6ac1227

Please sign in to comment.