Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[tesh] Write self-tests in perl (we may not have cc at hand)
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 30 Sep 2015 16:26:44 +0000 (18:26 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 30 Sep 2015 16:51:47 +0000 (18:51 +0200)
Also, revive the setenv test and make it work (the forked environment
was not modified but only the command line rewriting mechanism)

tools/cmake/AddTests.cmake
tools/tesh/background.tesh
tools/tesh/bg-set-signal.tesh
tools/tesh/catch-return.tesh
tools/tesh/catch-signal.tesh
tools/tesh/set-return.tesh
tools/tesh/setenv.tesh
tools/tesh/tesh.pl

index f978abd..ef53354 100644 (file)
@@ -67,6 +67,7 @@ IF(NOT enable_memcheck)
   ### TESH ###
   ADD_TESH(tesh-self-basic                       --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/basic.tesh)
   ADD_TESH(tesh-self-cd                          --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/cd.tesh)
+  ADD_TESH(tesh-self-setenv                      --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/setenv.tesh)
   ADD_TESH(tesh-self-IO-broken-pipe              --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/IO-broken-pipe.tesh)
   ADD_TESH(tesh-self-IO-orders                   --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/IO-orders.tesh)
   ADD_TESH(tesh-self-IO-bigsize                  --cd "${CMAKE_BINARY_DIR}/bin" ${CMAKE_HOME_DIRECTORY}/tools/tesh/IO-bigsize.tesh)
index 1029d89..8b177fe 100644 (file)
@@ -3,49 +3,18 @@ $ rm -rf temp_testdir_background
 $ mkdir temp_testdir_background
 $ cd temp_testdir_background
 
-< #include <unistd.h>
-< #include <stdlib.h>
-< #include <stdio.h>
-< #include <sys/types.h>
-< #include <sys/stat.h>
-< #include <fcntl.h>
-< #ifdef WIN32 
-<   #include "windows.h"
-< #endif
-<                   
-< int main() {
-<   char buff[2048];
-<   int got;
-<   int in;
+< use strict; 
+< sleep(2);
+< open (FILE, "<tmp_fich") || die "Cannot open tmp_fich: $!\n";
 < 
-< #ifndef WIN32 
-<   sleep(1);
-< #else
-<   Sleep(1000);
-< #endif
-<   in = open("tmp_fich",O_RDONLY|O_CREAT);
-<   if (in == -1) {
-<     perror("Cannot open tmp_fich: ");
-<     exit(1);
-<   }
-<   while ((got = read(in,&buff,2048))>0) {
-<      int w = write(1,&buff,got);
-<      if (w<0) {
-<        perror("Error while writing:");
-<        exit(1);
-<      }
-<   }
-<   if (got < 0) {
-<     perror("Error while reading:");
-<     exit(1);
-<   }
-<   return 0;
+< while (<FILE>) {
+<   print;
 < }
-$ mkfile delayed_cat.c
+< exit 0;
+<
+$ mkfile delayed_cat.pl
 
-$ cc -Wall -o delayed_cat delayed_cat.c
-
-& ./delayed_cat
+& perl delayed_cat.pl
 > TOTO
 
 < TOTO
index ff9c3d5..172435d 100644 (file)
@@ -5,17 +5,12 @@
 $ rm -rf temp_testdir-bg-set-signal
 $ mkdir temp_testdir-bg-set-signal
 
-$ cd temp_testdir-bg-set-signal
-< #include <stdlib.h>
-< int main(void) {
-<   char *A=NULL;
-<   *A = 1;
-< }
-$ mkfile segfault.c
+$ cd temp_testdir-catch-signal
+< kill 'SEGV', $$;
+$ mkfile segfault.pl
 
-$ cc -o segfault segfault.c
 ! expect signal SIGSEGV
-& ./segfault
-$ sleep 1
+& perl segfault.pl
+
 $ cd ..
 $ rm -rf temp_testdir-bg-set-signal
index 8e36d41..210d660 100644 (file)
@@ -2,26 +2,10 @@
 # This suite builds and uses a program returning 1.
 # tesh must detect this condition and report the issue.
 
-$ rm -rf temp_testdir-catch-return
-$ mkdir temp_testdir-catch-return
-
-$ cd temp_testdir-catch-return
-< #include <stdlib.h>
-< int main(void) {
-<   exit(1);
-< }
-$ mkfile return1.c
-
-$ cc -o return1 return1.c
-
 ! expect return 41
-< $ ./return1
-$ ../tesh --enable-coverage
-> Enable coverage
+< $ perl -e "exit 1"
+$ ./tesh
 > Test suite from stdin
-> [(stdin):1] ./return1
+> [(stdin):1] perl -e "exit 1"
 > Test suite `(stdin)': NOK (<(stdin):1> returned code 1)
 > <(stdin):1> No output so far.
-
-$ cd ..
-$ rm -rf temp_testdir-catch-return
index 892245e..3a7727f 100644 (file)
@@ -6,21 +6,18 @@ $ rm -rf temp_testdir-catch-signal
 $ mkdir temp_testdir-catch-signal
 
 $ cd temp_testdir-catch-signal
-< #include <stdlib.h>
-< int main(void) {
-<   char *A=NULL;
-<   *A = 1;
-< }
-$ mkfile segfault.c
+< kill 'SEGV', $$;
+$ mkfile segfault.pl
 
-$ cc -o segfault segfault.c
+! expect signal SIGSEGV
+$ perl segfault.pl
 
 ! expect return 15
-< $ ./segfault
+< $ perl segfault.pl
 $ ../tesh --enable-coverage
 > Enable coverage
 > Test suite from stdin
-> [(stdin):1] ./segfault
+> [(stdin):1] perl segfault.pl
 > Test suite `(stdin)': NOK (<(stdin):1> got signal SIGSEGV)
 > <(stdin):1> No output so far.
 
index 679234d..4ff5698 100644 (file)
@@ -2,19 +2,8 @@
 # This suite builds and uses a program returning 1.
 # tesh is instructed of this return code and must not whine.
 
-$ rm -rf temp_testdir-set-return
-$ mkdir temp_testdir-set-return
-
-$ cd temp_testdir-set-return
-< #include <stdlib.h>
-< int main(void) {
-<   exit(1);
-< }
-$ mkfile return1.c
-
-$ cc -o return1 return1.c
-
 ! expect return 1
-$ ./return1
-$ cd ..
-$ rm -rf temp_testdir-set-return
+$ perl -e "exit 1"
+
+! expect return 42
+$ perl -e "exit 42"
index 632fd8b..d932217 100644 (file)
@@ -2,30 +2,16 @@
 # This suite builds and uses a program returning 1.
 # tesh is instructed of this return code and must not whine.
 
-$ rm -rf temp_testdir-setenv
-$ mkdir temp_testdir-setenv
+$ rm -rf temp_testdir_setenv
+$ mkdir temp_testdir_setenv
+$ cd temp_testdir_setenv
 
-$ cd temp_testdir-setenv
-
-< #include <string.h>
-< #include <stdio.h>
-< extern char **environ;
-< int main(void) {
-<   char **env_iter=environ;
-<   while (*env_iter) {
-<     if (!strncmp(*env_iter,"tesh_test_toto=",strlen("tesh_test_toto=")))
-<       printf("%s\n",*env_iter);
-<     env_iter++;
-<   }
-<   return 0;
-< }
-$ mkfile getenv.c
-
-$ cc -o getenv getenv.c -g
+< print "tesh_test_toto=$ENV{tesh_test_toto}";
+$ mkfile testenv.pl
 
 ! setenv tesh_test_toto=blah
-$ ./getenv
+$ perl testenv.pl
 > tesh_test_toto=blah
 
 $ cd ..
-$ rm -rf temp_testdir-setenv
+$ rm -rf temp_testdir_setenv
index 29f141b..5ee51aa 100755 (executable)
@@ -470,7 +470,6 @@ LINE: while ( defined( my $line = <$infh> ) and not $error ) {
             exec_cmd( \%cmd );
             %cmd = ();
         }
-        print "hey\n";
         $cmd{'expect'} = "$1";
     } elsif ( $line =~ /^!\s*expect return/ ) {          #expect return
         if ( defined( $cmd{'cmd'} ) ) {
@@ -630,6 +629,7 @@ sub setenv_cmd($) {
         my ( $var, $ctn ) = ( $1, $2 );
         print "[Tesh/INFO] setenv $var=$ctn\n";
         $environ{$var} = $ctn;
+       $ENV{$var} = $ctn;
     } else {
         die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$arg'\n";
     }