build: add automated test target

This commit is contained in:
grayTerminal-sh 2026-07-13 13:52:36 +02:00
parent dbd86cf5fc
commit 629212156d
3 changed files with 142 additions and 4 deletions

View file

@ -2,6 +2,8 @@ CC = gcc
PKG_CONFIG = pkg-config PKG_CONFIG = pkg-config
.DEFAULT_GOAL := all
CFLAGS = -std=c17 \ CFLAGS = -std=c17 \
-Wall \ -Wall \
-Wextra \ -Wextra \
@ -12,22 +14,55 @@ CFLAGS = -std=c17 \
LDFLAGS = $(shell $(PKG_CONFIG) --libs gtk4 sqlite3) LDFLAGS = $(shell $(PKG_CONFIG) --libs gtk4 sqlite3)
TEST_CFLAGS = -std=c17 \
-Wall \
-Wextra \
-Werror \
-Iinclude \
$(shell $(PKG_CONFIG) --cflags glib-2.0)
TEST_LDFLAGS = $(shell $(PKG_CONFIG) --libs glib-2.0)
SRC := $(shell find src -name "*.c") SRC := $(shell find src -name "*.c")
OBJ := $(SRC:.c=.o) OBJ := $(SRC:.c=.o)
TARGET = labfy-investigation TARGET = labfy-investigation
TEST_NODE = tests/test_investigation_node
TEST_TREE_MODEL = tests/test_investigation_tree_model
all: $(TARGET)
$(TARGET): $(OBJ) $(TARGET): $(OBJ)
$(CC) $(OBJ) -o $@ $(LDFLAGS) $(CC) $(OBJ) -o $@ $(LDFLAGS)
$(TEST_NODE): \
tests/test_investigation_node.c \
src/core/investigation_node.c
$(CC) $(TEST_CFLAGS) $^ -o $@ $(TEST_LDFLAGS)
$(TEST_TREE_MODEL): \
tests/test_investigation_tree_model.c \
src/core/investigation_node.c \
src/core/investigation_tree_model.c
$(CC) $(TEST_CFLAGS) $^ -o $@ $(TEST_LDFLAGS)
test: $(TEST_NODE) $(TEST_TREE_MODEL)
@echo "Exécution des tests..."
@./$(TEST_NODE)
@./$(TEST_TREE_MODEL)
@echo "Tous les tests sont valides."
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJ) $(TARGET)
run: $(TARGET) run: $(TARGET)
./$(TARGET) ./$(TARGET)
.PHONY: clean run clean:
rm -f $(OBJ) $(TARGET) \
$(TEST_NODE) \
$(TEST_TREE_MODEL)
.PHONY: clean run test

View file

@ -0,0 +1,103 @@
# Ticket #009.5
## Titre
Ajouter une cible `make test`.
---
## Objectif
Automatiser la compilation et l'exécution de l'ensemble des tests du projet.
La commande suivante doit suffire :
```bash
make test
```
---
## Responsabilités
Le système de build doit :
- compiler chaque fichier de test ;
- lier uniquement les modules nécessaires ;
- exécuter tous les tests ;
- arrêter l'exécution si un test échoue ;
- supprimer les binaires de test avec `make clean`.
---
## Hors périmètre
Ce ticket ne doit pas :
- ajouter de nouveaux tests métier ;
- modifier le comportement des modules ;
- introduire un framework de test externe ;
- produire des rapports de couverture ;
- lancer Valgrind automatiquement.
---
## Fichiers concernés
```text
Makefile
```
Éventuellement :
```text
tests/Makefile
```
uniquement si le Makefile principal devient difficile à lire.
---
## Tests concernés
```text
tests/test_investigation_node.c
tests/test_investigation_tree_model.c
```
---
## Comportement attendu
La commande :
```bash
make test
```
doit :
1. compiler les binaires de test ;
2. exécuter chaque test ;
3. afficher clairement le résultat ;
4. retourner un code d'erreur si un test échoue.
---
## Critères d'acceptation
- [ ] `make test` compile tous les tests.
- [ ] `make test` exécute tous les tests.
- [ ] Un test en échec arrête la commande.
- [ ] `make clean` supprime les binaires de test.
- [ ] Aucun binaire de test n'est versionné.
- [ ] Le projet principal continue de compiler.
- [ ] Aucun warning.
---
## Commit attendu
```text
build: add automated test target
```