build: add automated test target
This commit is contained in:
parent
dbd86cf5fc
commit
629212156d
3 changed files with 142 additions and 4 deletions
|
|
@ -2,6 +2,8 @@ CC = gcc
|
|||
|
||||
PKG_CONFIG = pkg-config
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
CFLAGS = -std=c17 \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
|
|
@ -12,22 +14,55 @@ CFLAGS = -std=c17 \
|
|||
|
||||
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")
|
||||
|
||||
OBJ := $(SRC:.c=.o)
|
||||
|
||||
TARGET = labfy-investigation
|
||||
|
||||
TEST_NODE = tests/test_investigation_node
|
||||
TEST_TREE_MODEL = tests/test_investigation_tree_model
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(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
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET)
|
||||
|
||||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
.PHONY: clean run
|
||||
clean:
|
||||
rm -f $(OBJ) $(TARGET) \
|
||||
$(TEST_NODE) \
|
||||
$(TEST_TREE_MODEL)
|
||||
|
||||
.PHONY: clean run test
|
||||
|
|
|
|||
103
labfy-investigation/docs/tickets/closed/TICKET-009.5.md
Normal file
103
labfy-investigation/docs/tickets/closed/TICKET-009.5.md
Normal 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
|
||||
```
|
||||
Binary file not shown.
Loading…
Reference in a new issue