Mercurial > hg > octave-nkf
changeset 5836:ed69a3b5b3d0
[project @ 2006-06-01 16:16:00 by jwe]
author | jwe |
---|---|
date | Thu, 01 Jun 2006 16:16:01 +0000 |
parents | 07dd13bfc0ba |
children | 55404f3b0da1 |
files | test/ChangeLog test/fntests.m |
diffstat | 2 files changed, 88 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,12 @@ +2006-06-01 John W. Eaton <jwe@octave.org> + + * fntests.m (print_test_file_name, print_pass_fail): New functions. + (runtestdir, runtestscript): Use them. Print info for each file. + (run_test_dir): Rename from runtestdir. Change all uses. + (run_test_script): Rename from runtestscript. Change all uses. + Handle page_screen_output as a fucntion instead of a built-in + variable. + 2006-05-04 John W. Eaton <jwe@octave.org> * test_prefer.m: Adjust tests for eliminated built-in variables.
--- a/test/fntests.m +++ b/test/fntests.m @@ -23,129 +23,133 @@ script_tree = canonicalize_file_name (fullfile (topsrcdir, "scripts")); fundirs = {src_tree, script_tree}; -function [dp, dn] = runtestdir (fid, d); - lst = dir(d); +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 + else + printf (" no tests"); + endif + printf ("\n"); +endfunction + +function [dp, dn] = run_test_dir (fid, d); + lst = dir (d); dp = dn = 0; - for i = 1:length(lst) + 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] = test(nm(1:(end-2)),"quiet",fid); - filler = repmat (".", 1, 40-length(nm)); - printf(" %s %s PASS %4d/%-4d",nm,filler,p,n); - nfail = n - p; - if (nfail > 0) - printf (" FAIL %d\n", nfail); - else - printf ("\n"); - endif - dp +=p; + if (length (nm) > 5 && strcmp (nm(1:5), "test_") + && strcmp (nm((end-1):end), ".m")) + print_test_file_name (nm); + [p, n] = test (nm(1:(end-2)), "quiet", fid); + print_pass_fail (n, p); + dp += p; dn += n; endif endfor endfunction function y = hastests (f) - fid = fopen(f); - str = fscanf(fid,"%s"); - if (findstr(str,"%!test") || - findstr(str,"%!assert") || - findstr(str,"%!error") || - findstr(str,"%!warning")) + fid = fopen (f); + str = fscanf (fid, "%s"); + if (findstr (str, "%!test") || findstr (str, "%!assert") + || findstr (str, "%!error") || findstr (str, "%!warning")) y = 1; else y = 0; endif - fclose(fid); + fclose (fid); endfunction -function [dp, dn] = runtestscript (fid, d); +function [dp, dn] = run_test_script (fid, d); global topsrcdir; - lst = dir(d); + lst = dir (d); dp = dn = 0; - for i=1:length(lst) + for i = 1:length (lst) nm = lst(i).name; - if (lst(i).isdir && !strcmp(nm,".") && !strcmp(nm,"..") && - !strcmp(nm,"CVS")) - [p, n] = runtestscript (fid, [d, "/",nm]); + if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") + && ! strcmp (nm, "CVS")) + [p, n] = run_test_script (fid, [d, "/", nm]); dp += p; dn += n; endif endfor - for i=1:length(lst) + for i = 1:length (lst) nm = lst(i).name; - if ((length(nm) > 3 && strcmp(nm((end-2):end),".cc")) || - (length(nm) > 2 && strcmp(nm((end-1):end),".m"))) + if ((length (nm) > 3 && strcmp (nm((end-2):end), ".cc")) + || (length (nm) > 2 && strcmp (nm((end-1):end), ".m"))) f = fullfile (d, nm); + print_test_file_name (strrep (f, [topsrcdir, "/"], "")); + p = n = 0; ## Only run if it contains %!test, %!assert %!error or %!warning - if (hastests(f)) - [p, n] = test(f,"quiet",fid); + if (hastests (f)) + [p, n] = test (f, "quiet", fid); dp += p; dn += n; endif + print_pass_fail (n, p); endif endfor - tmpnm = strrep (d, [topsrcdir,"/"], ""); - filler = repmat (".", 1, 40-length(tmpnm)); - printf(" %s %s PASS %4d/%-4d", tmpnm, filler, dp, dn); - nfail = dn - dp; - if (nfail > 0) - printf (" FAIL %d\n", nfail); - else - printf ("\n"); - endif ## printf("%s%s -> passes %d of %d tests\n", ident, d, dp, dn); endfunction -function printf_assert(varargin) +function printf_assert (varargin) global _assert_printf; - _assert_printf=cat(2,_assert_printf,sprintf(varargin{:})); + _assert_printf = cat (2, _assert_printf, sprintf (varargin{:})); endfunction -function ret = prog_output_assert(str) +function ret = prog_output_assert (str) global _assert_printf; - if (isempty(_assert_printf)) - ret = isempty(str); + if (isempty (_assert_printf)) + ret = isempty (str); elseif (_assert_printf(end) == "\n") - ret = strcmp(_assert_printf(1:(end-1)),str); + ret = strcmp (_assert_printf(1:(end-1)), str); else - ret = strcmp(_assert_printf,str); + ret = strcmp (_assert_printf, str); endif _assert_printf = ""; endfunction -pso = page_screen_output; -warn_state = warning("query","quiet"); -warning("on","quiet"); +pso = page_screen_output (); +warn_state = warning ("query", "quiet"); +warning ("on", "quiet"); try - page_screen_output =0; - fid=fopen("fntests.log","wt"); + page_screen_output (0); + fid = fopen ("fntests.log", "wt"); if (fid < 0) - error("could not open fntests.log for writing"); + error ("could not open fntests.log for writing"); endif - test("","explain",fid); - dp=dn=0; - printf("\nIntegrated test scripts:\n\n"); - for i=1:length(fundirs) - [p,n] = runtestscript(fid,fundirs{i}); - dp+=p; - dn+=n; + test ("", "explain", fid); + dp = dn = 0; + printf ("\nIntegrated test scripts:\n\n"); + for i = 1:length (fundirs) + [p, n] = run_test_script (fid, fundirs{i}); + dp += p; + dn += n; endfor - printf("\nFixed test scripts:\n\n"); - for i=1:length(testdirs) - [p, n] = runtestdir (fid, testdirs{i}); - dp+=p; - dn+=n; + printf ("\nFixed test scripts:\n\n"); + for i = 1:length (testdirs) + [p, n] = run_test_dir (fid, testdirs{i}); + dp += p; + dn += n; endfor - printf("\nSummary:\n\n PASS %6d\n", dp); + printf ("\nSummary:\n\n PASS %6d\n", dp); nfail = dn - dp; printf (" FAIL %6d\n", nfail); - printf("\nSee fntests.log for details.\n"); - fclose(fid); - page_screen_output = pso; - warning(warn_state.state,"quiet"); + printf ("\nSee fntests.log for details.\n"); + fclose (fid); + page_screen_output (pso); + warning (warn_state.state, "quiet"); catch - page_screen_output = pso; - warning(warn_state.state,"quiet"); - disp(lasterr()); + page_screen_output (pso); + warning (warn_state.state, "quiet"); + disp (lasterr ()); end_try_catch