Mercurial > hg > octave-nkf
changeset 16170:2a4f83826024
new way to test for features in Octave scripts
* __have_feature__.m: New file.
* test.m, geometryimages.m, sparseimages.m: Use it. Delete tests for
testif and xfail.
* config-features.sh: New file.
* libinterp/Makefile.am (EXTRA_DIST): Include config-features.sh in
the list.
(oct-conf-features.h): New target.
(BUILT_NODISTFILES, nodist_liboctinterp_la_SOURCES): Include
oct-conf-features.h in the list.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 02 Mar 2013 07:41:50 -0500 |
parents | 0303fda3e929 |
children | cf6788da4152 |
files | doc/interpreter/geometryimages.m doc/interpreter/sparseimages.m libinterp/Makefile.am libinterp/config-features.sh libinterp/interpfcn/toplev.cc libinterp/octave-value/ov-fcn-handle.cc scripts/testfun/__have_feature__.m scripts/testfun/test.m |
diffstat | 8 files changed, 102 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/geometryimages.m +++ b/doc/interpreter/geometryimages.m @@ -29,7 +29,7 @@ d_typ = cstrcat ("-d", typ); endif - if (isempty (findstr (octave_config_info ("DEFS"), "HAVE_QHULL")) + if (! __have_feature__ ("QHULL") && (strcmp (nm, "voronoi") || strcmp (nm, "griddata") || strcmp (nm, "convhull") || strcmp (nm, "delaunay") || strcmp (nm, "triplot")))
--- a/doc/interpreter/sparseimages.m +++ b/doc/interpreter/sparseimages.m @@ -23,9 +23,9 @@ set (0, "defaulttextfontname", "*"); endif - if (! isempty (findstr (octave_config_info ("DEFS"), "HAVE_COLAMD")) - && ! isempty (findstr (octave_config_info ("DEFS"), "HAVE_CHOLMOD")) - && ! isempty (findstr (octave_config_info ("DEFS"), "HAVE_UMFPACK"))) + if (__have_feature__ ("COLAMD") + && __have_feature__ ("CHOLMOD") + && __have_feature__ ("UMFPACK")) if (strcmp(typ,"txt")) txtimages (nm, 15, typ); else @@ -86,8 +86,8 @@ elseif (strcmp (nm, "spmatrix")) printsparse(a,cstrcat("spmatrix.",typ)); else - if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_COLAMD")) && - !isempty(findstr(octave_config_info ("DEFS"),"HAVE_CHOLMOD"))) + if (__have_feature__ ("COLAMD") + && __have_feature__ ("CHOLMOD")) if (strcmp (nm, "spchol")) r1 = chol(a); printsparse(r1,cstrcat("spchol.",typ)); @@ -116,8 +116,8 @@ print(cstrcat("spmatrix.",typ), d_typ) hide_output (); else - if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_COLAMD")) && - !isempty(findstr(octave_config_info ("DEFS"),"HAVE_CHOLMOD"))) + if (__have_feature__ ("COLAMD") + && __have_feature__ ("CHOLMOD")) if (strcmp (nm, "spchol")) r1 = chol(a); spy(r1); @@ -182,9 +182,9 @@ d_typ = cstrcat ("-d", typ); endif - if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_COLAMD")) && - !isempty(findstr(octave_config_info ("DEFS"),"HAVE_CHOLMOD")) && - !isempty(findstr(octave_config_info ("DEFS"),"HAVE_UMFPACK"))) + if (__have_feature__ ("COLAMD") + && __have_feature__ ("CHOLMOD") + && __have_feature__ ("UMFPACK")) ## build a rectangle node_y = [1;1.2;1.5;1.8;2]*ones(1,11); node_x = ones(5,1)*[1,1.05,1.1,1.2,1.3,1.5,1.7,1.8,1.9,1.95,2];
--- a/libinterp/Makefile.am +++ b/libinterp/Makefile.am @@ -58,6 +58,7 @@ parse-tree/oct-gperf.h \ parse-tree/oct-parse.cc \ oct-conf.h \ + oct-conf-features.h \ version.h \ builtin-defun-decls.h \ builtins.cc @@ -76,6 +77,7 @@ builtin-defun-decls.h \ operators/ops.cc \ oct-conf.h \ + oct-conf-features.h \ version.h \ $(OPT_HANDLERS) \ $(OPT_INC) \ @@ -85,6 +87,7 @@ EXTRA_DIST = \ Makefile.in \ DOCSTRINGS \ + config-featurs.sh \ find-defun-files.sh \ gendoc.pl \ genprops.awk \ @@ -162,6 +165,7 @@ builtin-defun-decls.h \ builtins.cc \ oct-conf.h \ + oct-conf-features.h \ version.h \ $(OPT_INC) @@ -256,6 +260,10 @@ oct-conf.h: oct-conf.in.h Makefile @$(do_subst_config_vals) +oct-conf-features.h: $(top_builddir)/config.h config-features.sh + $(srcdir)/config-features.sh $< > $@-t + mv $@-t $@ + version.h: version.in.h Makefile $(SED) < $< \ -e "s|%NO_EDIT_WARNING%|DO NOT EDIT! Generated automatically from $(<F) by Make.|" \
new file mode 100755 --- /dev/null +++ b/libinterp/config-features.sh @@ -0,0 +1,36 @@ +#! /bin/sh + +set -e +AWK=${AWK:-awk} + +conffile=$1 + +cat << EOF +// DO NOT EDIT! Generated automatically from $conffile by Make." + +#include "oct-map.h" +#include "ov.h" + +octave_scalar_map +octave_config_features (void) +{ + octave_scalar_map m; + +EOF + +$AWK \ + '/#define HAVE_/ { + sub (/HAVE_/, "", $2); + printf (" m.assign (\"%s\", octave_value (true));\n", $2); + } + /\/\* #undef HAVE_/ { + sub (/HAVE_/, "", $3); + printf (" m.assign (\"%s\", octave_value (false));\n", $3); + } { + }' $conffile + +cat << EOF + + return m; +} +EOF
--- a/libinterp/interpfcn/toplev.cc +++ b/libinterp/interpfcn/toplev.cc @@ -57,6 +57,7 @@ #include "input.h" #include "lex.h" #include "oct-conf.h" +#include "oct-conf-features.h" #include "oct-hist.h" #include "oct-map.h" #include "oct-obj.h" @@ -1442,6 +1443,8 @@ m.assign ("words_little_endian", octave_value (oct_mach_info::words_little_endian ())); + m.assign ("features", octave_value (octave_config_features ())); + int i = 0; while (true)
--- a/libinterp/octave-value/ov-fcn-handle.cc +++ b/libinterp/octave-value/ov-fcn-handle.cc @@ -1304,7 +1304,8 @@ %! hdld2 = hdld; %! hbi2 = hbi; %! modes = {"-text", "-binary"}; -%! if (!isempty (findstr (octave_config_info ("DEFS"), "HAVE_HDF5"))) +%! if (isfield (octave_config_info, "HAVE_HDF5") +%! && octave_config_info ("HAVE_HDF5")) %! modes(end+1) = "-hdf5"; %! endif %! for i = 1:numel (modes) @@ -1356,7 +1357,8 @@ %! hdld2 = hdld; %! hbi2 = hbi; %! modes = {"-text", "-binary"}; -%! if (!isempty (findstr (octave_config_info ("DEFS"), "HAVE_HDF5"))) +%! if (isfield (octave_config_info, "HAVE_HDF5") +%! && octave_config_info ("HAVE_HDF5")) %! modes(end+1) = "-hdf5"; %! endif %! for i = 1:numel (modes)
new file mode 100644 --- /dev/null +++ b/scripts/testfun/__have_feature__.m @@ -0,0 +1,34 @@ +## Copyright (C) 2013 John W. Eaton +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {} __have_feature__ (feature) +## Undocumented internal function. +## @end deftypefn + +function retval = __have_feature__ (feature) + features = octave_config_info ("features"); + if (iscellstr (feature)) + retval = (all (isfield (features, feature)) + && cellfun (@(x) features.(x), feature)); + elseif (ischar (feature)) + retval = isfield (features, feature) && features.(feature); + else + retval = false; + endif +endfunction
--- a/scripts/testfun/test.m +++ b/scripts/testfun/test.m @@ -463,15 +463,16 @@ ## Strip comment any comment from testif line before looking for features __feat_line = strtok (__code(1:__e), '#%'); __feat = regexp (__feat_line, '\w+', 'match'); - __have_feat = strfind (octave_config_info ("DEFS"), __feat); - if (any (cellfun ("isempty", __have_feat))) + __feat = strrep (__feat, "HAVE_", ""); + __have_feat = __have_feature__ (__feat); + if (__have_feat) + __istest = 1; + __code = __code(__e + 1 : end); + else __xskip++; __istest = 0; __code = ""; # Skip the code. __msg = sprintf ("%sskipped test\n", __signal_skip); - else - __istest = 1; - __code = __code(__e + 1 : end); endif ### TEST @@ -679,19 +680,6 @@ endif endfunction -### Test for test for missing features -%!testif OCTAVE_SOURCE -%! ## This test should be run -%! assert (true); - -### Disable this test to avoid spurious skipped test for "make check" -% !testif HAVE_FOOBAR -% ! ## missing feature. Fail if this test is run -% ! error ("Failed missing feature test"); - -### Test for a known failure -%!xtest error ("This test is known to fail") - ### example from toeplitz %!shared msg1,msg2 %! msg1="C must be a vector";