diff --git a/tests/C/test-05-variables/run_test05.sh b/tests/C/test-05-variables/run_test05.sh new file mode 100755 index 0000000..b390a0e --- /dev/null +++ b/tests/C/test-05-variables/run_test05.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +# Script de test pour comparer bake et make +# Test 05 - Utilisation des variables + +# 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/test05_$(date +%Y%m%d_%H%M%S).log" + +echo "=================================" | tee -a "$LOG_FILE" +echo "Test 05 - Utilisation des variables" | 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" +# Pour make, supprimer l'exécutable s'il existe +cd make +rm -f main 2>/dev/null +cd .. + +# Pour bake, supprimer l'exécutable s'il existe +cd bake +rm -f main 2>/dev/null +cd .. +echo "Nettoyage terminé." | tee -a "$LOG_FILE" +echo "" | tee -a "$LOG_FILE" + +# Test avec make +echo "=================================" | tee -a "$LOG_FILE" +echo "Exécution de MAKE avec variables:" | 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érifier si l'exécutable a été créé +if [ -f "main" ]; then + echo "✅ make: L'exécutable 'main' a été généré avec succès" | tee -a "../$LOG_FILE" + + # Vérifier que l'exécutable fonctionne + if [ -x "main" ]; then + echo "$ ./main" | tee -a "../$LOG_FILE" + ./main 2>&1 | tee -a "../$LOG_FILE" + fi +else + echo "❌ make: L'exécutable 'main' n'a pas été généré" | tee -a "../$LOG_FILE" +fi +cd .. + +echo "" | tee -a "$LOG_FILE" + +# Test avec bake +echo "=================================" | tee -a "$LOG_FILE" +echo "Exécution de BAKE avec variables:" | 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érifier si l'exécutable a été créé +if [ -f "main" ]; then + echo "✅ bake: L'exécutable 'main' a été généré avec succès" | tee -a "../$LOG_FILE" + + # Vérifier que l'exécutable fonctionne + if [ -x "main" ]; then + echo "$ ./main" | tee -a "../$LOG_FILE" + ./main 2>&1 | tee -a "../$LOG_FILE" + fi +else + echo "❌ bake: L'exécutable 'main' n'a pas été généré" | tee -a "../$LOG_FILE" +fi +cd .. + +# Résumé des résultats +echo "" | tee -a "$LOG_FILE" +echo "=================================" | tee -a "$LOG_FILE" +echo "RÉSUMÉ:" | tee -a "$LOG_FILE" +echo "=================================" | tee -a "$LOG_FILE" + +cd make +MAKE_SUCCESS=$([ -f "main" ] && echo "true" || echo "false") +cd ../bake +BAKE_SUCCESS=$([ -f "main" ] && echo "true" || echo "false") +cd .. + +if [ "$MAKE_SUCCESS" = "true" ] && [ "$BAKE_SUCCESS" = "true" ]; then + echo "✅ Les deux outils ont correctement géré les variables et généré l'exécutable" | tee -a "$LOG_FILE" +elif [ "$MAKE_SUCCESS" = "false" ] && [ "$BAKE_SUCCESS" = "false" ]; then + echo "❌ Les deux outils ont échoué à gérer les variables et à générer l'exécutable" | tee -a "$LOG_FILE" +else + echo "⚠️ Comportement différent entre make et bake:" | tee -a "$LOG_FILE" + echo " - make: $([ "$MAKE_SUCCESS" = "true" ] && echo '✅ A réussi' || echo '❌ A échoué')" | tee -a "$LOG_FILE" + echo " - bake: $([ "$BAKE_SUCCESS" = "true" ] && echo '✅ A réussi' || echo '❌ A échoué')" | tee -a "$LOG_FILE" +fi + +# Vérification supplémentaire - comparaison des exécutables +if [ "$MAKE_SUCCESS" = "true" ] && [ "$BAKE_SUCCESS" = "true" ]; then + # Comparaison de la taille des exécutables + MAKE_SIZE=$(ls -l make/main | awk '{print $5}') + BAKE_SIZE=$(ls -l bake/main | awk '{print $5}') + + echo "" | tee -a "$LOG_FILE" + echo "Comparaison des exécutables produits:" | tee -a "$LOG_FILE" + echo " - Taille de l'exécutable make: $MAKE_SIZE octets" | tee -a "$LOG_FILE" + echo " - Taille de l'exécutable bake: $BAKE_SIZE octets" | tee -a "$LOG_FILE" + + # Vérifier si les tailles sont similaires (à 10% près) + DIFFERENCE=$(( (MAKE_SIZE > BAKE_SIZE) ? (MAKE_SIZE - BAKE_SIZE) : (BAKE_SIZE - MAKE_SIZE) )) + PERCENTAGE=$(( (DIFFERENCE * 100) / ((MAKE_SIZE + BAKE_SIZE) / 2) )) + + if [ "$PERCENTAGE" -lt 10 ]; then + echo "✅ Les exécutables produits ont des tailles similaires ou égal (différence < 10%)" | tee -a "$LOG_FILE" + else + echo "⚠️ Les exécutables produits ont des tailles significativement différentes (différence > 10%)" | tee -a "$LOG_FILE" + fi +fi + +echo "" | tee -a "$LOG_FILE" +echo "Test terminé. Résultats enregistrés dans: $LOG_FILE" | tee -a "$LOG_FILE" \ No newline at end of file