mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 18:17:13 +02:00
Dynamically choose extension for file with unit test transports (#3454)
C file should be used by default as only Arduino and mbed require C++ files. There might be a lot of legacy projects so custom transport is also set to use C++.
This commit is contained in:
@ -29,6 +29,7 @@ TRANSPORT_OPTIONS = {
|
|||||||
"flush": "Serial.flush()",
|
"flush": "Serial.flush()",
|
||||||
"begin": "Serial.begin($baudrate)",
|
"begin": "Serial.begin($baudrate)",
|
||||||
"end": "Serial.end()",
|
"end": "Serial.end()",
|
||||||
|
"language": "cpp",
|
||||||
},
|
},
|
||||||
"mbed": {
|
"mbed": {
|
||||||
"include": "#include <mbed.h>",
|
"include": "#include <mbed.h>",
|
||||||
@ -37,6 +38,7 @@ TRANSPORT_OPTIONS = {
|
|||||||
"flush": "",
|
"flush": "",
|
||||||
"begin": "pc.baud($baudrate)",
|
"begin": "pc.baud($baudrate)",
|
||||||
"end": "",
|
"end": "",
|
||||||
|
"language": "cpp",
|
||||||
},
|
},
|
||||||
"espidf": {
|
"espidf": {
|
||||||
"include": "#include <stdio.h>",
|
"include": "#include <stdio.h>",
|
||||||
@ -46,6 +48,14 @@ TRANSPORT_OPTIONS = {
|
|||||||
"begin": "",
|
"begin": "",
|
||||||
"end": "",
|
"end": "",
|
||||||
},
|
},
|
||||||
|
"zephyr": {
|
||||||
|
"include": "#include <sys/printk.h>",
|
||||||
|
"object": "",
|
||||||
|
"putchar": "printk(\"%c\", c)",
|
||||||
|
"flush": "",
|
||||||
|
"begin": "",
|
||||||
|
"end": "",
|
||||||
|
},
|
||||||
"native": {
|
"native": {
|
||||||
"include": "#include <stdio.h>",
|
"include": "#include <stdio.h>",
|
||||||
"object": "",
|
"object": "",
|
||||||
@ -61,6 +71,7 @@ TRANSPORT_OPTIONS = {
|
|||||||
"flush": "unittest_uart_flush()",
|
"flush": "unittest_uart_flush()",
|
||||||
"begin": "unittest_uart_begin()",
|
"begin": "unittest_uart_begin()",
|
||||||
"end": "unittest_uart_end()",
|
"end": "unittest_uart_end()",
|
||||||
|
"language": "cpp",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +91,7 @@ class TestProcessorBase(object):
|
|||||||
self.env_name = envname
|
self.env_name = envname
|
||||||
self.env_options = options["project_config"].items(env=envname, as_dict=True)
|
self.env_options = options["project_config"].items(env=envname, as_dict=True)
|
||||||
self._run_failed = False
|
self._run_failed = False
|
||||||
self._outputcpp_generated = False
|
self._output_file_generated = False
|
||||||
|
|
||||||
def get_transport(self):
|
def get_transport(self):
|
||||||
transport = None
|
transport = None
|
||||||
@ -105,11 +116,11 @@ class TestProcessorBase(object):
|
|||||||
click.secho(text, bold=self.options.get("verbose"))
|
click.secho(text, bold=self.options.get("verbose"))
|
||||||
|
|
||||||
def build_or_upload(self, target):
|
def build_or_upload(self, target):
|
||||||
if not self._outputcpp_generated:
|
if not self._output_file_generated:
|
||||||
self.generate_outputcpp(
|
self.generate_output_file(
|
||||||
self.options["project_config"].get_optional_dir("test")
|
self.options["project_config"].get_optional_dir("test")
|
||||||
)
|
)
|
||||||
self._outputcpp_generated = True
|
self._output_file_generated = True
|
||||||
|
|
||||||
if self.test_name != "*":
|
if self.test_name != "*":
|
||||||
self.cmd_ctx.meta[CTX_META_TEST_RUNNING_NAME] = self.test_name
|
self.cmd_ctx.meta[CTX_META_TEST_RUNNING_NAME] = self.test_name
|
||||||
@ -147,10 +158,10 @@ class TestProcessorBase(object):
|
|||||||
else:
|
else:
|
||||||
click.echo(line)
|
click.echo(line)
|
||||||
|
|
||||||
def generate_outputcpp(self, test_dir):
|
def generate_output_file(self, test_dir):
|
||||||
assert isdir(test_dir)
|
assert isdir(test_dir)
|
||||||
|
|
||||||
cpp_tpl = "\n".join(
|
file_tpl = "\n".join(
|
||||||
[
|
[
|
||||||
"$include",
|
"$include",
|
||||||
"#include <output_export.h>",
|
"#include <output_export.h>",
|
||||||
@ -194,10 +205,12 @@ class TestProcessorBase(object):
|
|||||||
fg="yellow",
|
fg="yellow",
|
||||||
)
|
)
|
||||||
|
|
||||||
tpl = Template(cpp_tpl).substitute(TRANSPORT_OPTIONS[self.get_transport()])
|
transport_options = TRANSPORT_OPTIONS[self.get_transport()]
|
||||||
|
tpl = Template(file_tpl).substitute(transport_options)
|
||||||
data = Template(tpl).substitute(baudrate=self.get_baudrate())
|
data = Template(tpl).substitute(baudrate=self.get_baudrate())
|
||||||
|
tmp_file = join(
|
||||||
tmp_file = join(test_dir, "output_export.cpp")
|
test_dir, "output_export." + transport_options.get("language", "c")
|
||||||
|
)
|
||||||
with open(tmp_file, "w") as fp:
|
with open(tmp_file, "w") as fp:
|
||||||
fp.write(data)
|
fp.write(data)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user