Création d'un script de test automatique pour le test n°1 + Amélioration du readme.md d'explication
This commit is contained in:
parent
77e954fff0
commit
43dc5102aa
tests/C/test-01-from-nothing
@ -1,12 +1,89 @@
|
||||
# Test 1 : Compilation depuis rien
|
||||
# Test 01 - Compilation à partir de rien
|
||||
|
||||
## Description
|
||||
Ce test vérifie que lorsque les fichiers objets et exécutables sont absents,
|
||||
le programme Bake compile correctement le fichier source `main.c` en `main`.
|
||||
Ce test vérifie le comportement de base de `bake` comparé à `make` lorsqu'on lance une compilation à partir de rien (sans fichiers exécutable préexistants).
|
||||
|
||||
## Fichiers utilisés
|
||||
- `main.c` : Fichier source en C.
|
||||
- `Bakefile` : Contient les règles de compilation.
|
||||
## Sommaire
|
||||
- [Structure du test](#structure-du-test)
|
||||
- [Contenu des fichiers de règles](#contenu-des-fichiers-de-règles)
|
||||
- [Objectif du test](#objectif-du-test)
|
||||
- [Comment exécuter le test](#comment-exécuter-le-test)
|
||||
- [Test automatique](#test-automatique)
|
||||
- [Test manuel](#test-manuel)
|
||||
- [Résultats attendus](#résultats-attendus)
|
||||
|
||||
## Résultat attendu
|
||||
La compilation doit se faire.
|
||||
## Structure du test
|
||||
|
||||
```
|
||||
test-01-from-nothing/
|
||||
├── README.md # Ce fichier
|
||||
├── bake/
|
||||
│ ├── Bakefile # Fichier de règles pour bake
|
||||
│ ├── bakefile.jar # Exécutable de bake (JAR)
|
||||
│ └── main.c # Fichier source C
|
||||
├── make/
|
||||
│ ├── Makefile # Fichier de règles pour make
|
||||
│ └── main.c # Fichier source C
|
||||
└── run_test01.sh # Programme de test automatique
|
||||
```
|
||||
|
||||
## Contenu des fichiers de règles
|
||||
|
||||
Les fichiers `Makefile` et `Bakefile` contiennent les mêmes règles :
|
||||
|
||||
```makefile
|
||||
main: main.c
|
||||
gcc -o main main.c
|
||||
|
||||
clean:
|
||||
rm main
|
||||
```
|
||||
|
||||
## Objectif du test
|
||||
|
||||
Ce test vérifie que `bake` se comporte comme `make` dans le scénario le plus basique:
|
||||
1. Compiler `main.c` en un exécutable `main` quand celui-ci n'existe pas encore
|
||||
2. Vérifier que les sorties sont similaires (commandes exécutées, messages)
|
||||
3. Vérifier que le résultat final (l'exécutable `main`) est bien créé et fonctionnel
|
||||
|
||||
## Comment exécuter le test
|
||||
|
||||
### Test automatique
|
||||
|
||||
1. Rendez le script de test exécutable :
|
||||
```
|
||||
chmod +x run_test01.sh
|
||||
```
|
||||
|
||||
2. Lancez le script de test :
|
||||
```
|
||||
./run_test01.sh
|
||||
```
|
||||
|
||||
3. Consultez les résultats affichés dans le terminal et dans le fichier de log généré dans le répertoire `logs/`.
|
||||
|
||||
### Test manuel
|
||||
|
||||
1. Pour Make :
|
||||
```
|
||||
cd make
|
||||
make
|
||||
```
|
||||
|
||||
2. Pour Bake :
|
||||
```
|
||||
cd bake
|
||||
java -cp bakefile.jar fr.monlouyan.bakefile.Main
|
||||
```
|
||||
|
||||
3. Comparez les deux résultats.
|
||||
|
||||
Attention : N'oubliez pas de supprimer les exécutables générer avant de recommencer le test.
|
||||
|
||||
## Résultats attendus
|
||||
|
||||
- Les deux outils devraient détecter que la cible `main` doit être construite
|
||||
- Les deux outils devraient exécuter la commande `gcc -o main main.c`
|
||||
- Les deux outils devraient produire un exécutable `main` fonctionnel
|
||||
- Les messages de sortie devraient être similaires
|
||||
|
||||
Ce test vérifie la fonctionnalité de base de détection de dépendances et d'exécution de commandes dans un cas simple.
|
83
tests/C/test-01-from-nothing/run_test01.sh
Executable file
83
tests/C/test-01-from-nothing/run_test01.sh
Executable file
@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script de test pour comparer bake et make dans le test n°1 - Compilation à partir de rien
|
||||
|
||||
# Création du répertoire de logs s'il n'existe pas
|
||||
mkdir -p logs
|
||||
|
||||
# Fichier de log avec timestamp pour éviter les écrasements
|
||||
LOG_FILE="logs/test01_$(date +%Y%m%d_%H%M%S).log"
|
||||
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
echo "Test 01 - Compilation à partir de rien" | tee -a "$LOG_FILE"
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
echo "" | tee -a "$LOG_FILE"
|
||||
|
||||
# Nettoyage préalable pour s'assurer qu'on part de zéro
|
||||
echo "Nettoyage préalable..." | tee -a "$LOG_FILE"
|
||||
cd make && make clean &>/dev/null || true
|
||||
cd ../bake && java -cp bakefile.jar fr.monlouyan.bakefile.Main clean &>/dev/null || true
|
||||
cd ..
|
||||
echo "" | tee -a "$LOG_FILE"
|
||||
|
||||
# Test avec make
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
echo "Exécution de MAKE:" | tee -a "$LOG_FILE"
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
cd make
|
||||
echo "$ make" | tee -a "../$LOG_FILE"
|
||||
make 2>&1 | tee -a "../$LOG_FILE"
|
||||
MAKE_EXIT_CODE=$?
|
||||
echo "" | tee -a "../$LOG_FILE"
|
||||
echo "Code de sortie: $MAKE_EXIT_CODE" | tee -a "../$LOG_FILE"
|
||||
|
||||
# Vérification de l'exécutable make
|
||||
if [ -f "main" ]; then
|
||||
echo "Exécutable 'main' créé avec succès par make" | tee -a "../$LOG_FILE"
|
||||
echo "$ ./main" | tee -a "../$LOG_FILE"
|
||||
./main 2>&1 | tee -a "../$LOG_FILE"
|
||||
else
|
||||
echo "ERREUR: Exécutable 'main' non créé par make" | tee -a "../$LOG_FILE"
|
||||
fi
|
||||
echo "" | tee -a "../$LOG_FILE"
|
||||
|
||||
cd ..
|
||||
|
||||
# Test avec bake
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
echo "Exécution de BAKE:" | tee -a "$LOG_FILE"
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
cd bake
|
||||
echo "$ java -cp bakefile.jar fr.monlouyan.bakefile.Main" | tee -a "../$LOG_FILE"
|
||||
java -cp bakefile.jar fr.monlouyan.bakefile.Main 2>&1 | tee -a "../$LOG_FILE"
|
||||
BAKE_EXIT_CODE=$?
|
||||
echo "" | tee -a "../$LOG_FILE"
|
||||
echo "Code de sortie: $BAKE_EXIT_CODE" | tee -a "../$LOG_FILE"
|
||||
|
||||
# Vérification de l'exécutable bake
|
||||
if [ -f "main" ]; then
|
||||
echo "Exécutable 'main' créé avec succès par bake" | tee -a "../$LOG_FILE"
|
||||
echo "$ ./main" | tee -a "../$LOG_FILE"
|
||||
./main 2>&1 | tee -a "../$LOG_FILE"
|
||||
else
|
||||
echo "ERREUR: Exécutable 'main' non créé par bake" | tee -a "../$LOG_FILE"
|
||||
fi
|
||||
echo "" | tee -a "../$LOG_FILE"
|
||||
|
||||
cd ..
|
||||
|
||||
# Résumé des résultats
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
echo "RÉSUMÉ:" | tee -a "$LOG_FILE"
|
||||
echo "=================================" | tee -a "$LOG_FILE"
|
||||
|
||||
if [ $MAKE_EXIT_CODE -eq 0 ] && [ $BAKE_EXIT_CODE -eq 0 ]; then
|
||||
echo "✅ Les deux outils ont réussi la compilation" | tee -a "$LOG_FILE"
|
||||
else
|
||||
echo "❌ Au moins un des outils a échoué" | tee -a "$LOG_FILE"
|
||||
echo " - make: $([ $MAKE_EXIT_CODE -eq 0 ] && echo '✅ Succès' || echo '❌ Échec')" | tee -a "$LOG_FILE"
|
||||
echo " - bake: $([ $BAKE_EXIT_CODE -eq 0 ] && echo '✅ Succès' || echo '❌ Échec')" | tee -a "$LOG_FILE"
|
||||
fi
|
||||
|
||||
echo "" | tee -a "$LOG_FILE"
|
||||
echo "Test terminé. Résultats enregistrés dans: $LOG_FILE" | tee -a "$LOG_FILE"
|
Loading…
x
Reference in New Issue
Block a user