mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Implement required setUp/tearDown functions for the latest Unity testing framework
This commit is contained in:
2
docs
2
docs
Submodule docs updated: ad5788644c...ec9d6ca64c
2
examples
2
examples
Submodule examples updated: 18c0d44404...a7b73dc2ff
@ -112,8 +112,9 @@ def unittest_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefine
|
||||
|
||||
if not verbose:
|
||||
click.echo("Verbose mode can be enabled via `-v, --verbose` option")
|
||||
click.secho("Collected %d tests" % len(test_names), bold=True, nl=False)
|
||||
click.echo(" (%s)" % ", ".join(test_names))
|
||||
click.secho("Collected %d tests" % len(test_names), bold=True, nl=not verbose)
|
||||
if verbose:
|
||||
click.echo(" (%s)" % ", ".join(test_names))
|
||||
|
||||
test_summary = TestSummary(os.path.basename(project_dir))
|
||||
default_envs = config.default_envs()
|
||||
|
@ -57,7 +57,7 @@ void unityOutputFlush();
|
||||
void unityOutputComplete();
|
||||
|
||||
#define UNITY_OUTPUT_START() unityOutputStart((unsigned long) $baudrate)
|
||||
#define UNITY_OUTPUT_CHAR(a) unityOutputChar(a)
|
||||
#define UNITY_OUTPUT_CHAR(c) unityOutputChar(c)
|
||||
#define UNITY_OUTPUT_FLUSH() unityOutputFlush()
|
||||
#define UNITY_OUTPUT_COMPLETE() unityOutputComplete()
|
||||
|
||||
@ -207,14 +207,23 @@ void unityOutputComplete(void) { unittest_uart_end(); }
|
||||
|
||||
def configure_build_env(self, env):
|
||||
env.Append(CPPDEFINES=["UNITY_INCLUDE_CONFIG_H"])
|
||||
if self.custom_unity_config_exists(
|
||||
[env.subst(item) for item in (env.get("CPPPATH") or [])]
|
||||
):
|
||||
return env
|
||||
env.Replace(
|
||||
UNITY_CONFIG_DIR=os.path.join("$BUILD_DIR", "unity_config"),
|
||||
BUILD_UNITY_CONFIG_DIR=os.path.join("$BUILD_DIR", "unity_config_build"),
|
||||
)
|
||||
env.Append(CPPPATH=["$UNITY_CONFIG_DIR"])
|
||||
self.generate_unity_extras(env.subst("$UNITY_CONFIG_DIR"))
|
||||
env.Append(
|
||||
CPPPATH=["$UNITY_CONFIG_DIR"],
|
||||
LIBS=[env.BuildLibrary("$BUILD_UNITY_CONFIG_DIR", "$UNITY_CONFIG_DIR")],
|
||||
env.BuildSources("$BUILD_UNITY_CONFIG_DIR", "$UNITY_CONFIG_DIR")
|
||||
return env
|
||||
|
||||
@staticmethod
|
||||
def custom_unity_config_exists(include_dirs):
|
||||
return any(
|
||||
os.path.isfile(os.path.join(d, "unity_config.h")) for d in include_dirs
|
||||
)
|
||||
|
||||
def generate_unity_extras(self, dst_dir):
|
||||
|
@ -126,6 +126,10 @@ void setUp(){
|
||||
my_extra_fun();
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
// clean stuff up here
|
||||
}
|
||||
|
||||
void dummy_test(void) {
|
||||
TEST_ASSERT_EQUAL(1, TEST_ONE);
|
||||
}
|
||||
@ -146,46 +150,6 @@ int main() {
|
||||
assert "Disabled test suite" not in result.output
|
||||
|
||||
|
||||
def test_unity_setup_teardown(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(){
|
||||
printf("setUp called");
|
||||
}
|
||||
void tearDown(){
|
||||
printf("tearDown called");
|
||||
}
|
||||
|
||||
void dummy_test(void) {
|
||||
TEST_ASSERT_EQUAL(1, 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
result = clirunner.invoke(
|
||||
unittest_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert all(f in result.output for f in ("setUp called", "tearDown called"))
|
||||
|
||||
|
||||
def test_crashed_program(clirunner, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
@ -230,6 +194,97 @@ int main(int argc, char *argv[]) {
|
||||
)
|
||||
|
||||
|
||||
def test_unity_setup_teardown(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(){
|
||||
printf("setUp called");
|
||||
}
|
||||
void tearDown(){
|
||||
printf("tearDown called");
|
||||
}
|
||||
|
||||
void dummy_test(void) {
|
||||
TEST_ASSERT_EQUAL(1, 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
result = clirunner.invoke(
|
||||
unittest_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert all(f in result.output for f in ("setUp called", "tearDown called"))
|
||||
|
||||
|
||||
def test_unity_custom_config(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("unity_config.h").write(
|
||||
"""
|
||||
#include <stdio.h>
|
||||
|
||||
#define CUSTOM_UNITY_CONFIG
|
||||
|
||||
#define UNITY_OUTPUT_CHAR(c) putchar(c)
|
||||
#define UNITY_OUTPUT_FLUSH() fflush(stdout)
|
||||
"""
|
||||
)
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(){
|
||||
#ifdef CUSTOM_UNITY_CONFIG
|
||||
printf("Found custom unity_config.h\\n");
|
||||
#endif
|
||||
}
|
||||
void tearDown(){
|
||||
}
|
||||
|
||||
void dummy_test(void) {
|
||||
TEST_ASSERT_EQUAL(1, 1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
result = clirunner.invoke(
|
||||
unittest_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert all(f in result.output for f in ("Found custom unity_config", "dummy_test"))
|
||||
|
||||
|
||||
def test_legacy_unity_custom_transport(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
@ -247,6 +302,14 @@ test_transport = custom
|
||||
"""
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(void) {
|
||||
// set stuff up here
|
||||
}
|
||||
|
||||
void tearDown(void) {
|
||||
// clean stuff up here
|
||||
}
|
||||
|
||||
void dummy_test(void) {
|
||||
TEST_ASSERT_EQUAL(1, 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user