diff --git a/CMakeLists.txt b/CMakeLists.txt index a24d967..498b0ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ Project(Stasis) SET(PACKAGE_VERSION 1) -SUBDIRS(src test utilities benchmarks examples) +SUBDIRS(src test utilities benchmarks examples lang) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) SET(FLEX_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake) SET(BISON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cmake) diff --git a/lang/CMakeLists.txt b/lang/CMakeLists.txt new file mode 100644 index 0000000..09497d8 --- /dev/null +++ b/lang/CMakeLists.txt @@ -0,0 +1 @@ +SUBDIRS(perl) diff --git a/lang/perl/CMakeLists.txt b/lang/perl/CMakeLists.txt new file mode 100644 index 0000000..471d1a3 --- /dev/null +++ b/lang/perl/CMakeLists.txt @@ -0,0 +1,16 @@ +#CREATE_CHECK_OPT(STASIS_DIR=${CMAKE_TOPLEVEL_SOURCE_DIR} ./t/test.pl) +#CREATE_CHECK_OPT(STASIS_DIR=${CMAKE_TOPLEVEL_SOURCE_DIR} ./t/test2.pl < t/test2.script) +SET(ENV{STASIS_DIR} ${CMAKE_HOME_DIRECTORY}) +MACRO(CREATE_CHECK_PERL NAME) + ADD_TEST(${NAME} perl -I ${CMAKE_HOME_DIRECTORY}/lang/perl ${CMAKE_CURRENT_SOURCE_DIR}/${NAME} --automated-test) +ENDMACRO(CREATE_CHECK_PERL) + +MACRO(CREATE_CHECK_PERL_OPT NAME OPT) + ADD_TEST(${NAME} perl -I ${CMAKE_HOME_DIRECTORY}/lang/perl ${CMAKE_CURRENT_SOURCE_DIR}/${NAME} --automated-test ${OPT}) +ENDMACRO(CREATE_CHECK_PERL_OPT) + +CREATE_CHECK_PERL(t/test.pl) +CREATE_CHECK_PERL_OPT(t/test2.pl ${CMAKE_CURRENT_SOURCE_DIR}/t/test2.script) + +#ADD_TEST(perl/test.pl perl -I${CMAKE_HOME_DIRECTORY}/lang/perl ${CMAKE_CURRENT_SOURCE_DIR}/t/test.pl) +#ADD_TEST(perl/t/test2.pl ${CMAKE_CURRENT_SOURCE_DIR}/t/test.pl STASIS_DIR=${CMAKE_HOME_DIRECTORY}) diff --git a/lang/perl/Stasis.pm b/lang/perl/Stasis.pm index ec62aae..314176c 100644 --- a/lang/perl/Stasis.pm +++ b/lang/perl/Stasis.pm @@ -3,9 +3,14 @@ require Inline; my $STASIS_DIR; BEGIN { - $STASIS_DIR = $ENV{STASIS_DIR} - || die "\nNeed STASIS_DIR environment variable!!\n\n"; -#'/home/sears/stasis4'; + $STASIS_DIR = $ENV{STASIS_DIR}; + if(!defined($STASIS_DIR)) { + $STASIS_DIR = $INC{"Stasis.pm"}; + $STASIS_DIR =~ s~/lang/perl/Stasis.pm~~g; + print $STASIS_DIR; + } + 1; +#die "\nNeed STASIS_DIR environment variable!!\n\n"; } use Inline C => Config => LIBS => "-L$STASIS_DIR/build/src/stasis/ " . diff --git a/lang/perl/t/test.pl b/lang/perl/t/test.pl index 7272be5..1268d68 100755 --- a/lang/perl/t/test.pl +++ b/lang/perl/t/test.pl @@ -3,33 +3,60 @@ use strict; use Stasis; +my $expected = qq(0 +rid is 1 0 +thequickbrown +rid is 1 1 +->3.14159 +42 +13 +42 +); +my $checking = 0; +my $out = ""; + +sub myprint { + my $a = shift; + if($checking) { + $out .= $a; + } else { + print $a; + } +} + +if($ARGV[0] eq "--automated-test") { + shift @ARGV; + system ("rm storefile.txt logfile.txt"); + $checking = 1; +} + Stasis::Tinit(); my $x=Stasis::Tbegin(); -print("$x\n"); +myprint("$x\n"); my $rid1 = Stasis::TallocScalar($x, "thequickbrown"); #14); -print "rid is $$rid1[0] $$rid1[1]\n"; +myprint "rid is $$rid1[0] $$rid1[1]\n"; defined ($rid1) || die; Stasis::Tset($x, $rid1, "thequickbrown"); my $thequickbrown = Stasis::Tread($x, $rid1); -print "$thequickbrown\n"; +myprint "$thequickbrown\n"; $rid1 = Stasis::TallocScalar($x, 3.14159); #14); -print "rid is $$rid1[0] $$rid1[1]\n"; +myprint "rid is $$rid1[0] $$rid1[1]\n"; defined ($rid1) || die; Stasis::Tset($x, $rid1, 3.14159); $thequickbrown = Stasis::Tread($x, $rid1); -print "->$thequickbrown\n"; +myprint "->$thequickbrown\n"; my $rid2 = Stasis::TallocScalar($x, 42); Stasis::Tset($x, $rid2, 42); $thequickbrown = Stasis::Tread($x, $rid2); -print "$thequickbrown\n"; +myprint "$thequickbrown\n"; $thequickbrown == 42 || die; @@ -39,14 +66,14 @@ $x = Stasis::Tbegin(); Stasis::Tset($x, $rid2, 13); $thequickbrown = Stasis::Tread($x, $rid2); -print "$thequickbrown\n"; +myprint "$thequickbrown\n"; $thequickbrown == 13 || die; Stasis::Tabort($x); $x = Stasis::Tbegin(); $thequickbrown = Stasis::Tread($x, $rid2); -print "$thequickbrown\n"; +myprint "$thequickbrown\n"; $thequickbrown == 42 || die; @@ -60,3 +87,10 @@ my $rid2cpy = Stasis::Tread($x,$rid3); Stasis::Tcommit($x); Stasis::Tdeinit(); + + +if($checking) { + $out eq $expected || die "\nFAIL: Output did not match. Expected\n$expected\nGot\n$out"; + print "\nPASS: Produced expected output:\n$out"; +} + diff --git a/lang/perl/t/test2.pl b/lang/perl/t/test2.pl index fbf13bc..1c99963 100755 --- a/lang/perl/t/test2.pl +++ b/lang/perl/t/test2.pl @@ -2,6 +2,40 @@ use strict; use Stasis; +my $expected = qq(! => + => y => q => a + b + r => c + d + z => s => e + f + t => g + h + - => @ => u => i + j + v => k + l + # => w => m + n + x => o + p +); +my $checking = 0; +my $out = ""; + +sub myprint { + my $a = shift; + if($checking) { + $out .= $a; + } else { + print $a; + } +} + +if($ARGV[0] eq "--automated-test") { + shift @ARGV; + system ("rm storefile.txt logfile.txt"); + $checking = 1; +} Stasis::Tinit(); my $xid = Stasis::Tbegin(); @@ -11,19 +45,19 @@ sub walk { my $from = shift; my $level = shift || 0; my $to = Stasis::ThashLookup($xid, $rid, $from); - print $from; + myprint $from; $level += (length($from) + 4); if(defined $to) { my @tok = split ',', $to; my $first = 1; foreach my $f (@tok) { - if($first) { print " => "; } else { my $n = $level; while($n--) {print " ";} } + if($first) { myprint " => "; } else { my $n = $level; while($n--) {myprint " ";} } $first = 0; walk($f,$level); } } else { - print "\n"; + myprint "\n"; } } @@ -46,3 +80,8 @@ while(my $line = <>) { Stasis::Tcommit($xid); Stasis::Tdeinit(); + +if($checking) { + $out eq $expected || die "\nFAIL: Output did not match. Expected\n$expected\nGot\n$out"; + print "\nPASS: Produced expected output:\n$out"; +} diff --git a/src/apps/referential/CMakeLists.txt b/src/apps/referential/CMakeLists.txt index 26b4c50..6375752 100644 --- a/src/apps/referential/CMakeLists.txt +++ b/src/apps/referential/CMakeLists.txt @@ -3,7 +3,5 @@ SUBDIRS(lang) ADD_LIBRARY(referential algebra.c dml.c ddl.c tuple.c lang/ast.c) TARGET_LINK_LIBRARIES(referential ${COMMON_LIBRARIES}) SET(COMMON_LIBRARIES referential refparse ${COMMON_LIBRARIES}) -IF(CHECK_LIBRARY) - CREATE_CHECK_OPT(toplevel ${CMAKE_CURRENT_SOURCE_DIR}/test-script.ref) -ENDIF(CHECK_LIBRARY) +CREATE_CHECK_OPT(toplevel ${CMAKE_CURRENT_SOURCE_DIR}/test-script.ref) endif(HAVE_GETLINE)