mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Improve unit testing output; fix issue with non-ascii output from embedded device // Issue #753
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
|
||||
import sys
|
||||
|
||||
VERSION = (3, 0, "0a5")
|
||||
VERSION = (3, 0, "0a6")
|
||||
__version__ = ".".join([str(s) for s in VERSION])
|
||||
|
||||
__title__ = "platformio"
|
||||
|
@ -258,7 +258,7 @@ def GetActualLDScript(env):
|
||||
|
||||
def ProgressHandler(env, node):
|
||||
item = str(node)
|
||||
if ("toolchain-" in item or "tool-" in item) or \
|
||||
if "toolchain-" in item or "tool-" in item or \
|
||||
item.endswith((".o", ".h", ".hpp", ".ipp")):
|
||||
return
|
||||
item = item.replace(env['PIOHOME_DIR'], ".platformio")
|
||||
|
@ -42,6 +42,7 @@ from platformio.managers.platform import PlatformFactory
|
||||
dir_okay=True,
|
||||
writable=True,
|
||||
resolve_path=True))
|
||||
@click.option("-s", "--silent", is_flag=True)
|
||||
@click.option("-v", "--verbose", is_flag=True)
|
||||
@click.option("--disable-auto-clean", is_flag=True)
|
||||
@click.pass_context
|
||||
@ -50,6 +51,7 @@ def cli(ctx, # pylint: disable=R0913,R0914
|
||||
target,
|
||||
upload_port,
|
||||
project_dir,
|
||||
silent,
|
||||
verbose,
|
||||
disable_auto_clean):
|
||||
with util.cd(project_dir):
|
||||
@ -102,11 +104,12 @@ def cli(ctx, # pylint: disable=R0913,R0914
|
||||
options['piotest'] = ctx.meta['piotest']
|
||||
|
||||
ep = EnvironmentProcessor(ctx, envname, options, target,
|
||||
upload_port, verbose)
|
||||
upload_port, silent, verbose)
|
||||
results.append(ep.process())
|
||||
|
||||
if not all(results):
|
||||
raise exception.ReturnErrorCode()
|
||||
return True
|
||||
|
||||
|
||||
class EnvironmentProcessor(object):
|
||||
@ -130,12 +133,14 @@ class EnvironmentProcessor(object):
|
||||
options,
|
||||
targets,
|
||||
upload_port,
|
||||
silent,
|
||||
verbose):
|
||||
self.cmd_ctx = cmd_ctx
|
||||
self.name = name
|
||||
self.options = options
|
||||
self.targets = targets
|
||||
self.upload_port = upload_port
|
||||
self.silent = silent
|
||||
self.verbose = verbose
|
||||
|
||||
def process(self):
|
||||
@ -155,6 +160,8 @@ class EnvironmentProcessor(object):
|
||||
self.name, fg="cyan", bold=True),
|
||||
", ".join(["%s: %s" % opts for opts in process_opts])))
|
||||
click.secho("-" * terminal_width, bold=True)
|
||||
if self.silent:
|
||||
click.echo("Please wait...")
|
||||
|
||||
self.options = self._validate_options(self.options)
|
||||
result = self._run()
|
||||
@ -238,7 +245,7 @@ class EnvironmentProcessor(object):
|
||||
cmd_platform_install, platforms=[self.options['platform']])
|
||||
p = PlatformFactory.newPlatform(self.options['platform'])
|
||||
|
||||
return p.run(build_vars, build_targets, self.verbose)
|
||||
return p.run(build_vars, build_targets, self.silent, self.verbose)
|
||||
|
||||
|
||||
def _autoinstall_libdeps(ctx, libraries, verbose=False):
|
||||
|
@ -53,8 +53,8 @@ def cli(ctx, environment, ignore, upload_port, project_dir, verbose):
|
||||
projectconf = util.load_project_config()
|
||||
assert check_project_envs(projectconf, environment)
|
||||
|
||||
click.echo("Verbose mode can be enabled via `-v, --verbose` option")
|
||||
click.echo("Collected %d items" % len(test_names))
|
||||
click.echo()
|
||||
|
||||
start_time = time()
|
||||
results = []
|
||||
@ -130,11 +130,11 @@ class TestProcessorBase(object):
|
||||
self._run_failed = False
|
||||
|
||||
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),
|
||||
is_error=is_error)
|
||||
click.echo()
|
||||
|
||||
def build_or_upload(self, target):
|
||||
if self.test_name != "*":
|
||||
@ -143,7 +143,7 @@ class TestProcessorBase(object):
|
||||
cmd_run,
|
||||
project_dir=self.options['project_dir'],
|
||||
upload_port=self.options['upload_port'],
|
||||
verbose=self.options['verbose'],
|
||||
silent=not self.options['verbose'],
|
||||
environment=[self.env_name],
|
||||
target=target)
|
||||
|
||||
@ -204,6 +204,13 @@ class EmbeddedTestProcessor(TestProcessorBase):
|
||||
timeout=self.SERIAL_TIMEOUT)
|
||||
while True:
|
||||
line = ser.readline().strip()
|
||||
|
||||
# fix non-ascii output from device
|
||||
for i, c in enumerate(line[::-1]):
|
||||
if ord(c) > 127:
|
||||
line = line[-i:]
|
||||
break
|
||||
|
||||
if not line:
|
||||
continue
|
||||
self.on_run_out(line)
|
||||
|
@ -235,14 +235,15 @@ class PlatformRunMixin(object):
|
||||
|
||||
LINE_ERROR_RE = re.compile(r"(\s+error|error[:\s]+)", re.I)
|
||||
|
||||
def run(self, variables, targets, verbose):
|
||||
def run(self, variables, targets, silent, verbose):
|
||||
assert isinstance(variables, dict)
|
||||
assert isinstance(targets, list)
|
||||
|
||||
self.configure_default_packages(variables, targets)
|
||||
self.install_packages(silent=True)
|
||||
|
||||
self._verbose = verbose or app.get_setting("force_verbose")
|
||||
self.silent = silent
|
||||
self.verbose = verbose or app.get_setting("force_verbose")
|
||||
|
||||
if "clean" in targets:
|
||||
targets = ["-c", "."]
|
||||
@ -276,7 +277,7 @@ class PlatformRunMixin(object):
|
||||
"-j %d" % self.get_job_nums(), "--warn=no-no-parallel-support",
|
||||
"-f", join(util.get_source_dir(), "builder", "main.py")
|
||||
]
|
||||
if not self._verbose and "-c" not in targets:
|
||||
if not self.verbose and "-c" not in targets:
|
||||
cmd.append("--silent")
|
||||
cmd += targets
|
||||
|
||||
@ -297,9 +298,10 @@ class PlatformRunMixin(object):
|
||||
is_error = self.LINE_ERROR_RE.search(line) is not None
|
||||
self._echo_line(line, level=3 if is_error else 2)
|
||||
|
||||
@staticmethod
|
||||
def _echo_line(line, level):
|
||||
def _echo_line(self, line, level):
|
||||
assert 1 <= level <= 3
|
||||
if self.silent and (level < 2 or not line):
|
||||
return
|
||||
fg = (None, "yellow", "red")[level - 1]
|
||||
if level == 1 and "is up to date" in line:
|
||||
fg = "green"
|
||||
@ -326,7 +328,8 @@ class PlatformBase(PlatformPackagesMixin, PlatformRunMixin):
|
||||
join(util.get_home_dir(), "packages"),
|
||||
self._manifest.get("packageRepositories"))
|
||||
|
||||
self._verbose = False
|
||||
self.silent = False
|
||||
self.verbose = False
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
Reference in New Issue
Block a user