diff --git a/build.sh b/build.sh index de1e3768..380289bc 100755 --- a/build.sh +++ b/build.sh @@ -56,7 +56,7 @@ EOF # get a list of pio env names that start with "env:" get_pio_envs() { - pio project config | grep 'env:' | sed 's/env://' + pio project config | grep '^env:' | sed 's/env://' } # Catch cries for help before doing anything else. diff --git a/scripts/tests/test_build_sh_envs.py b/scripts/tests/test_build_sh_envs.py new file mode 100644 index 00000000..869ddc0e --- /dev/null +++ b/scripts/tests/test_build_sh_envs.py @@ -0,0 +1,39 @@ +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +class BuildShEnvListTest(unittest.TestCase): + def test_list_excludes_extends_option_lines(self): + script = Path(__file__).resolve().parents[2] / "build.sh" + with tempfile.TemporaryDirectory(prefix="meshcore-build-") as directory: + # `pio project config` prints one option line per setting, so an env + # that extends another also yields a line holding "env:" — which + # is not an environment, however much it looks like one. + Path(directory, "pio").write_text( + "#!/bin/sh\n" + "cat <<'EOF'\n" + "env:Heltec_v3_repeater\n" + "----------------------\n" + "build_flags = -D ESP32_PLATFORM\n" + "\n" + "env:Heltec_v3_repeater_observer\n" + "-------------------------------\n" + "extends = env:Heltec_v3_repeater\n" + "build_flags = -D ESP32_PLATFORM\n" + "EOF\n" + ) + os.chmod(Path(directory, "pio"), 0o755) + result = subprocess.run( + ["bash", str(script), "list"], + env={**os.environ, "PATH": directory + os.pathsep + os.environ["PATH"]}, + check=True, capture_output=True, text=True, + ) + self.assertEqual(result.stdout.splitlines(), + ["Heltec_v3_repeater", "Heltec_v3_repeater_observer"]) + + +if __name__ == "__main__": + unittest.main()