11/*
2- * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2016-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
1111#include <stdio.h>
1212#include "unity.h"
1313#include "esp_system.h"
14+ #include "sdkconfig.h"
1415
1516/* similar to UNITY_PRINT_EOL */
1617#define UNITY_PRINT_TAB () UNITY_OUTPUT_CHAR('\t')
@@ -24,11 +25,37 @@ void unity_testcase_register(test_desc_t *desc)
2425 if (!s_unity_tests_first ) {
2526 s_unity_tests_first = desc ;
2627 s_unity_tests_last = desc ;
27- } else {
28- test_desc_t * temp = s_unity_tests_first ;
29- s_unity_tests_first = desc ;
30- s_unity_tests_first -> next = temp ;
28+ return ;
3129 }
30+ #if CONFIG_UNITY_TEST_ORDER_BY_FILE_PATH_AND_LINE
31+ test_desc_t * prev = NULL ;
32+ test_desc_t * current = s_unity_tests_first ;
33+
34+ while (current ) {
35+ int file_cmp = strcmp (desc -> file , current -> file );
36+ if (file_cmp < 0 || (file_cmp == 0 && desc -> line < current -> line )) {
37+ // Insert before current
38+ if (prev ) {
39+ prev -> next = desc ;
40+ } else {
41+ // Inserting at the head
42+ s_unity_tests_first = desc ;
43+ }
44+ desc -> next = current ;
45+ return ;
46+ }
47+ prev = current ;
48+ current = current -> next ;
49+ }
50+
51+ // Insert at the end
52+ prev -> next = desc ;
53+ s_unity_tests_last = desc ;
54+ #else
55+ // Insert at head (original behavior)
56+ desc -> next = s_unity_tests_first ;
57+ s_unity_tests_first = desc ;
58+ #endif
3259}
3360
3461/* print the multiple function case name and its sub-menu
0 commit comments