# HG changeset patch # User John W. Eaton # Date 1360360394 18000 # Node ID 5b2126a8c84fa4624c737e5921362b79a0e879d4 # Parent e0df71fbe39bbba493a5e3f476a711dd9c0e0a86 install tests and functions to run them * configure.ac (octtestsdir): New variable. * build-aux/common.mk (octtestsdir): New variable. (do_subst_default_vals): Substitute it. (test-file-commands): New macro. (%.cc-tst:%.cc, %.yy-tst:%.yy, %.ll-tst:%.ll): New rules. * libinterp/Makefile.am (TST_FILES_SRC, TST_FILES, libinterptestsdir, nobase_libinterptests_DATA): New variables. * defaults.in.h (OCTAVE_OCTTESTSDIR): New macro. * liboctave/Makefile.am (LIBOCTAVE_TST_SRC, TST_FILES_SRC, TST_FILES, liboctavetestsdir, nobase_liboctavetests_DATA): New variables. * toplev.cc (Foctave_config_info): Include octtestsdir in the struct. * fntests.m: Look in topbuilddir for C++ test files. * __run_test_suite__.m: New function, extracted from test/fntests.m. Look for -tst files, not .cc files. Don't report -tst files that are missing tests (there won't be any). * __prog_output_assert__.m, __printf_assert__.m: New functions, extracted from __run_test_suite__.m and renamed from prog_output_assert and printf_assert. Change all uses. * scripts/testfun/module.mk (testfun_FCN_FILES): Include new files in the list. * test/Makefile.am (GENERATED_BC_OVERLOADS_DIRS, GENERATED_BC_OVERLOADS_FILES, fixedtestsdir, nobase_fixedtests_DATA): New variables. (CLEANFILES): Include $(GENERATED_BC_OVERRLOADS_FILES) in the list. (clean-local): Use $(GENERATED_BC_OVERLOADS_DIRS). * build_bc_overload_tests.sh: New options, --list-files, --list-dirs, and --list-classes. * test/classes/module.mk (classes_FCN_FILES): Include recently added .m files in the list. * test.m: Use "var" argument for exist in tests. diff -r e0df71fbe39b -r 5b2126a8c84f build-aux/common.mk --- a/build-aux/common.mk Fri Feb 08 16:05:04 2013 +0100 +++ b/build-aux/common.mk Fri Feb 08 16:53:14 2013 -0500 @@ -363,6 +363,9 @@ man1dir = @man1dir@ man1ext = @man1ext@ +# Where to install test files. +octtestsdir = @octtestsdir@ + # The full path to the default doc cache file. doc_cache_file = @doc_cache_file@ @@ -677,6 +680,7 @@ -e "s|%OCTAVE_OCTINCLUDEDIR%|\"${octincludedir}\"|" \ -e "s|%OCTAVE_OCTLIBDIR%|\"${octlibdir}\"|" \ -e "s|%OCTAVE_OCTLOCALEDIR%|\"${octlocaledir}\"|" \ + -e "s|%OCTAVE_OCTTESTSDIR%|\"${octtestsdir}\"|" \ -e "s|%OCTAVE_STARTUPFILEDIR%|\"${startupfiledir}\"|" \ -e "s|%OCTAVE_PREFIX%|\"${prefix}\"|" \ -e "s|%OCTAVE_API_VERSION%|\"${api_version}\"|" \ @@ -725,3 +729,17 @@ rm -f $(DESTDIR)$(fcnfiledir)/$(script_sub_dir)/PKG_ADD -rmdir $(DESTDIR)$(fcnfiledir)/$(script_sub_dir) endef + +define test-file-commands +( echo "## DO NOT EDIT! Generated automatically from $( $@-t +mv $@-t $@ +endef + +%.cc-tst : %.cc + $(test-file-commands) + +%.yy-tst : %.yy + $(test-file-commands) + +%.ll-tst : %.ll + $(test-file-commands) diff -r e0df71fbe39b -r 5b2126a8c84f configure.ac --- a/configure.ac Fri Feb 08 16:05:04 2013 +0100 +++ b/configure.ac Fri Feb 08 16:53:14 2013 -0500 @@ -82,6 +82,7 @@ OCTAVE_SET_DEFAULT([octetcdir], '$(datadir)/octave/$(version)/etc') OCTAVE_SET_DEFAULT([octlocaledir], '$(datadir)/octave/$(version)/locale') OCTAVE_SET_DEFAULT([doc_cache_file], '$(octetcdir)/doc-cache') +OCTAVE_SET_DEFAULT([octtestsdir], '$(octetcdir)/tests') OCTAVE_SET_DEFAULT([texi_macros_file], '$(octetcdir)/macros.texi') OCTAVE_SET_DEFAULT([imagedir], '$(datadir)/octave/$(version)/imagelib') OCTAVE_SET_DEFAULT([man1dir], '$(mandir)/man1') diff -r e0df71fbe39b -r 5b2126a8c84f libinterp/Makefile.am --- a/libinterp/Makefile.am Fri Feb 08 16:05:04 2013 +0100 +++ b/libinterp/Makefile.am Fri Feb 08 16:53:14 2013 -0500 @@ -230,6 +230,16 @@ -DMAKE_BUILTINS $< | $(srcdir)/mkdefs $(srcdir) $< > $@-t mv $@-t $@ +## Rules to build test files + +TST_FILES_SRC := $(shell $(top_srcdir)/build-aux/find-files-with-tests.sh "$(srcdir)" $(DIST_SRC) $(DLDFCN_SRC)) + +TST_FILES := $(addsuffix -tst,$(TST_FILES_SRC)) + +libinterptestsdir := $(octtestsdir)/libinterp + +nobase_libinterptests_DATA = $(TST_FILES) + ## Override Automake's rule that forces a .hh extension on us even ## though we don't want it. It would be super awesome if automake ## would allow users to choose the header file extension. diff -r e0df71fbe39b -r 5b2126a8c84f libinterp/interpfcn/defaults.in.h --- a/libinterp/interpfcn/defaults.in.h Fri Feb 08 16:05:04 2013 +0100 +++ b/libinterp/interpfcn/defaults.in.h Fri Feb 08 16:53:14 2013 -0500 @@ -168,6 +168,10 @@ #define OCTAVE_OCTLIBDIR %OCTAVE_OCTLIBDIR% #endif +#ifndef OCTAVE_OCTTESTSDIR +#define OCTAVE_OCTTESTSDIR %OCTAVE_OCTTESTSDIR% +#endif + #ifndef OCTAVE_PREFIX #define OCTAVE_PREFIX %OCTAVE_PREFIX% #endif diff -r e0df71fbe39b -r 5b2126a8c84f libinterp/interpfcn/toplev.cc --- a/libinterp/interpfcn/toplev.cc Fri Feb 08 16:05:04 2013 +0100 +++ b/libinterp/interpfcn/toplev.cc Fri Feb 08 16:53:14 2013 -0500 @@ -1414,6 +1414,7 @@ { true, "octetcdir", OCTAVE_OCTETCDIR }, { true, "octincludedir", OCTAVE_OCTINCLUDEDIR }, { true, "octlibdir", OCTAVE_OCTLIBDIR }, + { true, "octtestsdir", OCTAVE_OCTTESTSDIR }, { true, "prefix", OCTAVE_PREFIX }, { true, "startupfiledir", OCTAVE_STARTUPFILEDIR }, { false, "version", OCTAVE_VERSION }, diff -r e0df71fbe39b -r 5b2126a8c84f liboctave/Makefile.am --- a/liboctave/Makefile.am Fri Feb 08 16:05:04 2013 +0100 +++ b/liboctave/Makefile.am Fri Feb 08 16:53:14 2013 -0500 @@ -75,6 +75,8 @@ ## C++ files with templates that are #included, not compiled TEMPLATE_SRC = +## A list of all files that could include tests + include array/module.mk include numeric/module.mk include operators/module.mk @@ -117,5 +119,21 @@ -bindir $(bindir) \ $(LIBOCTAVE_LINK_OPTS) +## Rules to build test files + +LIBOCTAVE_TST_SRC = \ + $(array_libarray_la_SOURCES) \ + $(numeric_libnumeric_la_SOURCES) \ + $(system_libsystem_la_SOURCES) \ + $(util_libutil_la_SOURCES) + +TST_FILES_SRC := $(shell $(top_srcdir)/build-aux/find-files-with-tests.sh "$(srcdir)" $(LIBOCTAVE_TST_SRC)) + +TST_FILES := $(addsuffix -tst,$(TST_FILES_SRC)) + +liboctavetestsdir := $(octtestsdir)/liboctave + +nobase_liboctavetests_DATA = $(TST_FILES) + DISTCLEANFILES += $(BUILT_INCS) diff -r e0df71fbe39b -r 5b2126a8c84f scripts/testfun/__printf_assert__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/__printf_assert__.m Fri Feb 08 16:53:14 2013 -0500 @@ -0,0 +1,27 @@ +## Copyright (C) 2005-2012 David Bateman +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __printf_assert__ (@dots{}) +## Undocumented internal function. +## @end deftypefn + +function __printf_assert__ (varargin) + global _assert_printf; + _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); +endfunction diff -r e0df71fbe39b -r 5b2126a8c84f scripts/testfun/__prog_output_assert__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/__prog_output_assert__.m Fri Feb 08 16:53:14 2013 -0500 @@ -0,0 +1,34 @@ +## Copyright (C) 2005-2012 David Bateman +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __prog_output_assert__ (@var{str}) +## Undocumented internal function. +## @end deftypefn + +function ret = __prog_output_assert__ (str) + global _assert_printf; + if (isempty (_assert_printf)) + ret = isempty (str); + elseif (_assert_printf(end) == "\n") + ret = strcmp (_assert_printf(1:(end-1)), str); + else + ret = strcmp (_assert_printf, str); + endif + _assert_printf = ""; +endfunction diff -r e0df71fbe39b -r 5b2126a8c84f scripts/testfun/__run_test_suite__.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/testfun/__run_test_suite__.m Fri Feb 08 16:53:14 2013 -0500 @@ -0,0 +1,284 @@ +## Copyright (C) 2005-2012 David Bateman +## +## 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 +## . + +## -*- texinfo -*- +## @deftypefn {Function File} {} __run_test_suite__ (@var{fcndirs}, @var{fixedtestdirs}) +## Undocumented internal function. +## @end deftypefn + +function __run_test_suite__ (fcndirs, fixedtestdirs) + testsdir = octave_config_info ("octtestsdir"); + libinterptestdir = fullfile (testsdir, "libinterp") + liboctavetestdir = fullfile (testsdir, "liboctave") + fixedtestdir = fullfile (testsdir, "fixed"); + fcnfiledir = octave_config_info ("fcnfiledir"); + if (nargin == 0) + fcndirs = { libinterptestdir, liboctavetestdir, fcnfiledir }; + fixedtestdirs = { fixedtestdir }; + endif + global files_with_no_tests = {}; + global files_with_tests = {}; + ## FIXME -- these names don't really make sense if we are running + ## tests for an installed copy of Octave. + global topsrcdir = fcnfiledir; + global topbuilddir = testsdir; + pso = page_screen_output (); + warn_state = warning ("query", "quiet"); + warning ("on", "quiet"); + try + page_screen_output (0); + warning ("off", "Octave:deprecated-function"); + fid = fopen ("fntests.log", "wt"); + if (fid < 0) + error ("could not open fntests.log for writing"); + endif + test ("", "explain", fid); + dp = dn = dxf = dsk = 0; + puts ("\nIntegrated test scripts:\n\n"); + for i = 1:length (fcndirs) + [p, n, xf, sk] = run_test_script (fid, fcndirs{i}); + dp += p; + dn += n; + dxf += xf; + dsk += sk; + endfor + puts ("\nFixed test scripts:\n\n"); + for i = 1:length (fixedtestdirs) + [p, n, xf, sk] = run_test_dir (fid, fixedtestdirs{i}); + dp += p; + dn += n; + dxf += xf; + dsk += sk; + endfor + puts ("\nSummary:\n\n"); + nfail = dn - dp; + printf (" PASS %6d\n", dp); + printf (" FAIL %6d\n", nfail); + if (dxf > 0) + printf (" XFAIL %6d\n", dxf); + endif + if (dsk > 0) + printf (" SKIPPED %6d\n", dsk); + endif + puts ("\n"); + puts ("See the file test/fntests.log for additional details.\n"); + if (dxf > 0) + puts ("\n"); + puts ("Expected failures (listed as XFAIL above) are known bugs.\n"); + puts ("Please help improve Octave by contributing fixes for them.\n"); + endif + if (dsk > 0) + puts ("\n"); + puts ("Tests are most often skipped because the features they require\n"); + puts ("have been disabled. Features are most often disabled because\n"); + puts ("they require dependencies that were not present when Octave\n"); + puts ("was built. The configure script should have printed a summary\n"); + puts ("at the end of its run indicating which dependencies were not found.\n"); + endif + + ## Weed out deprecated and private functions + weed_idx = cellfun (@isempty, regexp (files_with_tests, '\bdeprecated\b|\bprivate\b', 'once')); + files_with_tests = files_with_tests(weed_idx); + weed_idx = cellfun (@isempty, regexp (files_with_no_tests, '\bdeprecated\b|\bprivate\b', 'once')); + files_with_no_tests = files_with_no_tests(weed_idx); + + report_files_with_no_tests (files_with_tests, files_with_no_tests, ".m"); + + puts ("\nPlease help improve Octave by contributing tests for\n"); + puts ("these files (see the list in the file fntests.log).\n\n"); + + fprintf (fid, "\nFiles with no tests:\n\n%s", + list_in_columns (files_with_no_tests, 80)); + fclose (fid); + + page_screen_output (pso); + warning (warn_state.state, "quiet"); + catch + page_screen_output (pso); + warning (warn_state.state, "quiet"); + disp (lasterr ()); + end_try_catch +endfunction + +function print_test_file_name (nm) + filler = repmat (".", 1, 55-length (nm)); + printf (" %s %s", nm, filler); +endfunction + +function print_pass_fail (n, p) + if (n > 0) + printf (" PASS %4d/%-4d", p, n); + nfail = n - p; + if (nfail > 0) + printf (" FAIL %d", nfail); + endif + endif + puts ("\n"); +endfunction + +function retval = has_functions (f) + n = length (f); + if (n > 3 && strcmp (f((end-2):end), ".cc")) + fid = fopen (f); + if (fid >= 0) + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\b', 'lineanchors')); + else + error ("fopen failed: %s", f); + endif + elseif (n > 2 && strcmp (f((end-1):end), ".m")) + retval = true; + else + retval = false; + endif +endfunction + +function retval = has_tests (f) + fid = fopen (f); + if (fid >= 0) + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str, '^%!(assert|error|fail|test|warning)', "lineanchors")); + else + error ("fopen failed: %s", f); + endif +endfunction + +function retval = has_demos (f) + fid = fopen (f); + if (fid >= 0) + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str, '^%!demo', "lineanchors")); + else + error ("fopen failed: %s", f); + endif +endfunction + +function [dp, dn, dxf, dsk] = run_test_dir (fid, d); + global files_with_tests; + global files_with_no_tests; + lst = dir (d); + dp = dn = dxf = dsk = 0; + for i = 1:length (lst) + nm = lst(i).name; + if (lst(i).isdir + && ! strcmp (nm, ".") && ! strcmp (nm, "..") + && ! strcmp (nm, "private") && nm(1) != "@" + && ! strcmp (nm, "CVS")) + [p, n, xf, sk] = run_test_dir (fid, [d, filesep, nm]); + dp += p; + dn += n; + dxf += xf; + dsk += sk; + endif + endfor + saved_dir = pwd (); + unwind_protect + chdir (d); + for i = 1:length (lst) + nm = lst(i).name; + if (length (nm) > 5 && strcmp (nm(1:5), "test_") + && strcmp (nm((end-1):end), ".m")) + p = n = xf = sk = 0; + ffnm = fullfile (d, nm); + if (has_tests (ffnm)) + print_test_file_name (nm); + [p, n, xf, sk] = test (nm(1:(end-2)), "quiet", fid); + print_pass_fail (n, p); + files_with_tests(end+1) = ffnm; + ##elseif (has_demos (ffnm)) + ## files_with_tests(end+1) = ffnm; + else + files_with_no_tests(end+1) = ffnm; + endif + dp += p; + dn += n; + dxf += xf; + dsk += sk; + endif + endfor + unwind_protect_cleanup + chdir (saved_dir); + end_unwind_protect +endfunction + +function [dp, dn, dxf, dsk] = run_test_script (fid, d); + global files_with_tests; + global files_with_no_tests; + global topsrcdir; + global topbuilddir; + lst = dir (d); + dp = dn = dxf = dsk = 0; + for i = 1:length (lst) + nm = lst(i).name; + if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") + && ! strcmp (nm, "CVS")) + [p, n, xf, sk] = run_test_script (fid, [d, filesep, nm]); + dp += p; + dn += n; + dxf += xf; + dsk += sk; + endif + endfor + for i = 1:length (lst) + nm = lst(i).name; + ## Ignore hidden files + if (nm(1) == '.') + continue + endif + f = fullfile (d, nm); + if ((length (nm) > 2 && strcmp (nm((end-1):end), ".m")) || + (length (nm) > 4 && strcmp (nm((end-3):end), "-tst"))) + p = n = xf = 0; + ## Only run if it contains %!test, %!assert %!error or %!warning + if (has_tests (f)) + tmp = strrep (f, [topsrcdir, filesep], ""); + tmp = strrep (tmp, [topbuilddir, filesep], ""); + print_test_file_name (tmp); + [p, n, xf, sk] = test (f, "quiet", fid); + print_pass_fail (n, p); + dp += p; + dn += n; + dxf += xf; + dsk += sk; + files_with_tests(end+1) = f; + ##elseif (has_demos (f)) + ## files_with_tests(end+1) = f; + else + ## To reduce the list length, only mark .cc files that contain + ## DEFUN definitions. + files_with_no_tests(end+1) = f; + endif + endif + endfor + ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); +endfunction + +function n = num_elts_matching_pattern (lst, pat) + n = sum (cellfun (@(x) !isempty (x), regexp (lst, pat, 'once'))); +endfunction + +function report_files_with_no_tests (with, without, typ) + pat = cstrcat ('\', typ, "$"); + n_with = num_elts_matching_pattern (with, pat); + n_without = num_elts_matching_pattern (without, pat); + n_tot = n_with + n_without; + printf ("\n%d (of %d) %s files have no tests.\n", n_without, n_tot, typ); +endfunction diff -r e0df71fbe39b -r 5b2126a8c84f scripts/testfun/module.mk --- a/scripts/testfun/module.mk Fri Feb 08 16:05:04 2013 +0100 +++ b/scripts/testfun/module.mk Fri Feb 08 16:53:14 2013 -0500 @@ -1,6 +1,9 @@ FCN_FILE_DIRS += testfun testfun_FCN_FILES = \ + testfun/__printf_assert__.m \ + testfun/__prog_output_assert__.m \ + testfun/__run_test_suite__.m \ testfun/assert.m \ testfun/demo.m \ testfun/example.m \ diff -r e0df71fbe39b -r 5b2126a8c84f scripts/testfun/test.m --- a/scripts/testfun/test.m Fri Feb 08 16:05:04 2013 +0100 +++ b/scripts/testfun/test.m Fri Feb 08 16:53:14 2013 -0500 @@ -771,7 +771,7 @@ %!test a=3; # assign to a shared variable %!test assert (a,3) # variable should equal 3 %!shared b,c # replace shared variables -%!test assert (!exist ("a")); # a no longer exists +%!test assert (!exist ("a", "var")); # a no longer exists %!test assert (isempty (b)); # variables start off empty %!shared a,b,c # recreate a shared variable %!test assert (isempty (a)); # value is empty even if it had a previous value @@ -780,7 +780,7 @@ %!test c=6; # update a value %!test assert ([a, b, c],[1, 2, 6]); # show that the update sticks %!shared # clear all shared variables -%!test assert (!exist ("a")) # show that they are cleared +%!test assert (!exist ("a", "var")) # show that they are cleared %!shared a,b,c # support for initializer shorthand %! a=1; b=2; c=4; @@ -835,7 +835,7 @@ % !demo with syntax error # syntax errors in demo fail properly % !shared a,b,c % !demo # shared variables not available in demo -% ! assert(exist("a")) +% ! assert(exist("a", "var")) % !error % ! test('/etc/passwd'); % ! test("nonexistent file"); diff -r e0df71fbe39b -r 5b2126a8c84f test/Makefile.am --- a/test/Makefile.am Fri Feb 08 16:05:04 2013 +0100 +++ b/test/Makefile.am Fri Feb 08 16:53:14 2013 -0500 @@ -68,6 +68,12 @@ test_bc_overloads.m: build_bc_overload_tests.sh bc_overloads_expected $(srcdir)/build_bc_overload_tests.sh $(srcdir)/bc_overloads_expected +GENERATED_BC_OVERLOADS_DIRS := \ + $(shell $(srcdir)/build_bc_overload_tests.sh --list-dirs) + +GENERATED_BC_OVERLOADS_FILES := \ + $(shell $(srcdir)/build_bc_overload_tests.sh --list-files) + EXTRA_DIST = \ build_sparse_tests.sh \ build_bc_overload_tests.sh \ @@ -77,12 +83,17 @@ CLEANFILES = \ test_sparse.m \ - test_bc_overloads.m \ - tbcover.m + $(GENERATED_BC_OVERRLOADS_FILES) DISTCLEANFILES = \ fntests.log - + +fixedtestsdir := $(octtestsdir)/fixed + +nobase_fixedtests_DATA = \ + test_sparse.m \ + $(GENERATED_BC_OVERLOADS_FILES) \ + $(filter-out fntests.m, $(FCN_FILES)) + clean-local: - -rm -rf @double @logical @int8 @uint64 @int64 @cell @single @int32 \ - @uint8 @uint16 @uint32 @struct @int16 @function_handle @char + -rm -rf $(GENERATED_BC_OVERLOADS_DIRS) diff -r e0df71fbe39b -r 5b2126a8c84f test/build_bc_overload_tests.sh --- a/test/build_bc_overload_tests.sh Fri Feb 08 16:05:04 2013 +0100 +++ b/test/build_bc_overload_tests.sh Fri Feb 08 16:53:14 2013 -0500 @@ -37,7 +37,28 @@ " if [ $# -eq 1 ]; then - expected_results_file="$1" + case "$1" in + --list-files) + echo tbcover.m test_bc_overloads.m + for class in $CLASSES; do + echo @$class/tbcover.m + done + exit + ;; + --list-dirs) + for class in $CLASSES; do + echo @$class + done + exit + ;; + --list-classes) + echo $CLASSES + exit + ;; + *) + expected_results_file="$1" + ;; + esac else echo "usage: build_bc_overload_tests.sh expected-results-file" 1>&2 exit 1 diff -r e0df71fbe39b -r 5b2126a8c84f test/classes/module.mk --- a/test/classes/module.mk Fri Feb 08 16:05:04 2013 +0100 +++ b/test/classes/module.mk Fri Feb 08 16:53:14 2013 -0500 @@ -37,17 +37,39 @@ classes/@Snork/Snork.m \ classes/@Snork/cack.m \ classes/@Snork/display.m \ + classes/@Snork/double.m \ classes/@Snork/end.m \ + classes/@Snork/eq.m \ + classes/@Snork/fdisp.m \ + classes/@Snork/ge.m \ classes/@Snork/get.m \ classes/@Snork/getStash.m \ classes/@Snork/gick.m \ + classes/@Snork/gt.m \ + classes/@Snork/horzcat.m \ + classes/@Snork/ldivide.m \ + classes/@Snork/le.m \ classes/@Snork/loadobj.m \ + classes/@Snork/lt.m \ + classes/@Snork/minus.m \ + classes/@Snork/mldivide.m \ + classes/@Snork/mpower.m \ + classes/@Snork/mrdivide.m \ + classes/@Snork/mtimes.m \ + classes/@Snork/ne.m \ + classes/@Snork/plus.m \ + classes/@Snork/power.m \ classes/@Snork/private/myStash.m \ + classes/@Snork/rdivide.m \ classes/@Snork/saveobj.m \ classes/@Snork/set.m \ classes/@Snork/subsasgn.m \ classes/@Snork/subsindex.m \ classes/@Snork/subsref.m \ + classes/@Snork/times.m \ + classes/@Snork/uminus.m \ + classes/@Snork/uplus.m \ + classes/@Snork/vertcat.m \ classes/@Spork/Spork.m \ classes/@Spork/cack.m \ classes/@Spork/display.m \ diff -r e0df71fbe39b -r 5b2126a8c84f test/fntests.m --- a/test/fntests.m Fri Feb 08 16:05:04 2013 +0100 +++ b/test/fntests.m Fri Feb 08 16:53:14 2013 -0500 @@ -41,8 +41,8 @@ testdirs = {currdir, srcdir}; endif -src_tree = canonicalize_file_name (fullfile (topsrcdir, "libinterp")); -liboctave_tree = canonicalize_file_name (fullfile (topsrcdir, "liboctave")); +src_tree = canonicalize_file_name (fullfile (topbuilddir, "libinterp")); +liboctave_tree = canonicalize_file_name (fullfile (topbuilddir, "liboctave")); script_tree = canonicalize_file_name (fullfile (topsrcdir, "scripts")); local_script_tree = canonicalize_file_name (fullfile (currdir, "../scripts")); @@ -52,265 +52,4 @@ fundirs{end+1} = local_script_tree; endif -function print_test_file_name (nm) - filler = repmat (".", 1, 55-length (nm)); - printf (" %s %s", nm, filler); -endfunction - -function print_pass_fail (n, p) - if (n > 0) - printf (" PASS %4d/%-4d", p, n); - nfail = n - p; - if (nfail > 0) - printf (" FAIL %d", nfail); - endif - endif - puts ("\n"); -endfunction - -function retval = has_functions (f) - n = length (f); - if (n > 3 && strcmp (f((end-2):end), ".cc")) - fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char")'; - fclose (fid); - retval = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\b', 'lineanchors')); - else - error ("fopen failed: %s", f); - endif - elseif (n > 2 && strcmp (f((end-1):end), ".m")) - retval = true; - else - retval = false; - endif -endfunction - -function retval = has_tests (f) - fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char")'; - fclose (fid); - retval = ! isempty (regexp (str, '^%!(assert|error|fail|test|warning)', "lineanchors")); - else - error ("fopen failed: %s", f); - endif -endfunction - -function retval = has_demos (f) - fid = fopen (f); - if (fid >= 0) - str = fread (fid, "*char")'; - fclose (fid); - retval = ! isempty (regexp (str, '^%!demo', "lineanchors")); - else - error ("fopen failed: %s", f); - endif -endfunction - -function [dp, dn, dxf, dsk] = run_test_dir (fid, d); - global files_with_tests; - global files_with_no_tests; - lst = dir (d); - dp = dn = dxf = dsk = 0; - for i = 1:length (lst) - nm = lst(i).name; - if (lst(i).isdir - && ! strcmp (nm, ".") && ! strcmp (nm, "..") - && ! strcmp (nm, "private") && nm(1) != "@" - && ! strcmp (nm, "CVS")) - [p, n, xf, sk] = run_test_dir (fid, [d, filesep, nm]); - dp += p; - dn += n; - dxf += xf; - dsk += sk; - endif - endfor - saved_dir = pwd (); - unwind_protect - chdir (d); - for i = 1:length (lst) - nm = lst(i).name; - if (length (nm) > 5 && strcmp (nm(1:5), "test_") - && strcmp (nm((end-1):end), ".m")) - p = n = xf = sk = 0; - ffnm = fullfile (d, nm); - if (has_tests (ffnm)) - print_test_file_name (nm); - [p, n, xf, sk] = test (nm(1:(end-2)), "quiet", fid); - print_pass_fail (n, p); - files_with_tests(end+1) = ffnm; - ##elseif (has_demos (ffnm)) - ## files_with_tests(end+1) = ffnm; - else - files_with_no_tests(end+1) = ffnm; - endif - dp += p; - dn += n; - dxf += xf; - dsk += sk; - endif - endfor - unwind_protect_cleanup - chdir (saved_dir); - end_unwind_protect -endfunction - -function [dp, dn, dxf, dsk] = run_test_script (fid, d); - global files_with_tests; - global files_with_no_tests; - global topsrcdir; - global topbuilddir; - lst = dir (d); - dp = dn = dxf = dsk = 0; - for i = 1:length (lst) - nm = lst(i).name; - if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") - && ! strcmp (nm, "CVS")) - [p, n, xf, sk] = run_test_script (fid, [d, filesep, nm]); - dp += p; - dn += n; - dxf += xf; - dsk += sk; - endif - endfor - for i = 1:length (lst) - nm = lst(i).name; - ## Ignore hidden files - if (nm(1) == '.') - continue - endif - f = fullfile (d, nm); - if ((length (nm) > 2 && strcmp (nm((end-1):end), ".m")) || - (length (nm) > 3 && strcmp (nm((end-2):end), ".cc"))) - p = n = xf = 0; - ## Only run if it contains %!test, %!assert %!error or %!warning - if (has_tests (f)) - tmp = strrep (f, [topsrcdir, filesep], ""); - tmp = strrep (tmp, [topbuilddir, filesep], ["..", filesep]); - print_test_file_name (tmp); - [p, n, xf, sk] = test (f, "quiet", fid); - print_pass_fail (n, p); - dp += p; - dn += n; - dxf += xf; - dsk += sk; - files_with_tests(end+1) = f; - ##elseif (has_demos (f)) - ## files_with_tests(end+1) = f; - elseif (has_functions (f)) - ## To reduce the list length, only mark .cc files that contain - ## DEFUN definitions. - files_with_no_tests(end+1) = f; - endif - endif - endfor - ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); -endfunction - -function printf_assert (varargin) - global _assert_printf; - _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); -endfunction - -function ret = prog_output_assert (str) - global _assert_printf; - if (isempty (_assert_printf)) - ret = isempty (str); - elseif (_assert_printf(end) == "\n") - ret = strcmp (_assert_printf(1:(end-1)), str); - else - ret = strcmp (_assert_printf, str); - endif - _assert_printf = ""; -endfunction - -function n = num_elts_matching_pattern (lst, pat) - n = sum (cellfun (@(x) !isempty (x), regexp (lst, pat, 'once'))); -endfunction - -function report_files_with_no_tests (with, without, typ) - pat = cstrcat ('\', typ, "$"); - n_with = num_elts_matching_pattern (with, pat); - n_without = num_elts_matching_pattern (without, pat); - n_tot = n_with + n_without; - printf ("\n%d (of %d) %s files have no tests.\n", n_without, n_tot, typ); -endfunction - -pso = page_screen_output (); -warn_state = warning ("query", "quiet"); -warning ("on", "quiet"); -try - page_screen_output (0); - warning ("off", "Octave:deprecated-function"); - fid = fopen ("fntests.log", "wt"); - if (fid < 0) - error ("could not open fntests.log for writing"); - endif - test ("", "explain", fid); - dp = dn = dxf = dsk = 0; - puts ("\nIntegrated test scripts:\n\n"); - for i = 1:length (fundirs) - [p, n, xf, sk] = run_test_script (fid, fundirs{i}); - dp += p; - dn += n; - dxf += xf; - dsk += sk; - endfor - puts ("\nFixed test scripts:\n\n"); - for i = 1:length (testdirs) - [p, n, xf, sk] = run_test_dir (fid, testdirs{i}); - dp += p; - dn += n; - dxf += xf; - dsk += sk; - endfor - puts ("\nSummary:\n\n"); - nfail = dn - dp; - printf (" PASS %6d\n", dp); - printf (" FAIL %6d\n", nfail); - if (dxf > 0) - printf (" XFAIL %6d\n", dxf); - endif - if (dsk > 0) - printf (" SKIPPED %6d\n", dsk); - endif - puts ("\n"); - puts ("See the file test/fntests.log for additional details.\n"); - if (dxf > 0) - puts ("\n"); - puts ("Expected failures (listed as XFAIL above) are known bugs.\n"); - puts ("Please help improve Octave by contributing fixes for them.\n"); - endif - if (dsk > 0) - puts ("\n"); - puts ("Tests are most often skipped because the features they require\n"); - puts ("have been disabled. Features are most often disabled because\n"); - puts ("they require dependencies that were not present when Octave\n"); - puts ("was built. The configure script should have printed a summary\n"); - puts ("at the end of its run indicating which dependencies were not found.\n"); - endif - - ## Weed out deprecated and private functions - weed_idx = cellfun (@isempty, regexp (files_with_tests, '\bdeprecated\b|\bprivate\b', 'once')); - files_with_tests = files_with_tests(weed_idx); - weed_idx = cellfun (@isempty, regexp (files_with_no_tests, '\bdeprecated\b|\bprivate\b', 'once')); - files_with_no_tests = files_with_no_tests(weed_idx); - - report_files_with_no_tests (files_with_tests, files_with_no_tests, ".m"); - report_files_with_no_tests (files_with_tests, files_with_no_tests, ".cc"); - - puts ("\nPlease help improve Octave by contributing tests for\n"); - puts ("these files (see the list in the file fntests.log).\n\n"); - - fprintf (fid, "\nFiles with no tests:\n\n%s", - list_in_columns (files_with_no_tests, 80)); - fclose (fid); - - page_screen_output (pso); - warning (warn_state.state, "quiet"); -catch - page_screen_output (pso); - warning (warn_state.state, "quiet"); - disp (lasterr ()); -end_try_catch +__run_test_suite__ (fundirs, testdirs); diff -r e0df71fbe39b -r 5b2126a8c84f test/test_for.m --- a/test/test_for.m Fri Feb 08 16:05:04 2013 +0100 +++ b/test/test_for.m Fri Feb 08 16:53:14 2013 -0500 @@ -19,60 +19,60 @@ %% test/octave.test/for/for-1.m %!test %! for i = 1 -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! end -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1")); %% test/octave.test/for/for-2.m %!test %! for i = 1:4 -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1234")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1234")); %% test/octave.test/for/for-3.m %!test %! for i = [1,2,3,4] -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1234")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1234")); %% test/octave.test/for/for-4.m %!test %! for i = [1,2;3,4] -%! printf_assert ("%d", i(1,1)); -%! printf_assert ("%d", i(2,1)); +%! __printf_assert__ ("%d", i(1,1)); +%! __printf_assert__ ("%d", i(2,1)); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1324")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1324")); %% test/octave.test/for/for-5.m %!test %! for i = I -%! printf_assert ("%d", imag (i)); +%! __printf_assert__ ("%d", imag (i)); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1")); %% test/octave.test/for/for-6.m %!test %! for i = [1,2,3,4]*I -%! printf_assert ("%d", imag (i)); +%! __printf_assert__ ("%d", imag (i)); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1234")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1234")); %% test/octave.test/for/for-7.m %!test %! for i = [1,2;3,4]*I -%! printf_assert ("%d", imag (i(1,1))); -%! printf_assert ("%d", imag (i(2,1))); +%! __printf_assert__ ("%d", imag (i(1,1))); +%! __printf_assert__ ("%d", imag (i(2,1))); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("1324")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("1324")); %% test/octave.test/for/for-8.m %!test @@ -80,10 +80,10 @@ %! if (i > 2) %! break; %! endif -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("12")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("12")); %% test/octave.test/for/for-9.m %!test @@ -91,10 +91,10 @@ %! if (i < 3) %! continue; %! endif -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endfor -%! printf_assert ("\n"); -%! assert (prog_output_assert ("34")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("34")); %!test %! a = [1,3;2,4]; diff -r e0df71fbe39b -r 5b2126a8c84f test/test_if.m --- a/test/test_if.m Fri Feb 08 16:05:04 2013 +0100 +++ b/test/test_if.m Fri Feb 08 16:53:14 2013 -0500 @@ -21,67 +21,67 @@ %! i = 0; %! if (i == 0) %! i++; -%! printf_assert ("%d\n", i); +%! __printf_assert__ ("%d\n", i); %! endif -%! assert (prog_output_assert ("1")); +%! assert (__prog_output_assert__ ("1")); %% test/octave.test/if/if-2.m %!test %! if (eye (2)) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! else -%! printf_assert ("pass\n"); +%! __printf_assert__ ("pass\n"); %! end -%! assert (prog_output_assert ("pass")); +%! assert (__prog_output_assert__ ("pass")); %% test/octave.test/if/if-3.m %!test %! x = 2; %! if (eye (2)) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! elseif (x) -%! printf_assert ("pass\n"); +%! __printf_assert__ ("pass\n"); %! endif -%! assert (prog_output_assert ("pass")); +%! assert (__prog_output_assert__ ("pass")); %% test/octave.test/if/if-4.m %!test %! x = 0; %! y = -2; %! if (eye (2)) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! elseif (x) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! elseif (y) -%! printf_assert ("pass\n"); +%! __printf_assert__ ("pass\n"); %! end -%! assert (prog_output_assert ("pass")); +%! assert (__prog_output_assert__ ("pass")); %% test/octave.test/if/if-5.m %!test %! x = 0; %! y = -2; %! if (eye (2)) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! elseif (x) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! elseif (x) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! else -%! printf_assert ("pass\n"); +%! __printf_assert__ ("pass\n"); %! endif -%! assert (prog_output_assert ("pass")); +%! assert (__prog_output_assert__ ("pass")); %% test/octave.test/if/if-6.m %!test %! x = 0; %! y = -2; %! if (y) -%! printf_assert ("pass\n"); +%! __printf_assert__ ("pass\n"); %! elseif (x) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! elseif (x) -%! printf_assert ("fail\n"); +%! __printf_assert__ ("fail\n"); %! end -%! assert (prog_output_assert ("pass")); +%! assert (__prog_output_assert__ ("pass")); diff -r e0df71fbe39b -r 5b2126a8c84f test/test_io.m --- a/test/test_io.m Fri Feb 08 16:05:04 2013 +0100 +++ b/test/test_io.m Fri Feb 08 16:53:14 2013 -0500 @@ -352,7 +352,7 @@ %! mode = deblank (mode_list (k,:)); %! [id, err] = fopen (nm, mode, arch); %! if (id < 0) -%! printf_assert ("open failed: %s (%s, %s): %s\n", nm, mode, arch, err); +%! __printf_assert__ ("open failed: %s (%s, %s): %s\n", nm, mode, arch, err); %! status = 0; %! break; %! else @@ -361,7 +361,7 @@ %! tmp_mode = cstrcat (mode, "b"); %! [id, err] = fopen (nm, tmp_mode, arch); %! if (id < 0) -%! printf_assert ("open failed: %s (%s, %s): %s\n", nm, tmp_mode, arch, err); +%! __printf_assert__ ("open failed: %s (%s, %s): %s\n", nm, tmp_mode, arch, err); %! status = 0; %! break; %! else @@ -370,7 +370,7 @@ %! tmp_mode = cstrcat (mode, "t"); %! [id, err] = fopen (nm, tmp_mode, arch); %! if (id < 0) -%! printf_assert ("open failed: %s (%s, %s): %s\n", nm, tmp_mode, arch, err); +%! __printf_assert__ ("open failed: %s (%s, %s): %s\n", nm, tmp_mode, arch, err); %! status = 0; %! break; %! else @@ -399,7 +399,7 @@ %% test/octave.test/io/fopen-4.m %! fopen ("foo", "wb", "noodle"); -%! assert (prog_output_assert ("error:")); +%! assert (__prog_output_assert__ ("error:")); %% test/octave.test/io/fopen-5.m %!error fopen () @@ -452,13 +452,13 @@ %! endfor %! %! if (x == 1:n) -%! printf_assert ("ok\n"); +%! __printf_assert__ ("ok\n"); %! endif %! endif %! endif %! %! unlink (nm); -%! assert (prog_output_assert ("ok")); +%! assert (__prog_output_assert__ ("ok")); %% test/octave.test/io/file-pos-1.m %!test diff -r e0df71fbe39b -r 5b2126a8c84f test/test_system.m --- a/test/test_system.m Fri Feb 08 16:05:04 2013 +0100 +++ b/test/test_system.m Fri Feb 08 16:53:14 2013 -0500 @@ -39,8 +39,8 @@ %% test/octave.test/system/pause-1.m %!test %! pause (0); -%! printf_assert ("ok\n"); -%! assert (prog_output_assert ("ok")); +%! __printf_assert__ ("ok\n"); +%! assert (__prog_output_assert__ ("ok")); %% test/octave.test/system/pause-2.m %!error pause (1, 2) @@ -48,8 +48,8 @@ %% test/octave.test/system/sleep-1.m %!test %! sleep (0); -%! printf_assert ("ok\n"); -%! assert (prog_output_assert ("ok")); +%! __printf_assert__ ("ok\n"); +%! assert (__prog_output_assert__ ("ok")); %% test/octave.test/system/sleep-2.m %!error sleep () @@ -60,8 +60,8 @@ %% test/octave.test/system/usleep-1.m %!test %! usleep (0); -%! printf_assert ("ok\n"); -%! assert (prog_output_assert ("ok")); +%! __printf_assert__ ("ok\n"); +%! assert (__prog_output_assert__ ("ok")); %% test/octave.test/system/usleep-2.m %!error usleep () diff -r e0df71fbe39b -r 5b2126a8c84f test/test_while.m --- a/test/test_while.m Fri Feb 08 16:05:04 2013 +0100 +++ b/test/test_while.m Fri Feb 08 16:53:14 2013 -0500 @@ -21,28 +21,28 @@ %! i = 0; %! while (eye (2)) %! i++; -%! printf_assert ("%d\n", i); +%! __printf_assert__ ("%d\n", i); %! endwhile -%! assert (prog_output_assert ("")); +%! assert (__prog_output_assert__ ("")); %% test/octave.test/while/while-2.m %!test %! i = 5; %! while (--i) -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endwhile -%! printf_assert ("\n"); -%! assert (prog_output_assert ("4321")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("4321")); %% test/octave.test/while/while-3.m %!test %! i = 5; %! while (i) %! i--; -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endwhile -%! printf_assert ("\n"); -%! assert (prog_output_assert ("43210")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("43210")); %% test/octave.test/while/while-4.m %!test @@ -51,10 +51,10 @@ %! if (i > 2) %! break; %! endif -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endwhile -%! printf_assert ("\n"); -%! assert (prog_output_assert ("12")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("12")); %% test/octave.test/while/while-5.m %!test @@ -63,8 +63,8 @@ %! if (i < 3) %! continue; %! endif -%! printf_assert ("%d", i); +%! __printf_assert__ ("%d", i); %! endwhile -%! printf_assert ("\n"); -%! assert (prog_output_assert ("34")); +%! __printf_assert__ ("\n"); +%! assert (__prog_output_assert__ ("34"));