*(all paths and filenames mentioned in this section are relative to the `ext_tester` directory)*
Tests are by expanding the code of the utility directly, using a provded API. The recommended way to do that is to declare and define a test-running function (i.e. a function that uses the API to run specific tests) in a my_test.h/c pair of files in the `executions` subdirectory, and then add a call to your function in the main function, located in `main.c`.
Don't heasitate to refer to the existing tests provided for a good example.
Before you go anywhere, your test file should include `../execution.h`
The core function of the test-running API is the `execute_test()` function. This function runs `mojitos` in parallel and takes a pointer to an `Execution` object that will define what is done with this run.
```C
typedef struct {
char *const *args;
Tester *testers;
int nb_testers;
void *context;
} Execution;
```
-*args* points to a string array, which is the arguments that will be passed to `mojitos`.
-*testers* is an array of *nb_testers*`Tester` objects. Each of these objects defines a test performed during the run.
-*context* is an arbitrary pointer that will be passed to the testing functions.
The Tester object is defined as follows :
```C
typedef struct {
TesterInit init;
TesterReader read;
TesterFinalizer finalize;
void *state;
const char *name;
} Tester;
```
-*init*, *read* and *finalize* are pointers to function that will be called at various stages of the run. See below.
-*state* is an arbitrary pointer that may be initialized (to possibly allocated memory) by the *init* function.
-*name* is a string that will be used in the output of the program.
- The *TesterInit* function of a Tester is called once before `mojitos` is ran. It is given a pointer pointer to the state pointer, that will then be passed directly to the two other functions. Use this to allocate memory for a state-sotring structure.
- The *TesterReader* function of a Tester is called everytime `mojitos` outputs something. It is given a pointer to the null-terminated string that was read on mojitos output.
- The *TesterFinalizer* function of a Tester is called once `mojitos` exits, and should return a non-zero value if the test failed (incorrect mojitos output), or 0 otherwise. /!\ If this test uses a state object, it must be freed here !
Notice how every function is also give a \**context* pointer. This pointer is the context property of the current Execution.