mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Minor improvements to unit testing engine
This commit is contained in:
@ -22,7 +22,7 @@ from time import time
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import exception, util
|
from platformio import exception, util
|
||||||
from platformio.commands.run import print_header
|
from platformio.commands.run.helpers import print_header
|
||||||
from platformio.commands.test.embedded import EmbeddedTestProcessor
|
from platformio.commands.test.embedded import EmbeddedTestProcessor
|
||||||
from platformio.commands.test.native import NativeTestProcessor
|
from platformio.commands.test.native import NativeTestProcessor
|
||||||
from platformio.project.config import ProjectConfig
|
from platformio.project.config import ProjectConfig
|
||||||
@ -166,10 +166,11 @@ def cli( # pylint: disable=redefined-builtin
|
|||||||
passed_nums += 1
|
passed_nums += 1
|
||||||
status_str = click.style("PASSED", fg="green")
|
status_str = click.style("PASSED", fg="green")
|
||||||
|
|
||||||
|
format_str = "test/{:<%d} > {:<%d}\t[{}]" % (testname_max_len,
|
||||||
|
envname_max_len)
|
||||||
click.echo(
|
click.echo(
|
||||||
("test/{:<%d} > {:<%d}\t[{}]" %
|
format_str.format(testname, click.style(envname, fg="cyan"),
|
||||||
(testname_max_len, envname_max_len)).format(
|
status_str),
|
||||||
testname, click.style(envname, fg="cyan"), status_str),
|
|
||||||
err=status is False)
|
err=status is False)
|
||||||
|
|
||||||
print_header(
|
print_header(
|
||||||
|
@ -32,7 +32,8 @@ class EmbeddedTestProcessor(TestProcessorBase):
|
|||||||
target = ["__test"]
|
target = ["__test"]
|
||||||
if self.options['without_uploading']:
|
if self.options['without_uploading']:
|
||||||
target.append("checkprogsize")
|
target.append("checkprogsize")
|
||||||
self.build_or_upload(target)
|
if not self.build_or_upload(target):
|
||||||
|
return False
|
||||||
|
|
||||||
if not self.options['without_uploading']:
|
if not self.options['without_uploading']:
|
||||||
self.print_progress("Uploading... (2/3)")
|
self.print_progress("Uploading... (2/3)")
|
||||||
@ -41,7 +42,8 @@ class EmbeddedTestProcessor(TestProcessorBase):
|
|||||||
target.append("nobuild")
|
target.append("nobuild")
|
||||||
else:
|
else:
|
||||||
target.append("__test")
|
target.append("__test")
|
||||||
self.build_or_upload(target)
|
if not self.build_or_upload(target):
|
||||||
|
return False
|
||||||
|
|
||||||
if self.options['without_testing']:
|
if self.options['without_testing']:
|
||||||
return None
|
return None
|
||||||
|
@ -25,7 +25,8 @@ class NativeTestProcessor(TestProcessorBase):
|
|||||||
def process(self):
|
def process(self):
|
||||||
if not self.options['without_building']:
|
if not self.options['without_building']:
|
||||||
self.print_progress("Building... (1/2)")
|
self.print_progress("Building... (1/2)")
|
||||||
self.build_or_upload(["__test"])
|
if not self.build_or_upload(["__test"]):
|
||||||
|
return False
|
||||||
if self.options['without_testing']:
|
if self.options['without_testing']:
|
||||||
return None
|
return None
|
||||||
self.print_progress("Testing... (2/2)")
|
self.print_progress("Testing... (2/2)")
|
||||||
|
@ -21,7 +21,7 @@ import click
|
|||||||
|
|
||||||
from platformio import exception
|
from platformio import exception
|
||||||
from platformio.commands.run import cli as cmd_run
|
from platformio.commands.run import cli as cmd_run
|
||||||
from platformio.commands.run import print_header
|
from platformio.commands.run.helpers import print_header
|
||||||
from platformio.project.helpers import get_project_test_dir
|
from platformio.project.helpers import get_project_test_dir
|
||||||
|
|
||||||
TRANSPORT_OPTIONS = {
|
TRANSPORT_OPTIONS = {
|
||||||
@ -82,7 +82,7 @@ class TestProcessorBase(object):
|
|||||||
|
|
||||||
def __init__(self, cmd_ctx, testname, envname, options):
|
def __init__(self, cmd_ctx, testname, envname, options):
|
||||||
self.cmd_ctx = cmd_ctx
|
self.cmd_ctx = cmd_ctx
|
||||||
self.cmd_ctx.meta['piotest_processor'] = True
|
self.cmd_ctx.meta['piotest_processor'] = True # FIXME
|
||||||
self.test_name = testname
|
self.test_name = testname
|
||||||
self.options = options
|
self.options = options
|
||||||
self.env_name = envname
|
self.env_name = envname
|
||||||
@ -109,8 +109,9 @@ class TestProcessorBase(object):
|
|||||||
def print_progress(self, text, is_error=False):
|
def print_progress(self, text, is_error=False):
|
||||||
click.echo()
|
click.echo()
|
||||||
print_header(
|
print_header(
|
||||||
"[test/%s] %s" % (click.style(
|
"[test/%s > %s] %s" % (click.style(self.test_name, fg="yellow"),
|
||||||
self.test_name, fg="yellow", bold=True), text),
|
click.style(self.env_name, fg="cyan"),
|
||||||
|
text),
|
||||||
is_error=is_error)
|
is_error=is_error)
|
||||||
|
|
||||||
def build_or_upload(self, target):
|
def build_or_upload(self, target):
|
||||||
@ -119,19 +120,22 @@ class TestProcessorBase(object):
|
|||||||
self._outputcpp_generated = True
|
self._outputcpp_generated = True
|
||||||
|
|
||||||
if self.test_name != "*":
|
if self.test_name != "*":
|
||||||
self.cmd_ctx.meta['piotest'] = self.test_name
|
self.cmd_ctx.meta['piotest'] = self.test_name # FIXME
|
||||||
|
|
||||||
if not self.options['verbose']:
|
if not self.options['verbose']:
|
||||||
click.echo("Please wait...")
|
click.echo("Please wait...")
|
||||||
|
|
||||||
return self.cmd_ctx.invoke(
|
try:
|
||||||
cmd_run,
|
return self.cmd_ctx.invoke(
|
||||||
project_dir=self.options['project_dir'],
|
cmd_run,
|
||||||
upload_port=self.options['upload_port'],
|
project_dir=self.options['project_dir'],
|
||||||
silent=not self.options['verbose'],
|
upload_port=self.options['upload_port'],
|
||||||
environment=[self.env_name],
|
silent=not self.options['verbose'],
|
||||||
disable_auto_clean="nobuild" in target,
|
environment=[self.env_name],
|
||||||
target=target)
|
disable_auto_clean="nobuild" in target,
|
||||||
|
target=target)
|
||||||
|
except exception.ReturnErrorCode:
|
||||||
|
return False
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
Reference in New Issue
Block a user