Minor improvements to unit testing engine

This commit is contained in:
Ivan Kravets
2019-05-30 16:39:17 +03:00
parent 3cc4af1723
commit d5e277b7cc
4 changed files with 28 additions and 20 deletions

View File

@ -22,7 +22,7 @@ from time import time
import click
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.native import NativeTestProcessor
from platformio.project.config import ProjectConfig
@ -166,10 +166,11 @@ def cli( # pylint: disable=redefined-builtin
passed_nums += 1
status_str = click.style("PASSED", fg="green")
format_str = "test/{:<%d} > {:<%d}\t[{}]" % (testname_max_len,
envname_max_len)
click.echo(
("test/{:<%d} > {:<%d}\t[{}]" %
(testname_max_len, envname_max_len)).format(
testname, click.style(envname, fg="cyan"), status_str),
format_str.format(testname, click.style(envname, fg="cyan"),
status_str),
err=status is False)
print_header(

View File

@ -32,7 +32,8 @@ class EmbeddedTestProcessor(TestProcessorBase):
target = ["__test"]
if self.options['without_uploading']:
target.append("checkprogsize")
self.build_or_upload(target)
if not self.build_or_upload(target):
return False
if not self.options['without_uploading']:
self.print_progress("Uploading... (2/3)")
@ -41,7 +42,8 @@ class EmbeddedTestProcessor(TestProcessorBase):
target.append("nobuild")
else:
target.append("__test")
self.build_or_upload(target)
if not self.build_or_upload(target):
return False
if self.options['without_testing']:
return None

View File

@ -25,7 +25,8 @@ class NativeTestProcessor(TestProcessorBase):
def process(self):
if not self.options['without_building']:
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']:
return None
self.print_progress("Testing... (2/2)")

View File

@ -21,7 +21,7 @@ import click
from platformio import exception
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
TRANSPORT_OPTIONS = {
@ -82,7 +82,7 @@ class TestProcessorBase(object):
def __init__(self, cmd_ctx, testname, envname, options):
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.options = options
self.env_name = envname
@ -109,8 +109,9 @@ class TestProcessorBase(object):
def print_progress(self, text, is_error=False):
click.echo()
print_header(
"[test/%s] %s" % (click.style(
self.test_name, fg="yellow", bold=True), text),
"[test/%s > %s] %s" % (click.style(self.test_name, fg="yellow"),
click.style(self.env_name, fg="cyan"),
text),
is_error=is_error)
def build_or_upload(self, target):
@ -119,19 +120,22 @@ class TestProcessorBase(object):
self._outputcpp_generated = True
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']:
click.echo("Please wait...")
return self.cmd_ctx.invoke(
cmd_run,
project_dir=self.options['project_dir'],
upload_port=self.options['upload_port'],
silent=not self.options['verbose'],
environment=[self.env_name],
disable_auto_clean="nobuild" in target,
target=target)
try:
return self.cmd_ctx.invoke(
cmd_run,
project_dir=self.options['project_dir'],
upload_port=self.options['upload_port'],
silent=not self.options['verbose'],
environment=[self.env_name],
disable_auto_clean="nobuild" in target,
target=target)
except exception.ReturnErrorCode:
return False
def process(self):
raise NotImplementedError