summaryrefslogtreecommitdiffstats
path: root/docs/2_The_test_widget.md
blob: afd4c6d89bdb12821acfef7f1146138552f8d1d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# How to build the test widget using app-templates/cmake-apps-module

## Defining CMake targets

Now that the test tree has been created, in each directory you have to create
a `CMakeLists.txt` file to hold the CMake's target definition. For each target
you need to specify a **LABELS** depending on the purpose of the files for each
directory. There are more explanations about using the *cmake-apps-module* (the
former *app-templates* submodule) in the [documentation website](2_4-Use-app-templates.html#using-cmake-template-macros).

Here is a cheat sheet to map the **LABELS** target for each classic test tree
directory:

* `etc` uses the label **TEST-CONFIG**
* `fixtures` uses the label **TEST-DATA**
* `tests` uses the label **TEST-DATA**

i.e the `etc` folder:

```cmake
PROJECT_TARGET_ADD(test-config)

    file(GLOB CONF_FILES "*.json")

    add_input_files("${CONF_FILES}")

    SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
        LABELS "TEST-CONFIG"
        OUTPUT_NAME ${TARGET_NAME}
    )
```

i.e the `fixtures` folder:

```cmake
PROJECT_TARGET_ADD(test-fixtures)

    # Change the glob pattern to match your file's type
    file(GLOB DATA_FILES "*.sh" "*.data")

    add_input_files("${DATA_FILES}")

    SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
        LABELS "TEST-DATA"
        OUTPUT_NAME ${TARGET_NAME}
    )
```

i.e the `tests` folder:


```cmake
PROJECT_TARGET_ADD(tests)

    file(GLOB CONF_FILES "*.lua")

    add_input_files("${CONF_FILES}")

    SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
        LABELS "TEST-DATA"
        OUTPUT_NAME ${TARGET_NAME}
    )
```

> **CAUTION**: make sure that you have CMakeLists files that include your
> subdirectories target (cf: previous chapter `Write the tests`).

## Build the test widget

By default, the test widget is not built, you have to specify that you want to
build it or use a special target.

### Building at the same time than classic widget

Specify the option `BUILD_TEST_WGT=TRUE` when you configure your build.

ie:

```bash
cd build
cmake -DBUILD_TEST_WIDGET=TRUE ..
make
make widget
```

### Building separately only the test widget

Just use the target `test_widget` after a classic build.

ie:

```bash
cd build
cmake ..
make
make test_widget
```