Apply formatter
This commit is contained in:
@@ -28,6 +28,4 @@ define pio_restart_target
|
||||
end
|
||||
|
||||
$INIT_BREAK
|
||||
""" + (
|
||||
"set startup-with-shell off" if not IS_WINDOWS else ""
|
||||
)
|
||||
""" + ("set startup-with-shell off" if not IS_WINDOWS else "")
|
||||
|
||||
@@ -36,7 +36,7 @@ class DeviceListClient(RemoteClientBase):
|
||||
if not success:
|
||||
click.secho(value, fg="red", err=True)
|
||||
continue
|
||||
(agent_name, devlist) = value
|
||||
agent_name, devlist = value
|
||||
data[agent_name] = devlist
|
||||
|
||||
if self.json_output:
|
||||
|
||||
@@ -99,7 +99,7 @@ class DeviceMonitorClient( # pylint: disable=too-many-instance-attributes
|
||||
if not success:
|
||||
click.secho(value, fg="red", err=True)
|
||||
continue
|
||||
(agent_name, ports) = value
|
||||
agent_name, ports = value
|
||||
for item in ports:
|
||||
if "VID:PID" in item["hwid"]:
|
||||
hwid_devindexes.append(len(devices))
|
||||
|
||||
@@ -234,8 +234,7 @@ def test_private_lib_deps(
|
||||
project_dir = tmp_path / "project"
|
||||
private_lib_dir = project_dir / "lib" / "private"
|
||||
private_lib_dir.mkdir(parents=True)
|
||||
(private_lib_dir / "library.json").write_text(
|
||||
"""
|
||||
(private_lib_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "My Private Lib",
|
||||
"version": "1.0.0",
|
||||
@@ -244,14 +243,11 @@ def test_private_lib_deps(
|
||||
"milesburton/DallasTemperature": "^4.0.4"
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
""")
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:private]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
""")
|
||||
with fs.cd(str(project_dir)):
|
||||
config = ProjectConfig()
|
||||
|
||||
@@ -357,15 +353,13 @@ def test_unknown_project_dependencies(
|
||||
):
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:unknown_platform]
|
||||
platform = unknown_platform
|
||||
|
||||
[env:unknown_lib_deps]
|
||||
lib_deps = SPI, platformio/unknown_library
|
||||
"""
|
||||
)
|
||||
""")
|
||||
with fs.cd(str(project_dir)):
|
||||
result = clirunner.invoke(
|
||||
package_install_cmd,
|
||||
|
||||
@@ -127,29 +127,22 @@ def test_check_tool_complex_defines_handled(
|
||||
):
|
||||
project_dir = tmpdir_factory.mktemp("project_dir")
|
||||
|
||||
project_dir.join("platformio.ini").write(
|
||||
DEFAULT_CONFIG
|
||||
+ R"""
|
||||
project_dir.join("platformio.ini").write(DEFAULT_CONFIG + R"""
|
||||
check_tool = cppcheck, clangtidy, pvs-studio
|
||||
build_flags =
|
||||
-DEXTERNAL_INCLUDE_FILE=\"test.h\"
|
||||
"-DDEFINE_WITH_SPACE="Hello World!""
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
src_dir = project_dir.mkdir("src")
|
||||
src_dir.join("test.h").write(
|
||||
"""
|
||||
src_dir.join("test.h").write("""
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
#define ARBITRARY_CONST_VALUE 10
|
||||
#endif
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
src_dir.join("main.c").write(
|
||||
PVS_STUDIO_FREE_LICENSE_HEADER
|
||||
+ """
|
||||
src_dir.join("main.c").write(PVS_STUDIO_FREE_LICENSE_HEADER + """
|
||||
#if !defined(EXTERNAL_INCLUDE_FILE)
|
||||
#error "EXTERNAL_INCLUDE_FILE is not declared!"
|
||||
#else
|
||||
@@ -165,8 +158,7 @@ int main()
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
default_result = clirunner.invoke(cmd_check, ["--project-dir", str(project_dir)])
|
||||
validate_cliresult(default_result)
|
||||
@@ -183,12 +175,9 @@ def test_check_language_standard_definition_passed(clirunner, tmpdir):
|
||||
|
||||
|
||||
def test_check_language_standard_option_is_converted(clirunner, tmpdir):
|
||||
config = (
|
||||
DEFAULT_CONFIG
|
||||
+ """
|
||||
config = DEFAULT_CONFIG + """
|
||||
build_flags = -std=gnu++1y
|
||||
"""
|
||||
)
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
tmpdir.mkdir("src").join("main.cpp").write(TEST_CODE)
|
||||
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir), "-v"])
|
||||
@@ -197,13 +186,10 @@ build_flags = -std=gnu++1y
|
||||
|
||||
|
||||
def test_check_language_standard_is_prioritized_over_build_flags(clirunner, tmpdir):
|
||||
config = (
|
||||
DEFAULT_CONFIG
|
||||
+ """
|
||||
config = DEFAULT_CONFIG + """
|
||||
check_flags = --std=c++03
|
||||
build_flags = -std=c++17
|
||||
"""
|
||||
)
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
tmpdir.mkdir("src").join("main.cpp").write(TEST_CODE)
|
||||
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir), "-v"])
|
||||
@@ -288,8 +274,7 @@ def test_check_bad_flag_passed(clirunner, check_dir):
|
||||
|
||||
def test_check_success_if_no_errors(clirunner, validate_cliresult, tmpdir):
|
||||
tmpdir.join("platformio.ini").write(DEFAULT_CONFIG)
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write("""
|
||||
#include <stdlib.h>
|
||||
|
||||
void unused_function(){
|
||||
@@ -300,8 +285,7 @@ void unused_function(){
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
|
||||
validate_cliresult(result)
|
||||
@@ -349,17 +333,14 @@ def test_check_cppcheck_misra_addon(clirunner, validate_cliresult, tmpdir_factor
|
||||
check_dir = tmpdir_factory.mktemp("project")
|
||||
check_dir.join("platformio.ini").write(DEFAULT_CONFIG)
|
||||
check_dir.mkdir("src").join("main.c").write(TEST_CODE)
|
||||
check_dir.join("misra.json").write(
|
||||
"""
|
||||
check_dir.join("misra.json").write("""
|
||||
{
|
||||
"script": "addons/misra.py",
|
||||
"args": ["--rule-texts=rules.txt"]
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
check_dir.join("rules.txt").write(
|
||||
"""
|
||||
check_dir.join("rules.txt").write("""
|
||||
Appendix A Summary of guidelines
|
||||
Rule 3.1 Required
|
||||
R3.1 text.
|
||||
@@ -381,8 +362,7 @@ Rule 21.3 Required
|
||||
R21.3 Found MISRA defect
|
||||
Rule 21.4
|
||||
R21.4 text.
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_check, ["--project-dir", str(check_dir), "--flags=--addon=misra.json"]
|
||||
@@ -413,8 +393,7 @@ def test_check_fails_on_defects_only_on_specified_level(
|
||||
):
|
||||
config = DEFAULT_CONFIG + "\ncheck_tool = cppcheck, clangtidy"
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write("""
|
||||
#include <stdlib.h>
|
||||
|
||||
void unused_function(){
|
||||
@@ -425,8 +404,7 @@ void unused_function(){
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
high_result = clirunner.invoke(
|
||||
cmd_check, ["--project-dir", str(tmpdir), "--fail-on-defect=high"]
|
||||
@@ -485,22 +463,17 @@ def test_check_pvs_studio_fails_without_license(clirunner, tmpdir):
|
||||
reason="For some reason the error message is different on Windows",
|
||||
)
|
||||
def test_check_pvs_studio_fails_broken_license(clirunner, tmpdir):
|
||||
config = (
|
||||
DEFAULT_CONFIG
|
||||
+ """
|
||||
config = DEFAULT_CONFIG + """
|
||||
check_tool = pvs-studio
|
||||
check_flags = --lic-file=./pvs-studio.lic
|
||||
"""
|
||||
)
|
||||
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
tmpdir.mkdir("src").join("main.c").write(TEST_CODE)
|
||||
tmpdir.join("pvs-studio.lic").write(
|
||||
"""
|
||||
tmpdir.join("pvs-studio.lic").write("""
|
||||
TEST
|
||||
TEST-TEST-TEST-TEST
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
default_result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir)])
|
||||
verbose_result = clirunner.invoke(cmd_check, ["--project-dir", str(tmpdir), "-v"])
|
||||
@@ -524,9 +497,7 @@ board = nucleo_f401re
|
||||
framework = {framework}
|
||||
check_tool = {check_tool}
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
PVS_STUDIO_FREE_LICENSE_HEADER
|
||||
+ """
|
||||
tmpdir.mkdir("src").join("main.c").write(PVS_STUDIO_FREE_LICENSE_HEADER + """
|
||||
#include <stdlib.h>
|
||||
|
||||
void unused_function(int val){
|
||||
@@ -537,8 +508,7 @@ void unused_function(int val){
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
if framework == "zephyr":
|
||||
zephyr_dir = tmpdir.mkdir("zephyr")
|
||||
@@ -586,22 +556,18 @@ def test_check_multiline_error(clirunner, tmpdir_factory):
|
||||
project_dir = tmpdir_factory.mktemp("project")
|
||||
project_dir.join("platformio.ini").write(DEFAULT_CONFIG)
|
||||
|
||||
project_dir.mkdir("include").join("main.h").write(
|
||||
"""
|
||||
project_dir.mkdir("include").join("main.h").write("""
|
||||
#error This is a multiline error message \\
|
||||
that should be correctly reported \\
|
||||
in both default and verbose modes.
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
project_dir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
project_dir.mkdir("src").join("main.c").write("""
|
||||
#include <stdlib.h>
|
||||
#include "main.h"
|
||||
|
||||
int main() {}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(cmd_check, ["--project-dir", str(project_dir)])
|
||||
errors, _, _ = count_defects(result.output)
|
||||
@@ -693,14 +659,11 @@ def test_check_src_filter(
|
||||
def test_check_src_filter_from_config(clirunner, validate_cliresult, tmpdir_factory):
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
|
||||
config = (
|
||||
DEFAULT_CONFIG
|
||||
+ """
|
||||
config = DEFAULT_CONFIG + """
|
||||
check_src_filters =
|
||||
+<src/spi/*.c*>
|
||||
+<tests/test.cpp>
|
||||
"""
|
||||
)
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
|
||||
src_dir = tmpdir.mkdir("src")
|
||||
@@ -766,14 +729,11 @@ def test_check_src_filter_from_config_legacy(
|
||||
):
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
|
||||
config = (
|
||||
DEFAULT_CONFIG
|
||||
+ """
|
||||
config = DEFAULT_CONFIG + """
|
||||
check_patterns =
|
||||
src/spi/*.c*
|
||||
tests/test.cpp
|
||||
"""
|
||||
)
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
|
||||
src_dir = tmpdir.mkdir("src")
|
||||
@@ -829,13 +789,10 @@ check_src_filters =
|
||||
def test_check_sources_in_project_root(clirunner, validate_cliresult, tmpdir_factory):
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
|
||||
config = (
|
||||
"""
|
||||
config = """
|
||||
[platformio]
|
||||
src_dir = ./
|
||||
"""
|
||||
+ DEFAULT_CONFIG
|
||||
)
|
||||
""" + DEFAULT_CONFIG
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
tmpdir.join("main.cpp").write(TEST_CODE)
|
||||
tmpdir.mkdir("spi").join("uart.cpp").write(TEST_CODE)
|
||||
@@ -853,13 +810,10 @@ def test_check_sources_in_external_dir(clirunner, validate_cliresult, tmpdir_fac
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
external_src_dir = tmpdir_factory.mktemp("external_src_dir")
|
||||
|
||||
config = (
|
||||
f"""
|
||||
config = f"""
|
||||
[platformio]
|
||||
src_dir = {external_src_dir}
|
||||
"""
|
||||
+ DEFAULT_CONFIG
|
||||
)
|
||||
""" + DEFAULT_CONFIG
|
||||
tmpdir.join("platformio.ini").write(config)
|
||||
external_src_dir.join("main.cpp").write(TEST_CODE)
|
||||
|
||||
|
||||
@@ -116,20 +116,16 @@ def test_ci_keep_build_dir_nested_src_dirs(
|
||||
|
||||
# Split default Arduino project in two parts
|
||||
src_dir1 = tmpdir_factory.mktemp("src_1")
|
||||
src_dir1.join("src1.cpp").write(
|
||||
"""
|
||||
src_dir1.join("src1.cpp").write("""
|
||||
#include <Arduino.h>
|
||||
void setup() {}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
src_dir2 = tmpdir_factory.mktemp("src_2")
|
||||
src_dir2.join("src2.cpp").write(
|
||||
"""
|
||||
src_dir2.join("src2.cpp").write("""
|
||||
#include <Arduino.h>
|
||||
void loop() {}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
src_dir1 = str(src_dir1)
|
||||
src_dir2 = str(src_dir2)
|
||||
|
||||
@@ -30,8 +30,7 @@ from platformio.registry.client import RegistryClient
|
||||
def test_saving_deps(clirunner, validate_cliresult, isolated_pio_core, tmpdir_factory):
|
||||
regclient = RegistryClient()
|
||||
project_dir = tmpdir_factory.mktemp("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
project_dir.join("platformio.ini").write("""
|
||||
[env]
|
||||
lib_deps = ArduinoJson
|
||||
|
||||
@@ -43,8 +42,7 @@ framework = foo
|
||||
lib_deps =
|
||||
CustomLib
|
||||
ArduinoJson @ 6.18.5
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
cmd_lib,
|
||||
["-d", str(project_dir), "install", "64", "knolleary/PubSubClient@~2.7"],
|
||||
|
||||
+60
-123
@@ -32,8 +32,7 @@ def test_generic_build(clirunner, validate_cliresult, tmpdir):
|
||||
),
|
||||
]
|
||||
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
extra_scripts =
|
||||
@@ -44,36 +43,27 @@ build_src_flags = -DI_AM_ONLY_SRC_FLAG
|
||||
build_flags =
|
||||
; -DCOMMENTED_MACRO
|
||||
%s ; inline comment
|
||||
"""
|
||||
% " ".join([f[0] for f in build_flags])
|
||||
)
|
||||
""" % " ".join([f[0] for f in build_flags]))
|
||||
|
||||
tmpdir.join("pre_script.py").write(
|
||||
"""
|
||||
tmpdir.join("pre_script.py").write("""
|
||||
Import("env")
|
||||
|
||||
def post_prog_action(source, target, env):
|
||||
print("post_prog_action is called")
|
||||
|
||||
env.AddPostAction("$PROGPATH", post_prog_action)
|
||||
"""
|
||||
)
|
||||
tmpdir.join("post_script.py").write(
|
||||
"""
|
||||
""")
|
||||
tmpdir.join("post_script.py").write("""
|
||||
Import("projenv")
|
||||
|
||||
projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
tmpdir.mkdir("extra_inc").join("foo.h").write(
|
||||
"""
|
||||
tmpdir.mkdir("extra_inc").join("foo.h").write("""
|
||||
#define FOO
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
tmpdir.mkdir("src").join("main.cpp").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.cpp").write("""
|
||||
#include "foo.h"
|
||||
|
||||
#ifndef FOO
|
||||
@@ -116,17 +106,13 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
tmpdir.mkdir("include").join("cpppath-include.h").write(
|
||||
"""
|
||||
tmpdir.mkdir("include").join("cpppath-include.h").write("""
|
||||
#define I_AM_FORCED_CPPPATH_INCLUDE
|
||||
"""
|
||||
)
|
||||
""")
|
||||
component_dir = tmpdir.mkdir("lib").mkdir("component")
|
||||
component_dir.join("component.h").write(
|
||||
"""
|
||||
component_dir.join("component.h").write("""
|
||||
#define I_AM_COMPONENT
|
||||
|
||||
#ifndef I_AM_ONLY_SRC_FLAG
|
||||
@@ -134,22 +120,17 @@ int main() {
|
||||
#endif
|
||||
|
||||
void dummy(void);
|
||||
"""
|
||||
)
|
||||
component_dir.join("component.cpp").write(
|
||||
"""
|
||||
""")
|
||||
component_dir.join("component.cpp").write("""
|
||||
#ifdef I_AM_ONLY_SRC_FLAG
|
||||
#error "I_AM_ONLY_SRC_FLAG"
|
||||
#endif
|
||||
|
||||
void dummy(void ) {};
|
||||
"""
|
||||
)
|
||||
component_dir.join("component-forced-include.h").write(
|
||||
"""
|
||||
""")
|
||||
component_dir.join("component-forced-include.h").write("""
|
||||
#define I_AM_FORCED_COMPONENT_INCLUDE
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
@@ -160,8 +141,7 @@ void dummy(void ) {};
|
||||
|
||||
|
||||
def test_build_unflags(clirunner, validate_cliresult, tmpdir):
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
build_unflags =
|
||||
@@ -175,11 +155,9 @@ build_unflags =
|
||||
build_flags =
|
||||
-DTMP_MACRO_3=10
|
||||
extra_scripts = pre:extra.py
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
tmpdir.join("extra.py").write(
|
||||
"""
|
||||
tmpdir.join("extra.py").write("""
|
||||
Import("env")
|
||||
env.Append(CPPPATH="%s")
|
||||
env.Append(CPPDEFINES="TMP_MACRO_1")
|
||||
@@ -188,12 +166,9 @@ env.Append(CPPDEFINES=[("TMP_MACRO_3", 13)])
|
||||
env.Append(CPPDEFINES=[("TMP_MACRO_4", 4)])
|
||||
env.Append(CCFLAGS=["-Os"])
|
||||
env.Append(LIBS=["unknownLib"])
|
||||
"""
|
||||
% str(tmpdir)
|
||||
)
|
||||
""" % str(tmpdir))
|
||||
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write("""
|
||||
#ifndef TMP_MACRO_1
|
||||
#error "TMP_MACRO_1 should be defined"
|
||||
#endif
|
||||
@@ -212,8 +187,7 @@ env.Append(LIBS=["unknownLib"])
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
@@ -224,20 +198,16 @@ int main() {
|
||||
|
||||
|
||||
def test_debug_default_build_flags(clirunner, validate_cliresult, tmpdir):
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
build_type = debug
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write("""
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
@@ -256,22 +226,17 @@ int main() {
|
||||
def test_debug_custom_build_flags(clirunner, validate_cliresult, tmpdir):
|
||||
custom_debug_build_flags = ("-O3", "-g3", "-ggdb3")
|
||||
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
build_type = debug
|
||||
debug_build_flags = %s
|
||||
"""
|
||||
% " ".join(custom_debug_build_flags)
|
||||
)
|
||||
""" % " ".join(custom_debug_build_flags))
|
||||
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write("""
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
@@ -290,25 +255,20 @@ int main() {
|
||||
def test_symlinked_libs(clirunner, validate_cliresult, tmp_path: Path):
|
||||
external_pkg_dir = tmp_path / "External"
|
||||
external_pkg_dir.mkdir()
|
||||
(external_pkg_dir / "External.h").write_text(
|
||||
"""
|
||||
(external_pkg_dir / "External.h").write_text("""
|
||||
#define EXTERNAL 1
|
||||
"""
|
||||
)
|
||||
(external_pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
""")
|
||||
(external_pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "External",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
project_dir = tmp_path / "project"
|
||||
src_dir = project_dir / "src"
|
||||
src_dir.mkdir(parents=True)
|
||||
(src_dir / "main.c").write_text(
|
||||
"""
|
||||
(src_dir / "main.c").write_text("""
|
||||
#include <External.h>
|
||||
#
|
||||
#if !defined(EXTERNAL)
|
||||
@@ -317,15 +277,12 @@ def test_symlinked_libs(clirunner, validate_cliresult, tmp_path: Path):
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
""")
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:native]
|
||||
platform = native
|
||||
lib_deps = symlink://../External
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(project_dir)])
|
||||
validate_cliresult(result)
|
||||
|
||||
@@ -334,8 +291,7 @@ def test_stringification(clirunner, validate_cliresult, tmp_path: Path):
|
||||
project_dir = tmp_path / "project"
|
||||
src_dir = project_dir / "src"
|
||||
src_dir.mkdir(parents=True)
|
||||
(src_dir / "main.c").write_text(
|
||||
"""
|
||||
(src_dir / "main.c").write_text("""
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
printf("MACRO_1=<%s>\\n", MACRO_1);
|
||||
@@ -344,28 +300,23 @@ int main(void) {
|
||||
printf("MACRO_4=<%s>\\n", MACRO_4);
|
||||
return(0);
|
||||
}
|
||||
"""
|
||||
)
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
""")
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:native]
|
||||
platform = native
|
||||
extra_scripts = script.py
|
||||
build_flags =
|
||||
'-DMACRO_1="Hello World!"'
|
||||
'-DMACRO_2="Text is \\\\"Quoted\\\\""'
|
||||
"""
|
||||
)
|
||||
(project_dir / "script.py").write_text(
|
||||
"""
|
||||
""")
|
||||
(project_dir / "script.py").write_text("""
|
||||
Import("projenv")
|
||||
|
||||
projenv.Append(CPPDEFINES=[
|
||||
("MACRO_3", projenv.StringifyMacro('Hello "World"! Isn\\'t true?')),
|
||||
("MACRO_4", projenv.StringifyMacro("Special chars: ',(,),[,],:"))
|
||||
])
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
cmd_run, ["--project-dir", str(project_dir), "-t", "exec"]
|
||||
)
|
||||
@@ -383,11 +334,9 @@ def test_ldf(clirunner, validate_cliresult, tmp_path: Path):
|
||||
lib_dir = project_dir / "lib"
|
||||
a_lib_dir = lib_dir / "a"
|
||||
a_lib_dir.mkdir(parents=True)
|
||||
(a_lib_dir / "a.h").write_text(
|
||||
"""
|
||||
(a_lib_dir / "a.h").write_text("""
|
||||
#include <some_from_b.h>
|
||||
"""
|
||||
)
|
||||
""")
|
||||
# b
|
||||
b_lib_dir = lib_dir / "b"
|
||||
b_lib_dir.mkdir(parents=True)
|
||||
@@ -395,25 +344,19 @@ def test_ldf(clirunner, validate_cliresult, tmp_path: Path):
|
||||
# c
|
||||
c_lib_dir = lib_dir / "c"
|
||||
c_lib_dir.mkdir(parents=True)
|
||||
(c_lib_dir / "parse_c_by_name.h").write_text(
|
||||
"""
|
||||
(c_lib_dir / "parse_c_by_name.h").write_text("""
|
||||
void some_func();
|
||||
"""
|
||||
)
|
||||
(c_lib_dir / "parse_c_by_name.c").write_text(
|
||||
"""
|
||||
""")
|
||||
(c_lib_dir / "parse_c_by_name.c").write_text("""
|
||||
#include <d.h>
|
||||
#include <parse_c_by_name.h>
|
||||
|
||||
void some_func() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
(c_lib_dir / "some.c").write_text(
|
||||
"""
|
||||
""")
|
||||
(c_lib_dir / "some.c").write_text("""
|
||||
#include <d.h>
|
||||
"""
|
||||
)
|
||||
""")
|
||||
# d
|
||||
d_lib_dir = lib_dir / "d"
|
||||
d_lib_dir.mkdir(parents=True)
|
||||
@@ -422,25 +365,19 @@ void some_func() {
|
||||
# project
|
||||
src_dir = project_dir / "src"
|
||||
src_dir.mkdir(parents=True)
|
||||
(src_dir / "main.h").write_text(
|
||||
"""
|
||||
(src_dir / "main.h").write_text("""
|
||||
#include <a.h>
|
||||
#include <parse_c_by_name.h>
|
||||
"""
|
||||
)
|
||||
(src_dir / "main.c").write_text(
|
||||
"""
|
||||
""")
|
||||
(src_dir / "main.c").write_text("""
|
||||
#include <main.h>
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
""")
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(project_dir)])
|
||||
validate_cliresult(result)
|
||||
|
||||
+40
-80
@@ -98,31 +98,26 @@ def test_list_tests(clirunner, validate_cliresult, tmp_path: Path):
|
||||
def test_group_and_custom_runner(clirunner, validate_cliresult, tmp_path: Path):
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:native]
|
||||
platform = native
|
||||
test_framework = custom
|
||||
"""
|
||||
)
|
||||
""")
|
||||
test_dir = project_dir / "test"
|
||||
|
||||
# non-test folder, does not start with "test_"
|
||||
disabled_dir = test_dir / "disabled"
|
||||
disabled_dir.mkdir(parents=True)
|
||||
(disabled_dir / "main.c").write_text(
|
||||
"""
|
||||
(disabled_dir / "main.c").write_text("""
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Disabled test suite\\n")
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# root
|
||||
(test_dir / "my_extra.h").write_text(
|
||||
"""
|
||||
(test_dir / "my_extra.h").write_text("""
|
||||
#ifndef MY_EXTRA_H
|
||||
#define MY_EXTRA_H
|
||||
|
||||
@@ -130,23 +125,19 @@ int main() {
|
||||
|
||||
void my_extra_fun(void);
|
||||
#endif
|
||||
"""
|
||||
)
|
||||
(test_dir / "my_extra.c").write_text(
|
||||
"""
|
||||
""")
|
||||
(test_dir / "my_extra.c").write_text("""
|
||||
#include "my_extra.h"
|
||||
|
||||
void my_extra_fun(void) {
|
||||
printf("Called from my_extra_fun\\n");
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# test group
|
||||
test_group = test_dir / "group"
|
||||
test_group.mkdir(parents=True)
|
||||
(test_group / "test_custom_runner.py").write_text(
|
||||
"""
|
||||
(test_group / "test_custom_runner.py").write_text("""
|
||||
import click
|
||||
|
||||
from platformio.test.runners.unity import UnityTestRunner
|
||||
@@ -154,20 +145,16 @@ from platformio.test.runners.unity import UnityTestRunner
|
||||
class CustomTestRunner(UnityTestRunner):
|
||||
def teardown(self):
|
||||
click.echo("CustomTestRunner::TearDown called")
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# test suite
|
||||
test_suite_dir = test_group / "test_nested"
|
||||
test_include_dir = test_suite_dir / "include"
|
||||
test_include_dir.mkdir(parents=True)
|
||||
(test_include_dir / "my_nested.h").write_text(
|
||||
"""
|
||||
(test_include_dir / "my_nested.h").write_text("""
|
||||
#define TEST_ONE 1
|
||||
"""
|
||||
)
|
||||
(test_suite_dir / "main.c").write_text(
|
||||
"""
|
||||
""")
|
||||
(test_suite_dir / "main.c").write_text("""
|
||||
#include <unity.h>
|
||||
#include <my_extra.h>
|
||||
#include <include/my_nested.h>
|
||||
@@ -189,8 +176,7 @@ int main() {
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
pio_test_cmd,
|
||||
["-d", str(project_dir), "-e", "native", "--verbose"],
|
||||
@@ -204,15 +190,12 @@ int main() {
|
||||
|
||||
def test_crashed_program(clirunner, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
project_dir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
""")
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
test_dir.join("test_main.c").write("""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
|
||||
@@ -234,8 +217,7 @@ int main(int argc, char *argv[]) {
|
||||
UNITY_END();
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
pio_test_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
@@ -311,21 +293,16 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
def test_unity_setup_teardown(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
project_dir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
""")
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("test_main.h").write(
|
||||
"""
|
||||
test_dir.join("test_main.h").write("""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
"""
|
||||
)
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
""")
|
||||
test_dir.join("test_main.c").write("""
|
||||
#include "test_main.h"
|
||||
|
||||
void setUp(){
|
||||
@@ -344,8 +321,7 @@ int main() {
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
pio_test_cmd,
|
||||
["-d", str(project_dir), "-e", "native"],
|
||||
@@ -357,26 +333,21 @@ int main() {
|
||||
def test_unity_custom_config(clirunner, validate_cliresult, tmp_path: Path):
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
""")
|
||||
test_dir = project_dir / "test" / "native" / "test_component"
|
||||
test_dir.mkdir(parents=True)
|
||||
(test_dir.parent / "unity_config.h").write_text(
|
||||
"""
|
||||
(test_dir.parent / "unity_config.h").write_text("""
|
||||
#include <stdio.h>
|
||||
|
||||
#define CUSTOM_UNITY_CONFIG
|
||||
|
||||
#define UNITY_OUTPUT_CHAR(c) putchar(c)
|
||||
#define UNITY_OUTPUT_FLUSH() fflush(stdout)
|
||||
"""
|
||||
)
|
||||
(test_dir / "test_main.c").write_text(
|
||||
"""
|
||||
""")
|
||||
(test_dir / "test_main.c").write_text("""
|
||||
#include <stdio.h>
|
||||
#include <unity.h>
|
||||
|
||||
@@ -397,8 +368,7 @@ int main() {
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
pio_test_cmd,
|
||||
["-d", str(project_dir), "-e", "native", "--verbose"],
|
||||
@@ -409,19 +379,16 @@ int main() {
|
||||
|
||||
def test_legacy_unity_custom_transport(clirunner, validate_cliresult, tmpdir):
|
||||
project_dir = tmpdir.mkdir("project")
|
||||
project_dir.join("platformio.ini").write(
|
||||
"""
|
||||
project_dir.join("platformio.ini").write("""
|
||||
[env:embedded]
|
||||
platform = ststm32
|
||||
framework = stm32cube
|
||||
board = nucleo_f401re
|
||||
test_transport = custom
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
test_dir = project_dir.mkdir("test")
|
||||
test_dir.join("test_main.c").write(
|
||||
"""
|
||||
test_dir.join("test_main.c").write("""
|
||||
#include <unity.h>
|
||||
|
||||
void setUp(void) {
|
||||
@@ -441,10 +408,8 @@ int main() {
|
||||
RUN_TEST(dummy_test);
|
||||
UNITY_END();
|
||||
}
|
||||
"""
|
||||
)
|
||||
test_dir.join("unittest_transport.h").write(
|
||||
"""
|
||||
""")
|
||||
test_dir.join("unittest_transport.h").write("""
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -457,8 +422,7 @@ void unittest_uart_end(){}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = clirunner.invoke(
|
||||
pio_test_cmd,
|
||||
[
|
||||
@@ -478,17 +442,14 @@ void unittest_uart_end(){}
|
||||
def test_doctest_framework(clirunner, tmp_path: Path):
|
||||
project_dir = tmp_path / "project"
|
||||
project_dir.mkdir()
|
||||
(project_dir / "platformio.ini").write_text(
|
||||
"""
|
||||
(project_dir / "platformio.ini").write_text("""
|
||||
[env:native]
|
||||
platform = native
|
||||
test_framework = doctest
|
||||
"""
|
||||
)
|
||||
""")
|
||||
test_dir = project_dir / "test" / "test_dummy"
|
||||
test_dir.mkdir(parents=True)
|
||||
(test_dir / "test_main.cpp").write_text(
|
||||
"""
|
||||
(test_dir / "test_main.cpp").write_text("""
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include <doctest.h>
|
||||
|
||||
@@ -554,8 +515,7 @@ int main(int argc, char **argv)
|
||||
context.applyCommandLine(argc, argv);
|
||||
return context.run();
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
junit_output_path = tmp_path / "junit.xml"
|
||||
result = clirunner.invoke(
|
||||
pio_test_cmd,
|
||||
|
||||
@@ -95,15 +95,13 @@ def test_build_legacy_spec(isolated_pio_core, tmpdir_factory):
|
||||
pm = PlatformPackageManager(str(storage_dir))
|
||||
# test src manifest
|
||||
pkg1_dir = storage_dir.join("pkg-1").mkdir()
|
||||
pkg1_dir.join(".pio").mkdir().join(".piopkgmanager.json").write(
|
||||
"""
|
||||
pkg1_dir.join(".pio").mkdir().join(".piopkgmanager.json").write("""
|
||||
{
|
||||
"name": "StreamSpy-0.0.1.tar",
|
||||
"url": "https://dl.platformio.org/e8936b7/StreamSpy-0.0.1.tar.gz",
|
||||
"requirements": null
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
assert pm.build_legacy_spec(str(pkg1_dir)) == PackageSpec(
|
||||
name="StreamSpy-0.0.1.tar",
|
||||
uri="https://dl.platformio.org/e8936b7/StreamSpy-0.0.1.tar.gz",
|
||||
@@ -181,12 +179,10 @@ def test_install_from_uri(isolated_pio_core, tmpdir_factory):
|
||||
|
||||
# install from registry
|
||||
src_dir = tmp_dir.join("registry-1").mkdir()
|
||||
src_dir.join("library.properties").write(
|
||||
"""
|
||||
src_dir.join("library.properties").write("""
|
||||
name = wifilib
|
||||
version = 5.2.7
|
||||
"""
|
||||
)
|
||||
""")
|
||||
spec = PackageSpec("company/wifilib @ ^5")
|
||||
pkg = lm.install_from_uri("file://%s" % src_dir, spec)
|
||||
assert str(pkg.metadata.version) == "5.2.7"
|
||||
@@ -244,8 +240,7 @@ def test_install_lib_depndencies(isolated_pio_core, tmpdir_factory):
|
||||
src_dir = tmp_dir.join("lib-with-deps").mkdir()
|
||||
root_dir = src_dir.mkdir("root")
|
||||
root_dir.mkdir("src").join("main.cpp").write("#include <stdio.h>")
|
||||
root_dir.join("library.json").write(
|
||||
"""
|
||||
root_dir.join("library.json").write("""
|
||||
{
|
||||
"name": "lib-with-deps",
|
||||
"version": "2.0.0",
|
||||
@@ -261,8 +256,7 @@ def test_install_lib_depndencies(isolated_pio_core, tmpdir_factory):
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
lm = LibraryPackageManager(str(tmpdir_factory.mktemp("lib-storage")))
|
||||
lm.set_log_level(logging.ERROR)
|
||||
@@ -293,26 +287,22 @@ def test_install_force(isolated_pio_core, tmpdir_factory):
|
||||
def test_symlink(tmp_path: Path):
|
||||
external_pkg_dir = tmp_path / "External"
|
||||
external_pkg_dir.mkdir()
|
||||
(external_pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
(external_pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "External",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
storage_dir = tmp_path / "storage"
|
||||
installed_pkg_dir = storage_dir / "installed"
|
||||
installed_pkg_dir.mkdir(parents=True)
|
||||
(installed_pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
(installed_pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "Installed",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
spec = "CustomExternal=symlink://%s" % str(external_pkg_dir)
|
||||
lm = LibraryPackageManager(str(storage_dir))
|
||||
@@ -353,8 +343,7 @@ def test_scripts(isolated_pio_core, tmp_path: Path):
|
||||
pkg_dir = tmp_path / "foo"
|
||||
scripts_dir = pkg_dir / "scripts"
|
||||
scripts_dir.mkdir(parents=True)
|
||||
(scripts_dir / "script.py").write_text(
|
||||
"""
|
||||
(scripts_dir / "script.py").write_text("""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -363,10 +352,8 @@ Path("%s.flag" % action).touch()
|
||||
|
||||
if action == "preuninstall":
|
||||
Path("../%s.flag" % action).touch()
|
||||
"""
|
||||
)
|
||||
(pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
""")
|
||||
(pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "foo",
|
||||
"version": "1.0.0",
|
||||
@@ -375,8 +362,7 @@ if action == "preuninstall":
|
||||
"preuninstall2": ["scripts/script.py", "preuninstall"]
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
storage_dir = tmp_path / "storage"
|
||||
lm = LibraryPackageManager(str(storage_dir))
|
||||
@@ -392,8 +378,7 @@ def test_install_circular_dependencies(tmp_path: Path):
|
||||
# Foo
|
||||
pkg_dir = storage_dir / "foo"
|
||||
pkg_dir.mkdir(parents=True)
|
||||
(pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
(pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "Foo",
|
||||
"version": "1.0.0",
|
||||
@@ -401,13 +386,11 @@ def test_install_circular_dependencies(tmp_path: Path):
|
||||
"Bar": "*"
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
# Bar
|
||||
pkg_dir = storage_dir / "bar"
|
||||
pkg_dir.mkdir(parents=True)
|
||||
(pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
(pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "Bar",
|
||||
"version": "1.0.0",
|
||||
@@ -415,8 +398,7 @@ def test_install_circular_dependencies(tmp_path: Path):
|
||||
"Foo": "*"
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
lm = LibraryPackageManager(str(storage_dir))
|
||||
lm.set_log_level(logging.ERROR)
|
||||
@@ -425,8 +407,7 @@ def test_install_circular_dependencies(tmp_path: Path):
|
||||
# root library
|
||||
pkg_dir = tmp_path / "root"
|
||||
pkg_dir.mkdir(parents=True)
|
||||
(pkg_dir / "library.json").write_text(
|
||||
"""
|
||||
(pkg_dir / "library.json").write_text("""
|
||||
{
|
||||
"name": "Root",
|
||||
"version": "1.0.0",
|
||||
@@ -435,8 +416,7 @@ def test_install_circular_dependencies(tmp_path: Path):
|
||||
"Bar": "^1.0.0"
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
lm.install("file://%s" % str(pkg_dir))
|
||||
|
||||
|
||||
@@ -445,14 +425,7 @@ def test_get_installed(isolated_pio_core, tmpdir_factory):
|
||||
pm = ToolPackageManager(str(storage_dir))
|
||||
|
||||
# VCS package
|
||||
(
|
||||
storage_dir.join("pkg-vcs")
|
||||
.mkdir()
|
||||
.join(".git")
|
||||
.mkdir()
|
||||
.join(".piopm")
|
||||
.write(
|
||||
"""
|
||||
(storage_dir.join("pkg-vcs").mkdir().join(".git").mkdir().join(".piopm").write("""
|
||||
{
|
||||
"name": "pkg-via-vcs",
|
||||
"spec": {
|
||||
@@ -465,9 +438,7 @@ def test_get_installed(isolated_pio_core, tmpdir_factory):
|
||||
"type": "tool",
|
||||
"version": "0.0.0+sha.1ea4d5e"
|
||||
}
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
# package without metadata file
|
||||
(
|
||||
@@ -480,8 +451,7 @@ def test_get_installed(isolated_pio_core, tmpdir_factory):
|
||||
# package with metadata file
|
||||
foo_dir = storage_dir.join("foo").mkdir()
|
||||
foo_dir.join("package.json").write('{"name": "foo", "version": "3.6.0"}')
|
||||
foo_dir.join(".piopm").write(
|
||||
"""
|
||||
foo_dir.join(".piopm").write("""
|
||||
{
|
||||
"name": "foo",
|
||||
"spec": {
|
||||
@@ -492,8 +462,7 @@ def test_get_installed(isolated_pio_core, tmpdir_factory):
|
||||
"type": "tool",
|
||||
"version": "3.6.0"
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# test "system"
|
||||
storage_dir.join("pkg-incompatible-system").mkdir().join("package.json").write(
|
||||
|
||||
@@ -284,12 +284,10 @@ includes=Arduino.h, Arduino Space.hpp
|
||||
}
|
||||
|
||||
# Author + Maintainer
|
||||
data = parser.LibraryPropertiesManifestParser(
|
||||
"""
|
||||
data = parser.LibraryPropertiesManifestParser("""
|
||||
author=Rocket Scream Electronics <broken-email.com>
|
||||
maintainer=Rocket Scream Electronics
|
||||
"""
|
||||
).as_dict()
|
||||
""").as_dict()
|
||||
assert data["authors"] == [
|
||||
{"name": "Rocket Scream Electronics", "maintainer": True}
|
||||
]
|
||||
|
||||
@@ -98,8 +98,7 @@ def test_filters(tmpdir_factory):
|
||||
def test_gitgnore_filters(tmpdir_factory):
|
||||
pkg_dir = tmpdir_factory.mktemp("package")
|
||||
pkg_dir.join(".git").mkdir().join("file").write("")
|
||||
pkg_dir.join(".gitignore").write(
|
||||
"""
|
||||
pkg_dir.join(".gitignore").write("""
|
||||
# comment
|
||||
|
||||
gi_file
|
||||
@@ -111,8 +110,7 @@ gi_folder_*
|
||||
gi_keep_file
|
||||
!gi_keep_file
|
||||
LICENSE
|
||||
"""
|
||||
)
|
||||
""")
|
||||
pkg_dir.join("LICENSE").write("")
|
||||
pkg_dir.join("gi_keep_file").write("")
|
||||
pkg_dir.join("gi_file").write("")
|
||||
|
||||
@@ -438,15 +438,13 @@ def test_items(config):
|
||||
|
||||
def test_update_and_save(tmpdir_factory):
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[platformio]
|
||||
extra_configs = a.ini, b.ini
|
||||
|
||||
[env:myenv]
|
||||
board = myboard
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(tmpdir.join("platformio.ini").strpath)
|
||||
assert config.envs() == ["myenv"]
|
||||
assert config.as_tuple()[0][1][0][1] == ["a.ini", "b.ini"]
|
||||
@@ -487,15 +485,13 @@ board = myboard
|
||||
|
||||
def test_update_and_clear(tmpdir_factory):
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[platformio]
|
||||
extra_configs = a.ini, b.ini
|
||||
|
||||
[env:myenv]
|
||||
board = myboard
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(tmpdir.join("platformio.ini").strpath)
|
||||
assert config.sections() == ["platformio", "env:myenv"]
|
||||
config.update([["mysection", [("opt1", "value1"), ("opt2", "value2")]]], clear=True)
|
||||
@@ -588,12 +584,10 @@ def test_win_core_root_dir(tmpdir_factory):
|
||||
|
||||
# Override in config
|
||||
tmpdir = tmpdir_factory.mktemp("project")
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[platformio]
|
||||
core_dir = ~/.pio
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(tmpdir.join("platformio.ini").strpath)
|
||||
assert config.get("platformio", "core_dir") != win_core_root_dir
|
||||
assert config.get("platformio", "core_dir") == os.path.realpath(
|
||||
@@ -608,8 +602,7 @@ core_dir = ~/.pio
|
||||
|
||||
def test_this(tmp_path: Path):
|
||||
project_conf = tmp_path / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[common]
|
||||
board = uno
|
||||
|
||||
@@ -617,8 +610,7 @@ board = uno
|
||||
extends = common
|
||||
build_flags = -D${this.__env__}
|
||||
custom_option = ${this.board}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(str(project_conf))
|
||||
assert config.get("env:myenv", "custom_option") == "uno"
|
||||
assert config.get("env:myenv", "build_flags") == ["-Dmyenv"]
|
||||
@@ -628,30 +620,25 @@ def test_project_name(tmp_path: Path):
|
||||
project_dir = tmp_path / "my-project-name"
|
||||
project_dir.mkdir()
|
||||
project_conf = project_dir / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[env:myenv]
|
||||
"""
|
||||
)
|
||||
""")
|
||||
with fs.cd(str(project_dir)):
|
||||
config = ProjectConfig(str(project_conf))
|
||||
assert config.get("platformio", "name") == "my-project-name"
|
||||
|
||||
# custom name
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[platformio]
|
||||
name = custom-project-name
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(str(project_conf))
|
||||
assert config.get("platformio", "name") == "custom-project-name"
|
||||
|
||||
|
||||
def test_nested_interpolation(tmp_path: Path):
|
||||
project_conf = tmp_path / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[platformio]
|
||||
build_dir = /tmp/pio-$PROJECT_HASH
|
||||
data_dir = $PROJECT_DIR/assets
|
||||
@@ -669,8 +656,7 @@ test_testing_command =
|
||||
16000000L
|
||||
${UPLOAD_PORT and "-p "+UPLOAD_PORT}
|
||||
${platformio.build_dir}/${this.__env__}/firmware.elf
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(str(project_conf))
|
||||
assert config.get("platformio", "data_dir").endswith(
|
||||
os.path.join("$PROJECT_DIR", "assets")
|
||||
@@ -688,8 +674,7 @@ test_testing_command =
|
||||
|
||||
def test_extends_order(tmp_path: Path):
|
||||
project_conf = tmp_path / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[a]
|
||||
board = test
|
||||
|
||||
@@ -701,19 +686,16 @@ upload_tool = three
|
||||
|
||||
[env:na_ti-ve13]
|
||||
extends = a, b, c
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(str(project_conf))
|
||||
assert config.get("env:na_ti-ve13", "upload_tool") == "three"
|
||||
|
||||
|
||||
def test_invalid_env_names(tmp_path: Path):
|
||||
project_conf = tmp_path / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[env:app:1]
|
||||
"""
|
||||
)
|
||||
""")
|
||||
config = ProjectConfig(str(project_conf))
|
||||
with pytest.raises(InvalidEnvNameError, match=r".*Invalid environment name 'app:1"):
|
||||
config.validate()
|
||||
@@ -721,13 +703,11 @@ def test_invalid_env_names(tmp_path: Path):
|
||||
|
||||
def test_linting_errors(tmp_path: Path):
|
||||
project_conf = tmp_path / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[env:app1]
|
||||
lib_use = 1
|
||||
broken_line
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = ProjectConfig.lint(str(project_conf))
|
||||
assert not result["warnings"]
|
||||
assert result["errors"] and len(result["errors"]) == 1
|
||||
@@ -738,16 +718,14 @@ broken_line
|
||||
|
||||
def test_linting_warnings(tmp_path: Path):
|
||||
project_conf = tmp_path / "platformio.ini"
|
||||
project_conf.write_text(
|
||||
"""
|
||||
project_conf.write_text("""
|
||||
[platformio]
|
||||
build_dir = /tmp/pio-$PROJECT_HASH
|
||||
|
||||
[env:app1]
|
||||
lib_use = 1
|
||||
test_testing_command = /usr/bin/flash-tool -p $UPLOAD_PORT -b $UPLOAD_SPEED
|
||||
"""
|
||||
)
|
||||
""")
|
||||
result = ProjectConfig.lint(str(project_conf))
|
||||
assert not result["errors"]
|
||||
assert result["warnings"] and len(result["warnings"]) == 2
|
||||
|
||||
@@ -18,39 +18,30 @@ from platformio.project.commands.metadata import project_metadata_cmd
|
||||
|
||||
|
||||
def test_metadata_dump(clirunner, validate_cliresult, tmpdir):
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
[env:native]
|
||||
platform = native
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
component_dir = tmpdir.mkdir("lib").mkdir("component")
|
||||
component_dir.join("library.json").write(
|
||||
"""
|
||||
component_dir.join("library.json").write("""
|
||||
{
|
||||
"name": "component",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
"""
|
||||
)
|
||||
component_dir.mkdir("include").join("component.h").write(
|
||||
"""
|
||||
""")
|
||||
component_dir.mkdir("include").join("component.h").write("""
|
||||
#define I_AM_COMPONENT
|
||||
|
||||
void dummy(void);
|
||||
"""
|
||||
)
|
||||
component_dir.mkdir("src").join("component.cpp").write(
|
||||
"""
|
||||
""")
|
||||
component_dir.mkdir("src").join("component.cpp").write("""
|
||||
#include <component.h>
|
||||
|
||||
void dummy(void ) {};
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
tmpdir.mkdir("src").join("main.c").write(
|
||||
"""
|
||||
tmpdir.mkdir("src").join("main.c").write("""
|
||||
#include <component.h>
|
||||
|
||||
#ifndef I_AM_COMPONENT
|
||||
@@ -59,8 +50,7 @@ void dummy(void ) {};
|
||||
|
||||
int main() {
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
metadata_path = tmpdir.join("metadata.json")
|
||||
result = clirunner.invoke(
|
||||
|
||||
Reference in New Issue
Block a user