Introduce Black to automate code formatting
This commit is contained in:
+35
-24
@@ -16,27 +16,34 @@ from platformio.commands.run import cli as cmd_run
|
||||
|
||||
|
||||
def test_build_flags(clirunner, validate_cliresult, tmpdir):
|
||||
build_flags = [("-D TEST_INT=13", "-DTEST_INT=13"),
|
||||
("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"),
|
||||
('-DTEST_STR_SPACE="Andrew Smith"',
|
||||
'"-DTEST_STR_SPACE=Andrew Smith"')]
|
||||
build_flags = [
|
||||
("-D TEST_INT=13", "-DTEST_INT=13"),
|
||||
("-DTEST_SINGLE_MACRO", "-DTEST_SINGLE_MACRO"),
|
||||
('-DTEST_STR_SPACE="Andrew Smith"', '"-DTEST_STR_SPACE=Andrew Smith"'),
|
||||
]
|
||||
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
[env:native]
|
||||
platform = native
|
||||
extra_scripts = extra.py
|
||||
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("extra.py").write("""
|
||||
tmpdir.join("extra.py").write(
|
||||
"""
|
||||
Import("projenv")
|
||||
|
||||
projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
tmpdir.mkdir("src").join("main.cpp").write("""
|
||||
tmpdir.mkdir("src").join("main.cpp").write(
|
||||
"""
|
||||
#if !defined(TEST_INT) || TEST_INT != 13
|
||||
#error "TEST_INT"
|
||||
#endif
|
||||
@@ -55,26 +62,28 @@ projenv.Append(CPPDEFINES="POST_SCRIPT_MACRO")
|
||||
|
||||
int main() {
|
||||
}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
build_output = result.output[result.output.find(
|
||||
"Scanning dependencies..."):]
|
||||
build_output = result.output[result.output.find("Scanning dependencies...") :]
|
||||
for flag in build_flags:
|
||||
assert flag[1] in build_output, flag
|
||||
|
||||
|
||||
def test_build_unflags(clirunner, validate_cliresult, tmpdir):
|
||||
tmpdir.join("platformio.ini").write("""
|
||||
tmpdir.join("platformio.ini").write(
|
||||
"""
|
||||
[env:native]
|
||||
platform = native
|
||||
build_unflags = -DTMP_MACRO1=45 -I. -DNON_EXISTING_MACRO -lunknownLib -Os
|
||||
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_MACRO1")
|
||||
@@ -82,22 +91,24 @@ env.Append(CPPDEFINES=["TMP_MACRO2"])
|
||||
env.Append(CPPDEFINES=("TMP_MACRO3", 13))
|
||||
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(
|
||||
"""
|
||||
#ifdef TMP_MACRO1
|
||||
#error "TMP_MACRO1 should be removed"
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
result = clirunner.invoke(cmd_run, ["--project-dir", str(tmpdir), "--verbose"])
|
||||
validate_cliresult(result)
|
||||
build_output = result.output[result.output.find(
|
||||
"Scanning dependencies..."):]
|
||||
build_output = result.output[result.output.find("Scanning dependencies...") :]
|
||||
assert "-DTMP_MACRO1" not in build_output
|
||||
assert "-Os" not in build_output
|
||||
assert str(tmpdir) not in build_output
|
||||
|
||||
Reference in New Issue
Block a user