# Tests

### Compiling the library and the unit tests

It's crucial to compile your code regularly while you're writing code. It'll uncover problems that your IDE doesn't know about.

#### Running CMake

The first step to compiling is running CMake. CMake will generate the Makefiles that are used to build the project.
Usually, you only have to do this once, the very first time, and afterwards every time you add a new implementation (.cpp) file.

It's easiest to run this in the command line. In Visual Studio Code, go to the "Terminal" menu, and select "New Terminal".
The working directory of the terminal should be Control-Surface/build.

cmake ..

#### Compiling in Visual Studio Code

To compile the Control Surface library and its unit tests, you can use the CTRL+SHIFT+B shortcut (build).
Alternatively, you can press CTRL+P, type "task", space, and then "Make All".

#### Compiling using a terminal

If you're not using VSCode, you can compile everything from a terminal.
Simply navigate to the Control-Surface/build directory, and invoke GNU Make.
You can speed up the compilation by compiling multiple files in parallel using the -j option. nproc returns the number of CPUs available on your machine.

make -jnproc

#### Running the tests in Visual Studio Code

To run the tests, press CTRL+Shift+P, type "Tasks: Run Test Task". There should be three options.

• Make Check: builds any files that were modified, runs the tests, and prints the output to the console.
• Make Test: equivalent to Make Check, but it only prints the test results to the console, not the output (print statements) of the tests.
• Make & Test & Build examples: the same as Make Test, and after running the tests, it also compiles all Arduino examples. This can take a significant amount of time.

Before committing, Make & Test & Build examples has to pass.

#### Running the tests using a terminal

Open a terminal in the Control-Surface/build directory, build the library and tests, and run them:

make -jnproc
make test
make check

To compile all arduino examples, open a terminal in the Control-Surface/scripts directory, and run:

./build-arduino.sh nproc