1- # SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
1+ # SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
22# SPDX-License-Identifier: Apache-2.0
33import logging
44import os
1212
1313import pytest
1414from test_build_system_helpers import APP_BINS
15- from test_build_system_helpers import append_to_file
1615from test_build_system_helpers import BOOTLOADER_BINS
16+ from test_build_system_helpers import PARTITION_BIN
17+ from test_build_system_helpers import IdfPyFunc
18+ from test_build_system_helpers import append_to_file
1719from test_build_system_helpers import file_contains
1820from test_build_system_helpers import get_idf_build_env
19- from test_build_system_helpers import IdfPyFunc
20- from test_build_system_helpers import PARTITION_BIN
2121from test_build_system_helpers import replace_in_file
2222from test_build_system_helpers import run_cmake_and_build
2323
@@ -35,7 +35,9 @@ def test_build_alternative_directories(idf_py: IdfPyFunc, func_work_dir: Path, t
3535 assert os .listdir (alt_build_dir ) != [], 'No files found in new build directory!'
3636 default_build_dir = test_app_copy / 'build'
3737 if default_build_dir .exists ():
38- assert os .listdir (default_build_dir ) == [], f'Some files were incorrectly put into the default build directory: { default_build_dir } '
38+ assert os .listdir (default_build_dir ) == [], (
39+ f'Some files were incorrectly put into the default build directory: { default_build_dir } '
40+ )
3941 except Exception :
4042 raise
4143 else :
@@ -146,10 +148,17 @@ def test_build_with_sdkconfig_build_abspath(idf_py: IdfPyFunc, test_app_copy: Pa
146148
147149def test_build_fail_on_build_time (idf_py : IdfPyFunc , test_app_copy : Path ) -> None :
148150 logging .info ('Fail on build time works' )
149- append_to_file (test_app_copy / 'CMakeLists.txt' , '\n ' .join (['' ,
150- 'if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/hello.txt")' ,
151- 'fail_at_build_time(test_file "hello.txt does not exists")' ,
152- 'endif()' ]))
151+ append_to_file (
152+ test_app_copy / 'CMakeLists.txt' ,
153+ '\n ' .join (
154+ [
155+ '' ,
156+ 'if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/hello.txt")' ,
157+ 'fail_at_build_time(test_file "hello.txt does not exists")' ,
158+ 'endif()' ,
159+ ]
160+ ),
161+ )
153162 ret = idf_py ('build' , check = False )
154163 assert ret .returncode != 0 , 'Build should fail if requirements are not satisfied'
155164 (test_app_copy / 'hello.txt' ).touch ()
@@ -160,10 +169,14 @@ def test_build_fail_on_build_time(idf_py: IdfPyFunc, test_app_copy: Path) -> Non
160169def test_build_dfu (idf_py : IdfPyFunc ) -> None :
161170 logging .info ('DFU build works' )
162171 ret = idf_py ('dfu' , check = False )
163- assert 'command "dfu" is not known to idf.py and is not a Ninja target' in ret .stderr , 'DFU build should fail for default chip target'
172+ assert 'command "dfu" is not known to idf.py and is not a Ninja target' in ret .stderr , (
173+ 'DFU build should fail for default chip target'
174+ )
164175 idf_py ('set-target' , 'esp32s2' )
165176 ret = idf_py ('dfu' )
166- assert 'build/dfu.bin" has been written. You may proceed with DFU flashing.' in ret .stdout , 'DFU build should succeed for esp32s2'
177+ assert 'build/dfu.bin" has been written. You may proceed with DFU flashing.' in ret .stdout , (
178+ 'DFU build should succeed for esp32s2'
179+ )
167180 assert_built (BOOTLOADER_BINS + APP_BINS + PARTITION_BIN + ['build/dfu.bin' ])
168181
169182
@@ -174,23 +187,35 @@ def test_build_uf2(idf_py: IdfPyFunc) -> None:
174187 assert 'build/uf2.bin, ready to be flashed with any ESP USB Bridge' in ret .stdout , 'UF2 build should work for esp32'
175188 assert_built (BOOTLOADER_BINS + APP_BINS + PARTITION_BIN + ['build/uf2.bin' ])
176189 ret = idf_py ('uf2-app' )
177- assert 'build/uf2-app.bin, ready to be flashed with any ESP USB Bridge' in ret .stdout , 'UF2 build should work for application binary'
190+ assert 'build/uf2-app.bin, ready to be flashed with any ESP USB Bridge' in ret .stdout , (
191+ 'UF2 build should work for application binary'
192+ )
178193 assert_built (['build/uf2-app.bin' ])
179194 idf_py ('set-target' , 'esp32s2' )
180195 ret = idf_py ('uf2' )
181- assert 'build/uf2.bin, ready to be flashed with any ESP USB Bridge' in ret .stdout , 'UF2 build should work for esp32s2'
196+ assert 'build/uf2.bin, ready to be flashed with any ESP USB Bridge' in ret .stdout , (
197+ 'UF2 build should work for esp32s2'
198+ )
182199 assert_built (BOOTLOADER_BINS + APP_BINS + PARTITION_BIN + ['build/uf2.bin' ])
183200
184201
185202def test_build_loadable_elf (idf_py : IdfPyFunc , test_app_copy : Path ) -> None :
186203 logging .info ('Loadable ELF build works' )
187- (test_app_copy / 'sdkconfig' ).write_text ('\n ' .join (['CONFIG_APP_BUILD_TYPE_RAM=y' ,
188- 'CONFIG_VFS_SUPPORT_TERMIOS=n' ,
189- 'CONFIG_NEWLIB_NANO_FORMAT=y' ,
190- 'CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y' ,
191- 'CONFIG_ESP_ERR_TO_NAME_LOOKUP=n' ]))
204+ (test_app_copy / 'sdkconfig' ).write_text (
205+ '\n ' .join (
206+ [
207+ 'CONFIG_APP_BUILD_TYPE_RAM=y' ,
208+ 'CONFIG_VFS_SUPPORT_TERMIOS=n' ,
209+ 'CONFIG_NEWLIB_NANO_FORMAT=y' ,
210+ 'CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y' ,
211+ 'CONFIG_ESP_ERR_TO_NAME_LOOKUP=n' ,
212+ ]
213+ )
214+ )
192215 idf_py ('reconfigure' )
193- assert (test_app_copy / 'build' / 'flasher_args.json' ).exists (), 'flasher_args.json should be generated in a loadable ELF build'
216+ assert (test_app_copy / 'build' / 'flasher_args.json' ).exists (), (
217+ 'flasher_args.json should be generated in a loadable ELF build'
218+ )
194219 idf_py ('build' )
195220
196221
@@ -221,3 +246,15 @@ def test_build_cmake_executable_suffix(idf_py: IdfPyFunc, test_app_copy: Path) -
221246 append_to_file ((test_app_copy / 'CMakeLists.txt' ), 'set(CMAKE_EXECUTABLE_SUFFIX_CXX ".ext")' )
222247 ret = idf_py ('build' )
223248 assert 'Project build complete' in ret .stdout , 'Build with CMAKE_EXECUTABLE_SUFFIX set failed'
249+
250+
251+ def test_build_with_misspelled_kconfig (idf_py : IdfPyFunc , test_app_copy : Path ) -> None :
252+ logging .info ('idf.py can build with misspelled Kconfig file' )
253+ ret = idf_py ('build' )
254+ assert " file should be named 'Kconfig.projbuild'" in ret .stderr , 'Misspelled Kconfig file should be detected'
255+ assert_built (BOOTLOADER_BINS + APP_BINS + PARTITION_BIN )
256+ with open (test_app_copy / 'sdkconfig' , 'r' ) as f :
257+ sdkconfig = f .read ()
258+ assert 'CONFIG_FROM_MISSPELLED_KCONFIG=y' in sdkconfig , (
259+ 'There should be a config from the misspelled Kconfig file in sdkconfig'
260+ )
0 commit comments