1 // Copyright 2016-2021 Espressif Systems (Shanghai) Co. Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 /* IDF-specific additions to "Unity Fixture".
16  * This file doesn't need to be included directly, it gets included into unity.h
17  * through unity_config.h.
18  */
19 
20 #pragma once
21 
22 #include "sdkconfig.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #if !defined(CONFIG_IDF_TARGET) || defined(CONFIG_IDF_TARGET_LINUX)
29 #define UNITY_MAYBE_EXIT(rc)  do { exit(rc); } while(0)
30 #else
31 #define UNITY_MAYBE_EXIT(rc)  do { (void) rc; } while(0)
32 #endif
33 
34 /* A shorthand for running all tests called from one function "func_", from the app_main function.
35  * Use this when there is more than one test group.
36  *
37  * Example:
38  *
39  *    #include "unity.h"
40  *    #include "unity_fixture.h"
41  *
42  *    static_void run_all_tests(void) {
43  *        RUN_TEST_GROUP(group1);   // test group defined in another file, e.g. test_group1.c
44  *        RUN_TEST_GROUP(group2);   // test group defined in another file, e.g. test_group2.c
45  *    }
46  *
47  *    void app_main(void) {
48  *        UNITY_MAIN_FUNC(run_all_tests);
49  *    }
50  */
51 #define UNITY_MAIN_FUNC(func_) do { \
52     const char* argv[] = { "test", "-v" }; \
53     const int argc = sizeof(argv)/sizeof(argv[0]); \
54     int rc = UnityMain(argc, argv, func_); \
55     printf("\nTests finished, rc=%d\n", rc); \
56     UNITY_MAYBE_EXIT(rc); \
57 } while(0)
58 
59 /* A shorthand for running one test group from the app_main function, when there is only
60  * one test group and it is defined in the same file.
61  *
62  * Example:
63  *
64  *    #include "unity.h"
65  *    #include "unity_fixture.h"
66  *
67  *    TEST_GROUP(my_feature);
68  *    // also define TEST_SETUP, TEST_TEARDOWN, TESTs, TEST_GROUP_RUNNER
69  *
70  *    void app_main(void) {
71  *        UNITY_MAIN(my_feature);
72  *    }
73  */
74 #define UNITY_MAIN(group_) UNITY_MAIN_FUNC(TEST_ ## group_ ## _GROUP_RUNNER)
75 
76 #ifdef __cplusplus
77 }
78 #endif
79