changeset 20339:dadfb0be8a42

write sparse tests to stdout * test/build-sparse-tests.sh: Write output to stdout. * Makefile.am (sparse.tst): Adapt rule.
author John W. Eaton <jwe@octave.org>
date Thu, 02 Jul 2015 18:00:39 -0400
parents 3c87bcf7e0f9
children 4f911b4e012b
files test/Makefile.am test/build-sparse-tests.sh
diffstat 2 files changed, 87 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/test/Makefile.am	Thu Jul 02 17:44:05 2015 -0400
+++ b/test/Makefile.am	Thu Jul 02 18:00:39 2015 -0400
@@ -80,7 +80,9 @@
 endif
 
 sparse.tst: build-sparse-tests.sh
-	$(AM_V_GEN)$(srcdir)/build-sparse-tests.sh
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	$(srcdir)/build-sparse-tests.sh > $@-t && \
+	mv $@-t $@
 
 GENERATED_BC_OVERLOADS_DIRS := \
   $(shell $(srcdir)/build-bc-overload-tests.sh --list-dirs)
--- a/test/build-sparse-tests.sh	Thu Jul 02 17:44:05 2015 -0400
+++ b/test/build-sparse-tests.sh	Thu Jul 02 18:00:39 2015 -0400
@@ -113,14 +113,8 @@
     *) echo "build-sparse-tests.sh random|preset" && exit 1 ;;
 esac
 
-if $preset; then
-    TESTS=sparse.tst
-else
-    TESTS=sprandom.tst
-fi
-
 # create initial file
-cat >$TESTS <<EOF
+cat <<EOF
 ## !!! DO NOT EDIT !!!
 ## THIS IS AN AUTOMATICALLY GENERATED FILE
 ## modify build-sparse-tests.sh to generate the tests you need.
@@ -134,7 +128,7 @@
 # Section separator
 
 gen_section() {
-cat >>$TESTS <<EOF
+cat <<EOF
 
 # ==============================================================
 
@@ -149,7 +143,7 @@
 # If a sparse operation yields zeros, then those elements
 # of the returned sparse matrix should be eaten.
 gen_eat_zeros() {
-cat >>$TESTS <<EOF
+cat <<EOF
 %% Make sure newly introduced zeros get eaten
 %!assert (nnz (sparse ([bf,bf,1]).^realmax), 1)
 %!assert (nnz (sparse ([1,bf,bf]).^realmax), 1)
@@ -171,7 +165,7 @@
 }
 
 gen_specific() {
-cat >>$TESTS <<EOF
+cat <<EOF
 
 %!test # segfault test from edd@debian.org
 %! n = 510;
@@ -202,12 +196,12 @@
     gen_section
     gen_specific
     gen_section
-    echo '%!shared bf' >> $TESTS
-    echo '%!test bf=realmin;' >> $TESTS
+    echo '%!shared bf'
+    echo '%!test bf=realmin;'
     gen_eat_zeros
-    echo '%!test bf=realmin+realmin*1i;' >> $TESTS
+    echo '%!test bf=realmin+realmin*1i;'
     gen_eat_zeros
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!assert (nnz (sparse ([-1,realmin,realmin]).^1.5), 1)
 %!assert (nnz (sparse ([-1,realmin,realmin,1]).^1.5), 2)
 
@@ -231,7 +225,7 @@
 
 gen_function() {
     if $preset; then
-        cat >>$TESTS <<EOF
+        cat <<EOF
 ##
 ## test_sparse
 ##
@@ -243,7 +237,7 @@
 
 EOF
     else
-        cat >>$TESTS <<EOF
+        cat <<EOF
 ##
 ## test_sprandom
 ##
@@ -274,7 +268,7 @@
 
 # test ordered comparisons: uses as,af,bs,bf
 gen_ordering_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% real values can be ordered (uses as,af)
 %!assert (as<=bf, sparse (af<=bf))
 %!assert (bf<=as, sparse (bf<=af))
@@ -292,7 +286,7 @@
 }
 
 gen_sparsesparse_ordering_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!assert (as<=bs, sparse (af<=bf))
 %!assert (as>=bs, sparse (af>=bf))
 %!assert (as<bs, sparse (af<bf))
@@ -302,7 +296,7 @@
 
 # test element-wise binary operations: uses as,af,bs,bf,scalar
 gen_elementop_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Elementwise binary tests (uses as,af,bs,bf,scalar)
 %!assert (as==bs, sparse (af==bf))
 %!assert (bf==as, sparse (bf==af))
@@ -332,7 +326,7 @@
 }
 
 gen_sparsesparse_elementop_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!assert (as==bs, sparse (af==bf))
 %!assert (as!=bs, sparse (af!=bf))
 %!assert (as+bs, sparse (af+bf))
@@ -350,7 +344,7 @@
 
 # test matrix-matrix left and right division: uses as,af,bs,bf
 gen_divop_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Matrix-matrix operators (uses af,as,bs,bf)
 %!assert (as/bf, af/bf, 100*eps)
 %!assert (af/bs, af/bf, 100*eps)
@@ -364,7 +358,7 @@
 
 # test matrix-matrix left and right division: uses as,af,bs,bf
 gen_square_divop_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Matrix-matrix operators (uses af,as,bs,bf)
 %!assert (as/bf, af/bf, 100*eps)
 %!assert (af/bs, af/bf, 100*eps)
@@ -378,7 +372,7 @@
 
 # test matrix-matrix operations: uses as,af,bs,bf
 gen_matrixop_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Matrix-matrix operators (uses af,as,bs,bf)
 %!assert (as*bf', af*bf')
 %!assert (af*bs', af*bf')
@@ -389,7 +383,7 @@
 
 # test diagonal operations
 gen_matrixdiag_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Matrix diagonal tests (uses af,as,bf,bs)
 %!assert (diag (as), sparse (diag (af)))
 %!assert (diag (bs), sparse (diag (bf)))
@@ -414,7 +408,7 @@
 
 # test matrix reshape operations
 gen_matrixreshape_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Matrix diagonal tests (uses af,as,bf,bs)
 %!assert (reshape (as,1,prod(size(as))), sparse (reshape (af,1,prod(size(af)))))
 %!assert (reshape (as,prod(size(as)),1), sparse (reshape (af,prod(size(af)),1)))
@@ -428,11 +422,11 @@
 
 # test mapper matrix operations: uses as,af
 print_mapper_test() {
-echo "%!assert ($1(as), sparse ($1(af)))" >>$TESTS
+echo "%!assert ($1(as), sparse ($1(af)))"
 }
 
 print_real_mapper_test() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! wn2s = warning ("query", "Octave:num-to-str");
 %! warning ("off", "Octave:num-to-str");
@@ -449,7 +443,7 @@
 }
 
 gen_mapper_tests() {
-echo "%% Unary matrix tests (uses af,as)">>$TESTS
+echo "%% Unary matrix tests (uses af,as)"
 print_mapper_test abs
 print_mapper_test acos
 print_mapper_test acosh
@@ -483,7 +477,7 @@
 print_mapper_test tanh
 
 # Specific tests for certain mapper functions
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!assert (issparse (abs (as))  && isreal (abs (as)))
 %!assert (issparse (real (as)) && isreal (real (as)))
 %!assert (issparse (imag (as)) && isreal (imag (as)))
@@ -492,7 +486,7 @@
 }
 
 gen_real_mapper_tests() {
-echo "%% Unary matrix tests (uses af,as)">>$TESTS
+echo "%% Unary matrix tests (uses af,as)"
 print_real_mapper_test erf 1
 print_real_mapper_test erfc 1
 #print_real_mapper_test gamma 1
@@ -511,7 +505,7 @@
 #print_real_mapper_test gammaln 1
 
 # Specific tests for certain mapper functions
-    cat >>$TESTS <<EOF
+    cat <<EOF
 
 %!test
 %! wn2s = warning ("query", "Octave:num-to-str");
@@ -528,7 +522,7 @@
 
 # test matrix operations: uses as,af
 gen_unaryop_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %% Unary matrix tests (uses af,as)
 %!assert (issparse (as))
 %!assert (!issparse (af))
@@ -632,7 +626,7 @@
 # The \ and / operator tests on square matrices
     gen_square_divop_tests
 
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!testif HAVE_UMFPACK
 %! assert(det(bs+speye(size(bs))), det(bf+eye(size(bf))), 100*eps*abs(det(bf+eye(size(bf)))))
 
@@ -697,7 +691,7 @@
 
 # Cholesky tests
 gen_cholesky_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!testif HAVE_CHOLMOD
 %! assert (chol (bs)'*chol (bs), bs, 1e-10);
 %!testif HAVE_CHOLMOD
@@ -726,19 +720,19 @@
 
 # test scalar operations: uses af and real scalar bf; modifies as,bf,bs
 gen_scalar_tests() {
-    echo '%!test as = sparse (af);' >> $TESTS
-    echo '%!test bs = bf;' >> $TESTS
+    echo '%!test as = sparse (af);'
+    echo '%!test bs = bf;'
     gen_elementop_tests
     gen_ordering_tests
-    echo '%!test bf = bf+1i;' >>$TESTS
-    echo '%!test bs = bf;' >> $TESTS
+    echo '%!test bf = bf+1i;'
+    echo '%!test bs = bf;'
     gen_elementop_tests
 }
 
 # test matrix operations: uses af and bf; modifies as,bs
 gen_rectangular_tests() {
-    echo '%!test as = sparse(af);' >> $TESTS
-    echo '%!test bs = sparse(bf);' >>$TESTS
+    echo '%!test as = sparse(af);'
+    echo '%!test bs = sparse(bf);'
     gen_mapper_tests
     gen_real_mapper_tests
     gen_unaryop_tests
@@ -748,7 +742,7 @@
     # gen_divop_tests # Disable rectangular \ and / for now
     gen_matrixdiag_tests
     gen_matrixreshape_tests
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!testif HAVE_UMFPACK   # permuted LU
 %! [L,U] = lu (bs);
 %! assert (L*U, bs, 1e-10);
@@ -797,7 +791,7 @@
 # sparse assembly tests
 
 gen_assembly_tests() {
-cat >>$TESTS <<EOF
+cat <<EOF
 %%Assembly tests
 %!test
 %! m = max ([m;r(:)]);
@@ -838,14 +832,14 @@
 # sparse selection tests
 
 gen_scalar_select_tests () {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!assert (sparse (42)([1,1]), sparse ([42,42]))
 %!assert (sparse (42*1i)([1,1]), sparse ([42,42].*1i))
 EOF
 }
 
 gen_select_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test as = sparse (af);
 
 %% Point tests
@@ -912,7 +906,7 @@
 # sparse save and load tests
 
 gen_save_tests() {
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test # save ascii
 %! savefile = tempname ();
 %! as_save = as;
@@ -957,14 +951,14 @@
 gen_solver_tests() {
 
 if $preset; then
-  cat >>$TESTS <<EOF
+  cat <<EOF
 %! n=8;
 %! lf=diag (1:n); lf(n-1,1)=0.5*alpha; lf(n,2)=0.25*alpha; ls=sparse (lf);
 %! uf=diag (1:n); uf(1,n-1)=2*alpha; uf(2,n)=alpha; us=sparse (uf);
 %! ts=spdiags (ones (n,3),-1:1,n,n) + diag (1:n); tf = full (ts);
 EOF
 else
-  cat >>$TESTS <<EOF
+  cat <<EOF
 %! n = floor (lognrnd (8,2)+1)';
 %! ls = tril (sprandn (8,8,0.2),-1).*alpha + n*speye (8); lf = full (ls);
 %! us = triu (sprandn (8,8,0.2),1).*alpha + n*speye (8); uf = full (us);
@@ -972,7 +966,7 @@
 EOF
 fi
 
-cat >>$TESTS <<EOF
+cat <<EOF
 %! df = diag (1:n).* alpha; ds = sparse (df);
 %! pdf = df(randperm (n), randperm (n));
 %! pds = sparse (pdf);
@@ -1020,7 +1014,7 @@
 
 EOF
 
-cat >>$TESTS <<EOF
+cat <<EOF
 %% QR solver tests
 
 %!function f (a, sz, feps)
@@ -1154,12 +1148,12 @@
 fi
 
 # scalar operations
-echo '%!shared as,af,bs,bf' >> $TESTS
+echo '%!shared as,af,bs,bf'
 if $preset; then
-    echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS
-    echo '%!test bf=3;' >>$TESTS
+    echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];'
+    echo '%!test bf=3;'
 else
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! % generate m,n from 1 to <5000
 %! m = floor (lognrnd (8,2)+1);
@@ -1175,10 +1169,10 @@
 
 # rectangular operations
 if $preset; then
-    echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS
-    echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS
+    echo '%!test af=[1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];'
+    echo '%!test bf=[0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];'
 else
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! m = floor (lognrnd (8,2)+1);
 %! n = floor (lognrnd (8,2)+1);
@@ -1193,27 +1187,27 @@
 gen_section
 gen_save_tests
 gen_section
-echo '%!test bf = real (bf);' >> $TESTS
+echo '%!test bf = real (bf);'
 gen_rectangular_tests
 gen_section
 gen_sparsesparse_ordering_tests
 gen_section
-echo '%!test af = real (af);' >> $TESTS
+echo '%!test af = real (af);'
 gen_rectangular_tests
 gen_section
 gen_save_tests
 gen_section
-echo '%!test bf = bf+1i*(bf!=0);' >> $TESTS
+echo '%!test bf = bf+1i*(bf!=0);'
 gen_rectangular_tests
 gen_section
 
 # square operations
 if $preset; then
-    echo '%!test af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];' >> $TESTS
-    echo '%! as = sparse (af);' >> $TESTS
-    echo '%!test bf = [0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];' >> $TESTS
+    echo '%!test af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];'
+    echo '%! as = sparse (af);'
+    echo '%!test bf = [0,1-1i,0,0;2+1i,0,0,0;3-1i,2+3i,0,0];'
 else
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! m = floor (lognrnd (8,2)+1);
 %! n = floor (lognrnd (8,2)+1);
@@ -1224,7 +1218,7 @@
 EOF
 fi
 
-cat >>$TESTS <<EOF
+cat <<EOF
 %!test ;# invertible matrix
 %! bf = af'*bf+max (abs ([af(:);bf(:)]))*sparse (eye (columns (as)));
 %! bs = sparse (bf);
@@ -1233,48 +1227,48 @@
 
 gen_square_tests
 gen_section
-echo '%!test bf = real (bf);' >> $TESTS
-echo '%! bs = sparse (bf);' >> $TESTS
+echo '%!test bf = real (bf);'
+echo '%! bs = sparse (bf);'
 gen_square_tests
 gen_section
-echo '%!test af = real (af);' >> $TESTS
-echo '%! as = sparse (af);' >> $TESTS
+echo '%!test af = real (af);'
+echo '%! as = sparse (af);'
 gen_square_tests
 gen_section
-echo '%!test bf = bf+1i*(bf!=0);' >> $TESTS
-echo '%! bs = sparse (bf);' >> $TESTS
+echo '%!test bf = bf+1i*(bf!=0);'
+echo '%! bs = sparse (bf);'
 gen_square_tests
 gen_section
 
 # cholesky tests
 if $preset; then
-  echo '%!test bf = [5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];' >> $TESTS
-  echo '%! bs = sparse (bf);' >> $TESTS
+  echo '%!test bf = [5,0,1+1i,0;0,5,0,1-2i;1-1i,0,5,0;0,1+2i,0,5];'
+  echo '%! bs = sparse (bf);'
 else
-  echo '# This has a small chance of failing to create a positive definite matrix' >> $TESTS
-  echo '%!test n = floor (lognrnd (8,2)+1)' >> $TESTS
-  echo '%! bs = n*speye (n,n) + sprandn (n,n,0.3);' >> $TESTS
-  echo '%! bf = full (bs);' >> $TESTS
+  echo '# This has a small chance of failing to create a positive definite matrix'
+  echo '%!test n = floor (lognrnd (8,2)+1)'
+  echo '%! bs = n*speye (n,n) + sprandn (n,n,0.3);'
+  echo '%! bf = full (bs);'
 fi
 
 gen_cholesky_tests
 gen_section
-echo '%!test bf = real (bf);' >> $TESTS
-echo '%! bs = sparse (bf);' >> $TESTS
+echo '%!test bf = real (bf);'
+echo '%! bs = sparse (bf);'
 gen_cholesky_tests
 gen_section
 
 # assembly tests
-echo '%!shared r,c,m,n,fsum,funiq' >>$TESTS
+echo '%!shared r,c,m,n,fsum,funiq'
 if $use_preset; then
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! r = [1,1,2,1,2,3];
 %! c = [2,1,1,1,2,1];
 %! m = n = 0;
 EOF
 else
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! % generate m,n from 1 to <5000
 %! m = floor (lognrnd (8,2)+1);
@@ -1288,16 +1282,16 @@
 gen_section
 
 # slicing tests
-echo '%!shared ridx,cidx,idx,as,af' >>$TESTS
+echo '%!shared ridx,cidx,idx,as,af'
 if $use_preset; then
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! af = [1+1i,2-1i,0,0;0,0,0,3+2i;0,0,0,4];
 %! ridx = [1,3];
 %! cidx = [2,3];
 EOF
 else
-    cat >>$TESTS <<EOF
+    cat <<EOF
 %!test
 %! % generate m,n from 1 to <5000
 %! m = floor (lognrnd (8,2)+1);
@@ -1310,16 +1304,16 @@
 fi
 gen_scalar_select_tests
 gen_select_tests
-echo '%!test af = real (af);' >> $TESTS
+echo '%!test af = real (af);'
 gen_select_tests
 gen_section
-echo '%!shared alpha,beta,df,pdf,lf,plf,uf,puf,bf,cf,bcf,tf,tcf,xf,ds,pds,ls,pls,us,pus,bs,cs,bcs,ts,tcs,xs' >>$TESTS
-echo '%!test alpha=1; beta=1;' >> $TESTS
+echo '%!shared alpha,beta,df,pdf,lf,plf,uf,puf,bf,cf,bcf,tf,tcf,xf,ds,pds,ls,pls,us,pus,bs,cs,bcs,ts,tcs,xs'
+echo '%!test alpha=1; beta=1;'
 gen_solver_tests
-echo '%!test alpha=1; beta=1i;' >> $TESTS
+echo '%!test alpha=1; beta=1i;'
 gen_solver_tests
-echo '%!test alpha=1i; beta=1;' >> $TESTS
+echo '%!test alpha=1i; beta=1;'
 gen_solver_tests
-echo '%!test alpha=1i; beta=1i;' >> $TESTS
+echo '%!test alpha=1i; beta=1i;'
 gen_solver_tests
 gen_section