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