Also, revive the setenv test and make it work (the forked environment
was not modified but only the command line rewriting mechanism)
### 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)
### 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)
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)
$ mkdir temp_testdir_background
$ cd 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;
+< exit 0;
+<
+$ mkfile delayed_cat.pl
-$ cc -Wall -o delayed_cat delayed_cat.c
-
-& ./delayed_cat
$ rm -rf temp_testdir-bg-set-signal
$ mkdir temp_testdir-bg-set-signal
$ 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
$ cd ..
$ rm -rf temp_testdir-bg-set-signal
$ cd ..
$ rm -rf temp_testdir-bg-set-signal
# This suite builds and uses a program returning 1.
# tesh must detect this condition and report the issue.
# 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
-
-< $ ./return1
-$ ../tesh --enable-coverage
-> Enable coverage
+< $ perl -e "exit 1"
+$ ./tesh
+> [(stdin):1] perl -e "exit 1"
> Test suite `(stdin)': NOK (<(stdin):1> returned code 1)
> <(stdin):1> No output so far.
> Test suite `(stdin)': NOK (<(stdin):1> returned code 1)
> <(stdin):1> No output so far.
-
-$ cd ..
-$ rm -rf temp_testdir-catch-return
$ mkdir temp_testdir-catch-signal
$ cd 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
$ ../tesh --enable-coverage
> Enable coverage
> Test suite from stdin
$ ../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.
> Test suite `(stdin)': NOK (<(stdin):1> got signal SIGSEGV)
> <(stdin):1> No output so far.
# This suite builds and uses a program returning 1.
# tesh is instructed of this return code and must not whine.
# 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
-
-$ ./return1
-$ cd ..
-$ rm -rf temp_testdir-set-return
+$ perl -e "exit 1"
+
+! expect return 42
+$ perl -e "exit 42"
# This suite builds and uses a program returning 1.
# tesh is instructed of this return code and must not whine.
# 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
! setenv tesh_test_toto=blah
> tesh_test_toto=blah
$ cd ..
> tesh_test_toto=blah
$ cd ..
-$ rm -rf temp_testdir-setenv
+$ rm -rf temp_testdir_setenv
exec_cmd( \%cmd );
%cmd = ();
}
exec_cmd( \%cmd );
%cmd = ();
}
$cmd{'expect'} = "$1";
} elsif ( $line =~ /^!\s*expect return/ ) { #expect return
if ( defined( $cmd{'cmd'} ) ) {
$cmd{'expect'} = "$1";
} elsif ( $line =~ /^!\s*expect return/ ) { #expect return
if ( defined( $cmd{'cmd'} ) ) {
my ( $var, $ctn ) = ( $1, $2 );
print "[Tesh/INFO] setenv $var=$ctn\n";
$environ{$var} = $ctn;
my ( $var, $ctn ) = ( $1, $2 );
print "[Tesh/INFO] setenv $var=$ctn\n";
$environ{$var} = $ctn;
} else {
die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$arg'\n";
}
} else {
die "[Tesh/CRITICAL] Malformed argument to setenv: expected 'name=value' but got '$arg'\n";
}