comparison __py_tests__.m @ 383:d18843ff4dfd

Rewrite the test suite to run Octave-style built-in tests * Makefile.am (M_FILES): New declaration. (TST_FILES): New derived declaration. (%.cc-tst): New rule to generate test scripts from compiled sources. (check-local): Call __py_tests__.m script file to run test suite. (CLEANFILES): Include fntests.log and *-tst. * __py_tests__.m: New script file to run built-in tests. * .hgignore: Include fntests.log and *.cc-tst.
author Mike Miller <mtmiller@octave.org>
date Sun, 02 Apr 2017 11:20:53 -0700
parents
children c6e93e7dcfba
comparison
equal deleted inserted replaced
382:d36f06f07082 383:d18843ff4dfd
1 ## Copyright (C) 2017 Mike Miller
2 ## Copyright (C) 2005-2017 David Bateman
3 ##
4 ## This file is part of Pytave.
5 ##
6 ## Pytave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or
9 ## (at your option) any later version.
10 ##
11 ## Pytave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Pytave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## This is a script file, derived from Octave's __run_test_suite__.m
21 true;
22
23 function retval = __run_py_tests__ (varargin)
24
25 files_with_no_tests = {};
26 files_with_tests = {};
27
28 pso = page_screen_output ();
29
30 logfile = make_absolute_filename ("fntests.log");
31 unwind_protect
32 page_screen_output (false);
33 try
34 fid = fopen (logfile, "wt");
35 if (fid < 0)
36 error ("__run_test_suite__: could not open %s for writing", logfile);
37 endif
38 test ("", "explain", fid);
39 dp = dn = dxf = dsk = drtsk = 0;
40 puts ("\nIntegrated test scripts:\n\n");
41 for i = 1:length (varargin)
42 f = varargin{i};
43 if (has_tests (f))
44 print_test_file_name (f);
45 [p, n, xf, sk, rtsk] = test (f, "quiet", fid);
46 print_pass_fail (p, n, xf, sk, rtsk);
47 dp += p;
48 dn += n;
49 dxf += xf;
50 dsk += sk;
51 drtsk += rtsk;
52 files_with_tests(end+1) = f;
53 else
54 ## To reduce the list length, only mark .cc files that contain
55 ## DEFUN definitions.
56 files_with_no_tests(end+1) = f;
57 endif
58 endfor
59
60 puts ("\nSummary:\n\n");
61 nfail = dn - dp - dxf;
62 printf (" PASS %6d\n", dp);
63 printf (" FAIL %6d\n", nfail);
64 if (dxf > 0)
65 printf (" XFAIL %6d\n", dxf);
66 endif
67 if (dsk > 0)
68 printf (" SKIPPED (feature) %6d\n", dsk);
69 endif
70 if (drtsk > 0)
71 printf (" SKIPPED (run-time condition) %6d\n", drtsk);
72 endif
73 puts ("\n");
74 printf ("See the file %s for additional details.\n", logfile);
75 if (dxf > 0)
76 puts ("\n");
77 puts ("Items listed as XFAIL above are known bugs.\n");
78 puts ("Bug report numbers for them may be found in the log file:\n");
79 puts (logfile);
80 puts ("\nPlease help improve Pytave by contributing fixes for them.\n");
81 endif
82 if (dsk > 0 || drtsk > 0)
83 puts ("\n");
84 puts ("Tests are most often skipped because the features they require\n");
85 puts ("have been disabled. Features are most often disabled because\n");
86 puts ("they require dependencies that were not present when Octave or\n");
87 puts ("Pytave was built.\n");
88 endif
89
90 report_files_with_no_tests (files_with_tests, files_with_no_tests, ".m");
91
92 puts ("\nPlease help improve Pytave by contributing tests for these files\n");
93 printf ("(see the list in the file %s).\n\n", logfile);
94
95 fprintf (fid, "\nFiles with no tests:\n\n%s",
96 list_in_columns (files_with_no_tests, 80));
97 fclose (fid);
98 catch
99 disp (lasterr ());
100 end_try_catch
101 unwind_protect_cleanup
102 page_screen_output (pso);
103 end_unwind_protect
104 retval = (nfail != 0);
105 endfunction
106
107 function print_test_file_name (nm)
108 filler = repmat (".", 1, 60-length (nm));
109 printf (" %s %s", nm, filler);
110 endfunction
111
112 function print_pass_fail (p, n, xf, sk, rtsk)
113
114 if ((n + sk + rtsk) > 0)
115 printf (" PASS %4d/%-4d", p, n);
116 nfail = n - p - xf;
117 if (nfail > 0)
118 printf ("\n%71s %3d", "FAIL ", nfail);
119 endif
120 if (sk > 0)
121 printf ("\n%71s %3d", "(missing feature) SKIP ", sk);
122 endif
123 if (rtsk > 0)
124 printf ("\n%71s %3d", "(run-time condition) SKIP ", rtsk);
125 endif
126 if (xf > 0)
127 printf ("\n%71s %3d", "XFAIL", xf);
128 endif
129 endif
130 puts ("\n");
131
132 endfunction
133
134 function retval = has_tests (f)
135
136 fid = fopen (f);
137 if (fid < 0)
138 error ("__run_test_suite__: fopen failed: %s", f);
139 endif
140
141 str = fread (fid, "*char")';
142 fclose (fid);
143 retval = ! isempty (regexp (str,
144 '^%!(assert|error|fail|test|xtest|warning)',
145 'lineanchors', 'once'));
146
147 endfunction
148
149 function n = num_elts_matching_pattern (lst, pat)
150 n = sum (! cellfun ("isempty", regexp (lst, pat, 'once')));
151 endfunction
152
153 function report_files_with_no_tests (with, without, typ)
154 pat = ['\' typ "$"];
155 n_with = num_elts_matching_pattern (with, pat);
156 n_without = num_elts_matching_pattern (without, pat);
157 n_tot = n_with + n_without;
158 printf ("\n%d (of %d) %s files have no tests.\n", n_without, n_tot, typ);
159 endfunction
160
161 exit (__run_py_tests__ (argv (){:}));
162
163 ## Mark this file as fully tested.
164 %!assert (1)