From d2032f36c0ec6fdd7e4c0855df75a470af96ea23 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (l)" <j.wuttke@fz-juelich.de>
Date: Mon, 19 Oct 2015 20:49:54 +0200
Subject: [PATCH] ftest now under cmake - ftests return 0 on success; -
 throw_if -> exit_if

---
 pub/CMakeLists.txt              |  1 +
 pub/ftest/CMakeLists.txt        | 18 ++++++++++++++++++
 pub/ftest/arithmetics.f2t       | 20 ++++++++++----------
 pub/ftest/curve_functionals.f2t |  4 ++--
 pub/ftest/divisions.f2t         |  8 ++++----
 pub/ftest/fit0.f2t              |  6 +++---
 pub/ftest/fit1.f2t              |  2 +-
 pub/ftest/fit2glo.f2t           |  2 +-
 pub/ftest/fit3resol.f2t         |  2 +-
 pub/ftest/fit4glofreez.f2t      |  2 +-
 pub/ftest/fit5restrict.f2t      |  2 +-
 pub/ftest/fit6shift.f2t         |  6 +++---
 pub/ftest/fj_c.f2t              |  2 +-
 pub/ftest/freeze.f2t            | 18 +++++++++---------
 pub/ftest/i_as_j.f2t            |  6 +++---
 pub/ftest/jsel.f2t              | 18 +++++++++---------
 pub/ftest/mpa.f2t               | 18 +++++++++---------
 pub/ftest/mr_by_int.f2t         |  2 +-
 pub/ftest/nj_of_i.f2t           |  4 ++--
 pub/ftest/oi_avge.f2t           |  4 ++--
 pub/ftest/oi_p.f2t              |  4 ++--
 pub/ftest/oy1.f2t               |  4 ++--
 pub/ftest/oy_arg_collat.f2t     |  4 ++--
 pub/ftest/oz.f2t                |  3 ++-
 pub/ftest/r_of_i.f2t            |  4 ++--
 pub/ftest/run                   |  4 ++--
 pub/ftest/spheres_raw.f2t       |  4 ++--
 pub/ftest/ternary.f2t           |  6 +++---
 pub/lib/fbase.cpp               | 12 ++++++------
 pub/utest/CMakeLists.txt        | 11 +++++------
 30 files changed, 110 insertions(+), 91 deletions(-)
 create mode 100644 pub/ftest/CMakeLists.txt

diff --git a/pub/CMakeLists.txt b/pub/CMakeLists.txt
index 5e112775..4e8e7d5a 100644
--- a/pub/CMakeLists.txt
+++ b/pub/CMakeLists.txt
@@ -56,3 +56,4 @@ add_subdirectory(src)
 add_subdirectory(share)
 add_subdirectory(man)
 add_subdirectory(utest)
+add_subdirectory(ftest)
diff --git a/pub/ftest/CMakeLists.txt b/pub/ftest/CMakeLists.txt
new file mode 100644
index 00000000..1541e939
--- /dev/null
+++ b/pub/ftest/CMakeLists.txt
@@ -0,0 +1,18 @@
+# To run the tests on Linux, use 'make test' or 'ctest'.
+# To select which tests to run, use 'ctest -R regex'.
+# To see output from the individual tests, use 'ctest -V'.
+# For more options, run 'ctest --help'.
+
+enable_testing()
+
+# We glob test sources, though this is often considered evil.
+# Just touch CMakeLists.txt each time a test is added or withdrawn.
+
+file(GLOB test_sources "*.f2t")
+
+foreach(test_src ${test_sources})
+    # remove directory path and suffix, to retain just the name of the test
+    string(REGEX REPLACE ".*/" "" test_name "${test_src}")
+    string(REGEX REPLACE ".f2t$" "" test_name "${test_name}")
+    add_test(${test_name} "${test_src}")
+endforeach(test_src)
diff --git a/pub/ftest/arithmetics.f2t b/pub/ftest/arithmetics.f2t
index 6e050946..a18c73e6 100755
--- a/pub/ftest/arithmetics.f2t
+++ b/pub/ftest/arithmetics.f2t
@@ -1,11 +1,11 @@
 #!/usr/bin/env frida
-throw_unless(2+3==5,"arithmetic_failure")
-throw_unless(0.2+.3==.5,"arithmetic_failure")
-throw_unless(0.2+3==3.2,"arithmetic_failure")
-throw_unless(2<3,"arithmetic_failure")
-throw_unless(!(3<3),"arithmetic_failure")
-throw_unless(3<=3,"arithmetic_failure")
-throw_unless(3.1>3,"arithmetic_failure")
-throw_unless(!(3.>3),"arithmetic_failure")
-throw_unless(!(-3.<-3),"arithmetic_failure")
-exit(1)
\ No newline at end of file
+exit_unless(2+3==5,"arithmetic_failure")
+exit_unless(0.2+.3==.5,"arithmetic_failure")
+exit_unless(0.2+3==3.2,"arithmetic_failure")
+exit_unless(2<3,"arithmetic_failure")
+exit_unless(!(3<3),"arithmetic_failure")
+exit_unless(3<=3,"arithmetic_failure")
+exit_unless(3.1>3,"arithmetic_failure")
+exit_unless(!(3.>3),"arithmetic_failure")
+exit_unless(!(-3.<-3),"arithmetic_failure")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/curve_functionals.f2t b/pub/ftest/curve_functionals.f2t
index 900ae2c6..c9279892 100755
--- a/pub/ftest/curve_functionals.f2t
+++ b/pub/ftest/curve_functionals.f2t
@@ -1,4 +1,4 @@
 #!/usr/bin/env frida
 cca sin(t)
-throw_unless(abs(integrate(0,pi)-2)<1e-14,"integration_failed")
-exit(1)
\ No newline at end of file
+exit_unless(abs(integrate(0,pi)-2)<1e-14,"integration_failed")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/divisions.f2t b/pub/ftest/divisions.f2t
index 6501107a..e2dd0893 100755
--- a/pub/ftest/divisions.f2t
+++ b/pub/ftest/divisions.f2t
@@ -1,5 +1,5 @@
 #!/usr/bin/env frida
-throw_unless(abs(5/3-5.0/3.0)<1e-14,"fp_division_failed")
-throw_unless(5//3==1,"int_division_failed")
-throw_unless(5%3==2,"modulo_failed")
-exit(1)
\ No newline at end of file
+exit_unless(abs(5/3-5.0/3.0)<1e-14,"fp_division_failed")
+exit_unless(5//3==1,"int_division_failed")
+exit_unless(5%3==2,"modulo_failed")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/fit0.f2t b/pub/ftest/fit0.f2t
index e64797a6..0ae27140 100755
--- a/pub/ftest/fit0.f2t
+++ b/pub/ftest/fit0.f2t
@@ -5,6 +5,6 @@ oy! 7*i
 cc p0*t
 cwc
 cf
-throw_unless(abs(p0-7)<1e-13,"fit_failed")
-throw_unless(abs(f(1.5)-10.5)<1e-13,"curve_eval_failed")
-exit(1)
+exit_unless(abs(p0-7)<1e-13,"fit_failed")
+exit_unless(abs(f(1.5)-10.5)<1e-13,"curve_eval_failed")
+exit(0)
diff --git a/pub/ftest/fit1.f2t b/pub/ftest/fit1.f2t
index 92226a23..f160c8a4 100755
--- a/pub/ftest/fit1.f2t
+++ b/pub/ftest/fit1.f2t
@@ -4,4 +4,4 @@ oy 100*(j+x^1.1)
 ody! sqrt(1+y)
 cc p0+p1*t
 cf
-exit(1)
+exit(0)
diff --git a/pub/ftest/fit2glo.f2t b/pub/ftest/fit2glo.f2t
index 39913b10..bb3285c4 100755
--- a/pub/ftest/fit2glo.f2t
+++ b/pub/ftest/fit2glo.f2t
@@ -10,4 +10,4 @@ cp
 cg 1
 cf
 cp
-exit(1)
+exit(0)
diff --git a/pub/ftest/fit3resol.f2t b/pub/ftest/fit3resol.f2t
index 4b859d6f..602a1d48 100755
--- a/pub/ftest/fit3resol.f2t
+++ b/pub/ftest/fit3resol.f2t
@@ -5,4 +5,4 @@ fl dat-qel dat-res
 cp
 cf
 cp
-exit(1)
+exit(0)
diff --git a/pub/ftest/fit4glofreez.f2t b/pub/ftest/fit4glofreez.f2t
index f7e966f2..d0bfe74c 100755
--- a/pub/ftest/fit4glofreez.f2t
+++ b/pub/ftest/fit4glofreez.f2t
@@ -11,4 +11,4 @@ cg 1
 m/ 0
 cf
 cp
-exit(1)
+exit(0)
diff --git a/pub/ftest/fit5restrict.f2t b/pub/ftest/fit5restrict.f2t
index 5c17a533..938bb48c 100755
--- a/pub/ftest/fit5restrict.f2t
+++ b/pub/ftest/fit5restrict.f2t
@@ -5,4 +5,4 @@ cc p0+p1*(t-p2)
 cwc
 cr y>.1
 cf
-exit(1)
+exit(0)
diff --git a/pub/ftest/fit6shift.f2t b/pub/ftest/fit6shift.f2t
index 918e596c..164e4617 100755
--- a/pub/ftest/fit6shift.f2t
+++ b/pub/ftest/fit6shift.f2t
@@ -11,6 +11,6 @@ op1 40
 op2 1e-8
 cv 2
 cf
-throw_unless(abs(p0[4,0]-.15)<.05,"shifted_resol_fit_failed")
-throw_unless(abs(p1[4,0]-80)<1,"shifted_resol_fit_failed")
-exit(1)
+exit_unless(abs(p0[4,0]-.15)<.05,"shifted_resol_fit_failed")
+exit_unless(abs(p1[4,0]-80)<1,"shifted_resol_fit_failed")
+exit(0)
diff --git a/pub/ftest/fj_c.f2t b/pub/ftest/fj_c.f2t
index 637c6d1e..2ad11daa 100755
--- a/pub/ftest/fj_c.f2t
+++ b/pub/ftest/fj_c.f2t
@@ -9,4 +9,4 @@ cwc
 cf
 4:7 mfj
 cp
-exit(1)
+exit(0)
diff --git a/pub/ftest/freeze.f2t b/pub/ftest/freeze.f2t
index ac33b04d..fc52fbe7 100755
--- a/pub/ftest/freeze.f2t
+++ b/pub/ftest/freeze.f2t
@@ -3,14 +3,14 @@ fm 1 1000 h
 oy! 1
 m/ 33,100:300:10
 oy! 0
-throw_unless(y[,32,0]==0,"failed")
-throw_unless(y[,33,0]==1,"failed")
-throw_unless(y[,100,0]==1,"failed")
-throw_unless(y[,101,0]==0,"failed")
+exit_unless(y[,32,0]==0,"failed")
+exit_unless(y[,33,0]==1,"failed")
+exit_unless(y[,100,0]==1,"failed")
+exit_unless(y[,101,0]==0,"failed")
 m/-
 oy! 2
-throw_unless(y[,32,0]==2,"failed")
-throw_unless(y[,33,0]==2,"failed")
-throw_unless(y[,100,0]==2,"failed")
-throw_unless(y[,101,0]==2,"failed")
-exit(1)
\ No newline at end of file
+exit_unless(y[,32,0]==2,"failed")
+exit_unless(y[,33,0]==2,"failed")
+exit_unless(y[,100,0]==2,"failed")
+exit_unless(y[,101,0]==2,"failed")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/i_as_j.f2t b/pub/ftest/i_as_j.f2t
index 55de5f1e..c2a09be6 100755
--- a/pub/ftest/i_as_j.f2t
+++ b/pub/ftest/i_as_j.f2t
@@ -4,6 +4,6 @@ oy! 10*j+i
 oz0! 100*j
 0 oi y[,,1]
 1 oy z0[0,i]
-throw_unless(x[2,0,1]==100,"x_wrong")
-throw_unless(y[2,0,1]==100,"y_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(x[2,0,1]==100,"x_wrong")
+exit_unless(y[2,0,1]==100,"y_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/jsel.f2t b/pub/ftest/jsel.f2t
index 615bd889..62ab7f32 100755
--- a/pub/ftest/jsel.f2t
+++ b/pub/ftest/jsel.f2t
@@ -1,18 +1,18 @@
 #!/usr/bin/env frida
 fm 1000 1 h
-throw_unless(ni==1000,"mpr_failed")
+exit_unless(ni==1000,"mpr_failed")
 mpr 0:899
-throw_unless(ni==900,"mpr_failed")
+exit_unless(ni==900,"mpr_failed")
 mpr 50:
-throw_unless(ni==850,"mpr_failed")
+exit_unless(ni==850,"mpr_failed")
 mpr :799
-throw_unless(ni==800,"mpr_failed")
+exit_unless(ni==800,"mpr_failed")
 mpr ::4
-throw_unless(ni==200,"mpr_failed")
+exit_unless(ni==200,"mpr_failed")
 mpd ::4
-throw_unless(ni==150,"mpr_failed")
+exit_unless(ni==150,"mpr_failed")
 mpr 0:119:3
-throw_unless(ni==40,"mpr_failed")
+exit_unless(ni==40,"mpr_failed")
 mpd 0:39:4
-throw_unless(ni==30,"mpr_failed")
-exit(1)
\ No newline at end of file
+exit_unless(ni==30,"mpr_failed")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/mpa.f2t b/pub/ftest/mpa.f2t
index 14f7619b..f88813c1 100755
--- a/pub/ftest/mpa.f2t
+++ b/pub/ftest/mpa.f2t
@@ -2,14 +2,14 @@
 fm 9 1 h
 0 oy 3+i
 1 mpa 0,3
-throw_unless(abs(y[2,0,0]-(3+1))<1e-15,"mpa_test11")
-throw_unless(abs(y[2,0,1]-(3+5.5))<1e-15,"mpa_test12")
+exit_unless(abs(y[2,0,0]-(3+1))<1e-15,"mpa_test11")
+exit_unless(abs(y[2,0,1]-(3+5.5))<1e-15,"mpa_test12")
 1 mpaf 3
-throw_unless(ni[3,0]==3,"mpa_test20")
-throw_unless(abs(y[3,0,0]-(3+1))<1e-15,"mpa_test21")
-throw_unless(abs(y[3,0,2]-(3+7))<1e-15,"mpa_test22")
+exit_unless(ni[3,0]==3,"mpa_test20")
+exit_unless(abs(y[3,0,0]-(3+1))<1e-15,"mpa_test21")
+exit_unless(abs(y[3,0,2]-(3+7))<1e-15,"mpa_test22")
 1 mpaf 4
-throw_unless(ni[4,0]==2,"mpa_test30")
-throw_unless(abs(y[4,0,0]-(3+1.5))<1e-15,"mpa_test31")
-throw_unless(abs(y[4,0,1]-(3+5.5))<1e-15,"mpa_test32")
-exit(1)
+exit_unless(ni[4,0]==2,"mpa_test30")
+exit_unless(abs(y[4,0,0]-(3+1.5))<1e-15,"mpa_test31")
+exit_unless(abs(y[4,0,1]-(3+5.5))<1e-15,"mpa_test32")
+exit(0)
diff --git a/pub/ftest/mr_by_int.f2t b/pub/ftest/mr_by_int.f2t
index 8ceb71db..1fda00f5 100755
--- a/pub/ftest/mr_by_int.f2t
+++ b/pub/ftest/mr_by_int.f2t
@@ -3,4 +3,4 @@ fm 7 7 h
 oy j+i
 oi avge
 1 mr y[2,0,j]>7
-exit(1)
+exit(0)
diff --git a/pub/ftest/nj_of_i.f2t b/pub/ftest/nj_of_i.f2t
index 598848d3..a6730e0a 100755
--- a/pub/ftest/nj_of_i.f2t
+++ b/pub/ftest/nj_of_i.f2t
@@ -4,5 +4,5 @@ fm 1 2 h2
 fm 1 3 h3
 fm 3 1 out
 oy nj[i]
-throw_unless(sum==6,"sum_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(sum==6,"sum_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/oi_avge.f2t b/pub/ftest/oi_avge.f2t
index a824c2b7..7cc4ea4a 100755
--- a/pub/ftest/oi_avge.f2t
+++ b/pub/ftest/oi_avge.f2t
@@ -1,5 +1,5 @@
 #!/usr/bin/env frida
 fm 11 1 h
 oy i
-throw_unless(avge==5,"final_result_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(avge==5,"final_result_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/oi_p.f2t b/pub/ftest/oi_p.f2t
index 128e95fd..e294b734 100755
--- a/pub/ftest/oi_p.f2t
+++ b/pub/ftest/oi_p.f2t
@@ -3,5 +3,5 @@ fm 3 3 h
 cc p0*t
 op0 j+.77
 oi p0
-throw_unless(y[,,2]==2.77,"final_result_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(y[,,2]==2.77,"final_result_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/oy1.f2t b/pub/ftest/oy1.f2t
index 71b55adc..f85f08bd 100755
--- a/pub/ftest/oy1.f2t
+++ b/pub/ftest/oy1.f2t
@@ -4,5 +4,5 @@ ox! i
 oy! j+i
 oz0! j
 oy x+z0
-throw_unless(y[0,2,7]==9&&y[1,2,7]==9,"final_result_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(y[0,2,7]==9&&y[1,2,7]==9,"final_result_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/oy_arg_collat.f2t b/pub/ftest/oy_arg_collat.f2t
index 23c11be8..e1463976 100755
--- a/pub/ftest/oy_arg_collat.f2t
+++ b/pub/ftest/oy_arg_collat.f2t
@@ -5,5 +5,5 @@ fm 7 1 h
 oy! i
 0 oy y/y[1,0]
 df
-throw_unless(y[2,2,6]==3,"final_result_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(y[2,2,6]==3,"final_result_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/oz.f2t b/pub/ftest/oz.f2t
index 41207107..cca7f756 100755
--- a/pub/ftest/oz.f2t
+++ b/pub/ftest/oz.f2t
@@ -2,4 +2,5 @@
 fm 7 3 h
 oz+ 100*j
 mz- 0
-exit(z0[,2]==200)
\ No newline at end of file
+exit_unless(z0[,2]==200,"failed")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/r_of_i.f2t b/pub/ftest/r_of_i.f2t
index c1e39f0c..915e2c8c 100755
--- a/pub/ftest/r_of_i.f2t
+++ b/pub/ftest/r_of_i.f2t
@@ -2,5 +2,5 @@
 fm 1 1 h
 or+ 77
 oy r0[1+i]
-throw_unless(y==77,"result_wrong")
-exit(1)
\ No newline at end of file
+exit_unless(y==77,"result_wrong")
+exit(0)
\ No newline at end of file
diff --git a/pub/ftest/run b/pub/ftest/run
index 684450f2..a7347674 100755
--- a/pub/ftest/run
+++ b/pub/ftest/run
@@ -4,11 +4,11 @@ COUNTER=0
 rm -f log.tmp
 for I in *.f2t; do
     ./$I >> log.tmp
-    if [ $? = 1 ]; then
+    if [ $? = 0 ]; then
        echo "passed $I"
     else
        echo "FAILED $I"
        let COUNTER=COUNTER+1
-    fi    
+    fi
 done
 echo "=> $COUNTER failures. See log.tmp for full dialogs."
diff --git a/pub/ftest/spheres_raw.f2t b/pub/ftest/spheres_raw.f2t
index fd4c3aa9..2c25e532 100755
--- a/pub/ftest/spheres_raw.f2t
+++ b/pub/ftest/spheres_raw.f2t
@@ -1,5 +1,5 @@
 #!/usr/bin/env frida
 ry8 spheres_raw
 0
-throw_unless(nk==8,"failed")
-exit(1)
+exit_unless(nk==8,"failed")
+exit(0)
diff --git a/pub/ftest/ternary.f2t b/pub/ftest/ternary.f2t
index ca9c42f5..6be24725 100755
--- a/pub/ftest/ternary.f2t
+++ b/pub/ftest/ternary.f2t
@@ -1,4 +1,4 @@
 #!/usr/bin/env frida
-throw_unless(0?2:3==3,"cond_expr_failed")
-throw_unless(1?4:5==4,"cond_expr_failed")
-exit(1)
+exit_unless(0?2:3==3,"cond_expr_failed")
+exit_unless(1?4:5==4,"cond_expr_failed")
+exit(0)
diff --git a/pub/lib/fbase.cpp b/pub/lib/fbase.cpp
index 72031fe3..2c2d61d4 100644
--- a/pub/lib/fbase.cpp
+++ b/pub/lib/fbase.cpp
@@ -169,8 +169,8 @@ double func_diehl( double a ) {
 
 int func_exit( int a ) { exit(a); return 0; }
 
-int func_throw_if( int a, string s ) { if(a) throw s; return 0; }
-int func_throw_unless( int a, string s ) { if(!a) throw s; return 0; }
+int func_exit_if( int a, string s ) { if(a) { cerr << s << "\n"; exit(1); } return 0; }
+int func_exit_unless( int a, string s ) { return func_exit_if( !a, s ); }
 
 //**************************************************************************************************
 //*  Functions of two arguments
@@ -591,10 +591,10 @@ void fbase_initialize()
     G->register_fct_d_d  ( "lndiehl", func_lndiehl );
 
     // f(2 args)
-    G->register_fct_meta ( "throw_if", 2, "(x,s): throw s if x" );
-    G->register_fct_i_is ( "throw_if", func_throw_if );
-    G->register_fct_meta ( "throw_unless", 1, "(x,s): throw s if !x" );
-    G->register_fct_i_is ( "throw_unless", func_throw_unless );
+    G->register_fct_meta ( "exit_if", 2, "(x,s): throw s if x" );
+    G->register_fct_i_is ( "exit_if", func_exit_if );
+    G->register_fct_meta ( "exit_unless", 1, "(x,s): throw s if !x" );
+    G->register_fct_i_is ( "exit_unless", func_exit_unless );
     G->register_fct_meta ( "min2", 2, "(x,y): the smaller of the two arguments x and y" );
     G->register_fct_i_ii ( "min2", func_min );
     G->register_fct_d_dd ( "min2", func_min );
diff --git a/pub/utest/CMakeLists.txt b/pub/utest/CMakeLists.txt
index 2903d3c4..8ac2b8eb 100644
--- a/pub/utest/CMakeLists.txt
+++ b/pub/utest/CMakeLists.txt
@@ -1,13 +1,12 @@
-# CMake build script for Tests
+# To run the tests on Linux, use 'make test' or 'ctest'.
+# To select which tests to run, use 'ctest -R regex'.
+# To see output from the individual tests, use 'ctest -V'.
+# For more options, run 'ctest --help'.
 
 include(cmake/utils.cmake) # defines cxx_executable, cxx_test
 
 enable_testing()
 
-# To run the tests on Linux, use 'make test' or 'ctest'.
-# You can select which tests to run using 'ctest -R regex'.
-# For more options, run 'ctest --help'.
-
 include_directories(
     ${gtest_SOURCE_DIR}/include
     ${gtest_SOURCE_DIR}
@@ -32,7 +31,7 @@ set(test_link_libs
     )
 
 # We glob test sources, though this is often considered evil.
-# Just touch Tests/CMakeLists.txt each time a test is added or withdrawn.
+# Just touch CMakeLists.txt each time a test is added or withdrawn.
 
 file(GLOB test_sources "test[0-9]*.cpp")
 
-- 
GitLab