#!/usr/bin/perl -w #On suppose que CVS et Bugzilla sont installés. #On crée un répertoire contenant quelques fichiers à archiver #avec cvs import. Puis on effectue des cvs commit qui modifient #ou non ugzilla. #********************** Partie a modifier **********************# #Cette variable doit contenir un numéro de bug valide de Bugzilla #dont le status peut passer à RESOLVED (i.e. le status initial #doit être NEW, REOPENED ou ASSIGNED). $bug1 = 10; #Cette variable doit contenir un numéro de bug valide de Bugzilla #dont le status ne peut pas passer à RESOLVED. $bug2 = 13; #Cette variable doit contenir un numéro de bug non valide pour #Bugzilla. $bug3 = 5000; #Cette variable doit contenir un numéro de bug valide de Bugzilla #mais dont l'utilisateur n'a pas le droit d'effectuer #des modifications. $bug4 = 14; #***************************************************************# #Variables globales : $file_temp = "install_temp"; $file_temp2 = "install_temp2"; $dir_temp = "travail_temp_005"; #Création d'un répertoire de travail temporaire dont on assure le #suivi des fichiers avec CVS. if (-e "$file_temp"){ die "Please, delete or rename the file $file_temp before running again ". "the verif script"; } if (-e "$dir_temp") { die "Execute this script in a directory which not contains a ". "directory named $dir_temp or delete the ". "$dir_temp directory"; } else { #Création d'un fichier et de 2 répertoires contenant chacun #1 fichier. print "Creation of a temporary test directory...\n"; mkdir "$dir_temp"; system "echo 'int main(){\n\thello();\n}\nint hello {\n\treturn 1;\n}' ". ">> $dir_temp/fichier1.c"; mkdir "$dir_temp/rep1"; system "echo 'int main(){\n\tsalut();\n}\nint salut {\n\treturn 2;\n}' ". ">> $dir_temp/rep1/fichier2.c"; mkdir "$dir_temp/rep2"; system "echo 'int main(){\n\tbonjour();\n}\nint bonjour {\n\treturn 3;\n}'". ">> $dir_temp/rep2/fichier3.c"; } ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '#A temporary directory has been created in order ". "to check\n#if the installation has succeeded. The files of ". "this\n#directory are registered in CVS. ". "So, below there is\n#the result of the import cvs command.\n". "#The sentence \"No conflicts created by this import\"\n". "#should appear if the import has succeeded.' >> $file_temp"; &Lignen(); #Archivage sous CVS des fichiers précédents. $cvsimport = system ("cd $dir_temp;". "cvs import -m 'Enregistrement sous CVS' $dir_temp Recup V0 ". "1>& ./../$file_temp2 >> ./../$file_temp;". "cd ..; rm -r $dir_temp;". "cvs checkout $dir_temp 1>& $file_temp2 >> $file_temp;"); if ($cvsimport != 0) { die "The files can not be recorded with CVS"; } #On effectue des commit avec différents numéro de bug et on regarde le #résultat que l'on compare aux résultats attendus. print "Test 1/5...\n"; #1ER CAS : Modification d'un bug valide dont le status peut passer au status #RESOLVED et dont l'utilisateur peut modifier le status. ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '#Test 1\n#Test of the modification of CVS and Bugzilla.\n". "#Below, you should see CVS information ". "between the sentences :\n#\"Execution of the commit command...\"". "\n#and \"The transaction has finished successfully!\"' ". ">> $file_temp"; &Lignen(); &ModificationFiles(); &Commit($bug1); ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '#You can check the status of the bug#$bug1 ". "in Bugzilla.\n#It should be RESOLVED and the resolution ". "should be FIXED.\n#You should also have received an email ". "that indicates you\n#the changes of status for the bug#$bug1.'". ">> $file_temp\n"; #On vérifie que tous les fichiers sont à jour #avec la commande CVS status. system "echo '#\n#You can check below the status in CVS of the three\n#". "files fichier1.c, fichier2.c and fichier3.c. They should\n#". "be at the status Up-to-date.'>> $file_temp"; &Lignen(); $cvsstatus = system ("cd $dir_temp;". "cvs status fichier1.c | grep File: >> ../$file_temp;". "cvs status rep1/fichier2.c | grep File: >> ../$file_temp;". "cvs status rep2/fichier3.c | grep File: >> ../$file_temp;"); if ($cvsstatus != 0) { die "The cvs commande cvs status does not work or the directory ". "$dir_temp is unreachable"; } print "Test 2/5...\n"; #2IEME CAS : Modification d'un bug valide dont le status ne peut pas passer #au status RESOLVED. ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '#Test 2\n#Now, the modification of an existing Bugzilla bug,\n#". "but that can not pass to the RESOLVED status, is attempted.\n#". "The following message should appear :\n#". "The bug#$bug2 can not be set to the RESOLVED status as it is now\n#". "at the NO_VALID_STATUS status. The commit command is canceled.'". ">> $file_temp"; &Lignen(); &ModificationFiles(); &Commit($bug2); print "Test 3/5...\n"; #3IEME CAS : Modification d'un bug non valide de Bugzilla. ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '#Test 3\n#Then, the modification of an non existing Bugzilla bug ". "is attempted.\n#The following message should appear :\n#". "This bug number $bug3 does not exist for Bugzilla\n#". "The commit command is canceled' >> $file_temp"; &Lignen(); &ModificationFiles(); &Commit($bug3); print "Test 4/5...\n"; #4IEME CAS : Modification d'un bug valide dont le status peut passer au status #RESOLVED et dont l'utilisateur n'est pas autorisé à modifier le status. ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '#Test 4\n#Then, the modification of an existing Bugzilla bug, that\n#". "can be changed to RESOLVED, but which the user do not have the\n#". "right to access is attempted.\n#The following message should appear :\n#". "You are not allowed to modify the status of this bug number $bug4\n#". "The commit command is canceled' >> $file_temp"; &Lignen(); &ModificationFiles(); &Commit($bug4); print "Test 5/5...\n"; #5IEME CAS : Archivage sans modification de Bugzilla : ### Ajout de commentaires dans le fichier de vérification &Ligne(); system "echo '##Test 5\nFinally, the files are registered in CVS whithout ". "trying to modify\n#Bugzilla. You should see the usual CVS ". "information message.'>> $file_temp"; &Lignen(); &ModificationFiles(); &Commit("coucou"); #On vérifie que les informations dans le fichier de sortie #sont bien celles attendues. unless (open(MESSAGE, "$file_temp")) { print "Sorry, it is impossible to execute the commit command". "as the file $file_temp is not readable"; exit(1); } $error = 21; while ($ligne = ){ if (!($ligne =~ /^\#/)){ if ($ligne =~ /^No conflicts created by this import/){ $error--; $test0 = 1; } if ($ligne =~ /^Execution of the commit command.../){ $error--; $test1 = 1; } if ($ligne =~ /^The transaction has finished successfully!/){ $error--; $test11 = 1; } if ($ligne =~ /^File: fichier1.c Status: Up-to-date/){ $error--; $test12 = 1; } if ($ligne =~ /^File: fichier2.c Status: Up-to-date/){ $error--; $test13 = 1; } if ($ligne =~ /^File: fichier3.c Status: Up-to-date/){ $error--; $test14 = 1; } if ($ligne =~ /^The bug\#\d+ can\'t be set to the RESOLVED status as it is now at the /){ $error--; $test2 = 1; } if ($ligne =~ /^This bug number \d+ does not exist for Bugzilla/){ $error--; $test3 = 1; } if ($ligne =~ /^You are not allowed to modify the status of this bug number /){ $error--; $test4 = 1; } if ($ligne =~ /^Checking in fichier1.c;/){ $error--; $test5 = 1; } if ($ligne =~ /^done/){ $error--; $test51 = 1; } if ($ligne =~ /^Checking in rep1\/fichier2.c;/){ $error--; $test52 = 1; } if ($ligne =~ /^Checking in rep2\/fichier3.c;/){ $error--; $test53 = 1; } } } $texterreur0 = ""; $texterreur1 = ""; $texterreur2 = ""; $texterreur3 = ""; $texterreur4 = ""; $texterreur5 = ""; if ($error != 0){ if (!$test0) { $texterreur0 = "The cvs import command has failed.\n"; } if ((!$test1)||(!$test11)||(!$test12)||(!$test13)||(!$test14)) { $texterreur1 = "The verification failed during the test 1.\n"; } if (!$test2) { $texterreur2 = "The verification failed during the test 2.\n"; } if (!$test3) { $texterreur3 = "The verification failed during the test 3.\n"; } if (!$test4) { $texterreur4 = "The verification failed during the test 4.\n"; } if ((!$test5)||(!$test51)||(!$test52)||(!$test53)) { $texterreur5 = "The verification failed during the test 5.\n"; } print "\n".$texterreur0."".$texterreur1."".$texterreur2."" .$texterreur3."".$texterreur4."".$texterreur5."Please,". " look at the file $file_temp to have more information.\n"; } else { print "\nThe verification ended successfully!\nYou can chek if ". "you want the details of the tests in the file $file_temp.\n"; } #Nettoyage system "rm -r $dir_temp"; system "rm $file_temp2"; ################ some functions sub ModificationFiles { #Modification des 3 fichiers system "echo ' ' >> $dir_temp/fichier1.c;". "echo ' ' >> $dir_temp/rep1/fichier2.c;". "echo ' ' >> $dir_temp/rep2/fichier3.c"; } sub Commit { my($bug_id) = @_; system ("cd $dir_temp;". "cvs commit -m 'Correction du #!:,;BUG \t$bug_id' 1>&". "./../$file_temp2 >>./../$file_temp;"); } sub Ligne { system "echo '\n#####################################################". "##############' >> $file_temp"; } sub Lignen { system "echo '######################################################". "#############\n' >> $file_temp"; }