Browse Source

ci: run pio test directory

mcspr-patch-1
Max Prokhorov 4 years ago
committed by Maxim Prokhorov
parent
commit
a41819a28a
7 changed files with 62 additions and 13 deletions
  1. +3
    -0
      .travis.yml
  2. +2
    -1
      code/test/platformio.ini
  3. +16
    -0
      code/test/unit/basic/basic.cpp
  4. +14
    -10
      code/test/unit/tuya/tuya.cpp
  5. +21
    -0
      code/test/unit/url/url.cpp
  6. +3
    -1
      travis_install.sh
  7. +3
    -1
      travis_script.sh

+ 3
- 0
.travis.yml View File

@ -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


+ 2
- 1
code/test/platformio.ini View File

@ -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/

+ 16
- 0
code/test/unit/basic/basic.cpp View File

@ -0,0 +1,16 @@
#include <unity.h>
#include <Arduino.h>
// 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();
}

code/test/unit/tuya_test.cpp → code/test/unit/tuya/tuya.cpp View File

@ -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<bool> 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();
}

+ 21
- 0
code/test/unit/url/url.cpp View File

@ -0,0 +1,21 @@
#include <Arduino.h>
#include <unity.h>
#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();
}

+ 3
- 1
travis_install.sh View File

@ -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


+ 3
- 1
travis_script.sh View File

@ -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


Loading…
Cancel
Save