From a41819a28ae015978bdb872ef8e206056c88b463 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Thu, 2 Jan 2020 00:22:00 +0300 Subject: [PATCH] ci: run pio test directory --- .travis.yml | 3 +++ code/test/platformio.ini | 3 ++- code/test/unit/basic/basic.cpp | 16 +++++++++++++ .../unit/{tuya_test.cpp => tuya/tuya.cpp} | 24 +++++++++++-------- code/test/unit/url/url.cpp | 21 ++++++++++++++++ travis_install.sh | 4 +++- travis_script.sh | 4 +++- 7 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 code/test/unit/basic/basic.cpp rename code/test/unit/{tuya_test.cpp => tuya/tuya.cpp} (97%) create mode 100644 code/test/unit/url/url.cpp diff --git a/.travis.yml b/.travis.yml index fc6fc382..495c72de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,8 @@ env: script: - ./travis_script.sh stages: +- name: Test Host + if: tag IS NOT present - name: Test WebUI if: tag IS NOT present - name: Test PlatformIO Build @@ -23,6 +25,7 @@ stages: if: tag IS present AND tag =~ ^\d+\.\d+\.\d+$ jobs: include: + - stage: Test Host - stage: Test WebUI - stage: Test PlatformIO Build env: TEST_ENV=travis-2_3_0 diff --git a/code/test/platformio.ini b/code/test/platformio.ini index 5cbef5b1..b7a74be1 100644 --- a/code/test/platformio.ini +++ b/code/test/platformio.ini @@ -6,6 +6,7 @@ platform = native lib_compat_mode = off lib_deps = StreamString - https://github.com/bxparks/UnixHostDuino + https://github.com/bxparks/UnixHostDuino#d740398e build_flags = + -std=gnu++11 -I../espurna/ diff --git a/code/test/unit/basic/basic.cpp b/code/test/unit/basic/basic.cpp new file mode 100644 index 00000000..7ecf5eef --- /dev/null +++ b/code/test/unit/basic/basic.cpp @@ -0,0 +1,16 @@ +#include +#include + +// Ensure build system works +// ref: https://github.com/bxparks/UnixHostDuino/pull/6 + +void test_linkage() { + pinMode(0, INPUT); + pinMode(0, OUTPUT); +} + +int main(int argc, char** argv) { + UNITY_BEGIN(); + RUN_TEST(test_linkage); + UNITY_END(); +} diff --git a/code/test/unit/tuya_test.cpp b/code/test/unit/tuya/tuya.cpp similarity index 97% rename from code/test/unit/tuya_test.cpp rename to code/test/unit/tuya/tuya.cpp index 88abc7a8..88fcbc8f 100644 --- a/code/test/unit/tuya_test.cpp +++ b/code/test/unit/tuya/tuya.cpp @@ -18,7 +18,7 @@ using namespace Tuya; -bool test_datatype(const DataFrame& frame, const Type expect_type) { +static bool datatype_same(const DataFrame& frame, const Type expect_type) { const auto type = dataType(frame); return expect_type == type; } @@ -73,7 +73,7 @@ void test_static_dataframe_bool() { "Version should stay 0 unless explicitly set"); TEST_ASSERT_MESSAGE(frame.commandEquals(Command::SetDP), "commandEquals should return true with the same arg as in the constructor"); - TEST_ASSERT_MESSAGE(test_datatype(frame, Type::BOOL), + TEST_ASSERT_MESSAGE(datatype_same(frame, Type::BOOL), "DataProtocol should translate to Type::BOOL"); } @@ -94,27 +94,28 @@ void test_static_dataframe_int() { } -void test_dataframe_const() { +void test_static_dataframe_heartbeat() { - const DataFrame frame(Command::SetDP); + DataFrame frame(Command::Heartbeat); TEST_ASSERT_EQUAL_MESSAGE(0, frame.length, - "Frame with Command::SetDP should not have any data attached to it"); + "Frame with Command::Heartbeat should not have any data attached to it"); TEST_ASSERT_EQUAL_MESSAGE(0, std::distance(frame.cbegin(), frame.cend()), "Frame with Command::SetDP should not have any data attached to it"); + //test_hexdump("static", static_frame.serialize()); } -void test_static_dataframe_heartbeat() { +void test_dataframe_const() { - DataFrame frame(Command::Heartbeat); + const DataFrame frame(Command::SetDP); TEST_ASSERT_EQUAL_MESSAGE(0, frame.length, - "Frame with Command::Heartbeat should not have any data attached to it"); + "Frame with Command::SetDP should not have any data attached to it"); TEST_ASSERT_EQUAL_MESSAGE(0, std::distance(frame.cbegin(), frame.cend()), "Frame with Command::SetDP should not have any data attached to it"); - //test_hexdump("static", static_frame.serialize()); } + void test_dataframe_copy() { DataFrame frame(Command::Heartbeat); @@ -149,7 +150,7 @@ void test_dataframe_raw_data() { DataFrame frame(data.cbegin()); TEST_ASSERT_MESSAGE(frame.commandEquals(Command::ReportDP), "This message should be parsed as data protocol"); - TEST_ASSERT_MESSAGE(test_datatype(frame, Type::BOOL), + TEST_ASSERT_MESSAGE(datatype_same(frame, Type::BOOL), "This message should have boolean datatype attached to it"); TEST_ASSERT_EQUAL_MESSAGE(5, frame.length, "Boolean DP contains 5 bytes"); @@ -176,6 +177,7 @@ class BufferedStream : public Stream { // Print interface size_t write(uint8_t c) { _buffer.push((int)c); + return 1; } size_t write(const unsigned char* data, unsigned long size) { for (size_t n = 0; n < size; ++n) { @@ -219,6 +221,7 @@ void test_transport() { int main(int argc, char** argv) { UNITY_BEGIN(); + RUN_TEST(test_states); RUN_TEST(test_static_dataframe_bool); RUN_TEST(test_static_dataframe_int); @@ -227,6 +230,7 @@ int main(int argc, char** argv) { RUN_TEST(test_dataframe_copy); RUN_TEST(test_dataframe_raw_data); RUN_TEST(test_transport); + UNITY_END(); } diff --git a/code/test/unit/url/url.cpp b/code/test/unit/url/url.cpp new file mode 100644 index 00000000..a0c4fe9b --- /dev/null +++ b/code/test/unit/url/url.cpp @@ -0,0 +1,21 @@ +#include +#include + +#include "libs/URL.h" + +void test_parse() { + URL url("http://api.thingspeak.com/update"); + TEST_ASSERT_EQUAL_STRING("api.thingspeak.com", url.host.c_str()); + TEST_ASSERT_EQUAL_STRING("/update", url.path.c_str()); + TEST_ASSERT_EQUAL(80, url.port); +} + +int main(int argc, char** argv) { + + UNITY_BEGIN(); + + RUN_TEST(test_parse); + + UNITY_END(); + +} diff --git a/travis_install.sh b/travis_install.sh index 251bdd14..ce1043ce 100755 --- a/travis_install.sh +++ b/travis_install.sh @@ -14,7 +14,9 @@ pio_install() { cd code -if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then +if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test host" ]; then + pio_install +elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then npm_install elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test platformio build" ]; then pio_install diff --git a/travis_script.sh b/travis_script.sh index 3881873e..9efaf00f 100755 --- a/travis_script.sh +++ b/travis_script.sh @@ -4,7 +4,9 @@ set -x -e -v cd code -if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then +if [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test host" ]; then + cd test/ && pio test +elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test webui" ]; then ./build.sh -f environments elif [ "${TRAVIS_BUILD_STAGE_NAME}" = "Test platformio build" ]; then # shellcheck disable=SC2086