make check recommended practice?

Moritz Borgmann octave at moriborg.de
Mon Dec 3 16:22:45 CST 2007


looks great to me! The only thing missing AFAICT is some notice to 
the user that tests are skipped. Where should we put this?

Provided that I find some time, I may even volunteer to put in some 
testif blocks. I have a pretty minimal build here without bells and 
whistles.

Thanks,

Moritz

>Ok, then what about the attached? It adds the code to test.m for the
>"%!testif" blocks, the tests to "test.m" to test its functionality and
>then converts regexp.cc to use the new "%!testif" blocks. We then need
>to make many of the tests on the sparse functionality conditional,
>though thats a bit harder as I'll have to remove suitesparse from my
>build to test this..
>
>D.
>
>
>
>*** ./scripts/testfun/test.m.orig43	2007-11-09 22:14:01.000000000 +0100
>--- ./scripts/testfun/test.m	2007-12-03 22:45:12.607540290 +0100
>***************
>*** 75,88 ****
>
>   ## PKG_ADD: mark_as_command test
>
>! function [__ret1, __ret2, __ret3] = test (__name, __flag, __fid)
>     ## information from test will be introduced by "key"
>     persistent __signal_fail =  "!!!!! ";
>     persistent __signal_empty = "????? ";
>     persistent __signal_block = "  ***** ";
>     persistent __signal_file =  ">>>>> ";
>
>     __xfail = 0;
>
>     if (nargin < 2 || isempty (__flag))
>       __flag = "quiet";
>--- 75,90 ----
>
>   ## PKG_ADD: mark_as_command test
>
>! function [__ret1, __ret2, __ret3, __ret4] = test (__name, __flag, __fid)
>     ## information from test will be introduced by "key"
>     persistent __signal_fail =  "!!!!! ";
>     persistent __signal_empty = "????? ";
>     persistent __signal_block = "  ***** ";
>     persistent __signal_file =  ">>>>> ";
>+   persistent __signal_skip = "----- ";
>
>     __xfail = 0;
>+   __xskip = 0;
>
>     if (nargin < 2 || isempty (__flag))
>       __flag = "quiet";
>***************
>*** 415,420 ****
>--- 417,436 ----
>         endif
>         __code = ""; # code already processed
>        
>+     ## TESTIF
>+     elseif (strcmp (__type, "testif"))
>+       [__e, __feat] = regexp (__code, '^\s*([^\s]+)', 'end', 'tokens');
>+       if (isempty (findstr (octave_config_info ("DEFS"), __feat{1}{1})))
>+         __xskip++;
>+	__success = 0;
>+	__istest = 0;
>+	__code = ""; # skip the code
>+	__msg = sprintf ("%sskipped test\n", __signal_skip);
>+       else
>+         __istest = 1;
>+	__code = __code(__e + 1 : end);
>+       endif
>+
>       ## TEST
>       elseif (strcmp (__type, "test") || strcmp (__type, "xtest"))
>         __istest = 1;
>***************
>*** 495,500 ****
>--- 511,519 ----
>       else
>         printf ("PASSES %d out of %d tests\n", __successes, __tests);
>       endif
>+     if (__xskip)
>+       printf ("Skipped %d tests due to missing features\n", __xskip);
>+     endif
>     elseif (__grabdemo)
>       __ret1 = __demo_code;
>       __ret2 = __demo_idx;
>***************
>*** 504,509 ****
>--- 523,529 ----
>       __ret1 = __successes;
>       __ret2 = __tests;
>       __ret3 = __xfail;
>+     __ret4 = __xskip;
>     endif
>   endfunction
>
>***************
>*** 594,599 ****
>--- 614,627 ----
>     endif
>   endfunction
>
>+ ## Test for test for missing features
>+ %!testif OCTAVE_SOURCE
>+ %! ## This test should be run
>+ %! assert (true);
>+ %!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")
>
>*** ./src/DLD-FUNCTIONS/regexp.cc.orig43	2007-12-03 
>22:46:40.529091204 +0100
>--- ./src/DLD-FUNCTIONS/regexp.cc	2007-12-03 22:37:26.966103098 +0100
>***************
>*** 927,1021 ****
>   %! ## Matlab gives [1,0] here but that seems wrong.
>   %! assert (size(t), [1,1])
>
>! %!test
>   %! ## This test is expected to fail if PCRE is not installed
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   [s, e, te, m, t, nm] = regexp('short test 
>string','(?<word1>\w*t)\s*(?<word2>\w*t)');
>! %!   assert (s,1)
>! %!   assert (e,10)
>! %!   assert (size(te), [1,1])
>! %!   assert (te{1}, [1 5; 7, 10])
>! %!   assert (m{1},'short test')
>! %!   assert (size(t),[1,1])
>! %!   assert (t{1}{1},'short')
>! %!   assert (t{1}{2},'test')
>! %!   assert (size(nm), [1,1])
>! %!   assert (!isempty(fieldnames(nm)))
>! %!   assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %!   assert (nm.word1,'short')
>! %!   assert (nm.word2,'test')
>! %! endif
>
>! %!test
>   %! ## This test is expected to fail if PCRE is not installed
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   [nm, m, te, e, s, t] = regexp('short test 
>string','(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 
>'tokenExtents', 'end', 'start', 'tokens');
>! %!   assert (s,1)
>! %!   assert (e,10)
>! %!   assert (size(te), [1,1])
>! %!   assert (te{1}, [1 5; 7, 10])
>! %!   assert (m{1},'short test')
>! %!   assert (size(t),[1,1])
>! %!   assert (t{1}{1},'short')
>! %!   assert (t{1}{2},'test')
>! %!   assert (size(nm), [1,1])
>! %!   assert (!isempty(fieldnames(nm)))
>! %!   assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %!   assert (nm.word1,'short')
>! %!   assert (nm.word2,'test')
>! %! endif
>
>! %!test
>   %! ## This test is expected to fail if PCRE is not installed
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   [t, nm] = regexp("John Davis\nRogers, 
>James",'(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)','tokens','names');
>! %!   assert (size(t), [1,2]);
>! %!   assert (t{1}{1},'John');
>! %!   assert (t{1}{2},'Davis');
>! %!   assert (t{2}{1},'Rogers');
>! %!   assert (t{2}{2},'James');
>! %!   assert (size(nm), [1,1]);
>! %!   assert (nm.first{1},'John');
>! %!   assert (nm.first{2},'James');
>! %!   assert (nm.last{1},'Davis');
>! %!   assert (nm.last{2},'Rogers');
>! %! endif
>
>   %!assert(regexp("abc\nabc",'.'),[1:7])
>   %!assert(regexp("abc\nabc",'.','dotall'),[1:7])
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert(regexp("abc\nabc",'(?s).'),[1:7])
>! %!   assert(regexp("abc\nabc",'.','dotexceptnewline'),[1,2,3,5,6,7])
>! %!   assert(regexp("abc\nabc",'(?-s).'),[1,2,3,5,6,7])
>! %! endif
>
>   %!assert(regexp("caseCaSe",'case'),1)
>   %!assert(regexp("caseCaSe",'case',"matchcase"),1)
>   %!assert(regexp("caseCaSe",'case',"ignorecase"),[1,5])
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert(regexp("caseCaSe",'(?-i)case'),1)
>! %!   assert(regexp("caseCaSe",'(?i)case'),[1,5])
>! %! endif
>
>   %!assert (regexp("abc\nabc",'c$'),7)
>   %!assert (regexp("abc\nabc",'c$',"stringanchors"),7)
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert (regexp("abc\nabc",'(?-m)c$'),7)
>! %!   assert (regexp("abc\nabc",'c$',"lineanchors"),[3,7])
>! %!   assert (regexp("abc\nabc",'(?m)c$'),[3,7])
>! %! endif
>
>   %!assert (regexp("this word",'s w'),4)
>   %!assert (regexp("this word",'s w','literalspacing'),4)
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert (regexp("this word",'(?-x)s w','literalspacing'),4)
>! %!   assert (regexp("this word",'s w','freespacing'),zeros(1,0))
>! %!   assert (regexp("this word",'(?x)s w'),zeros(1,0))
>! %! endif
>
>   %!error regexp('string', 'tri', 'BadArg');
>   %!error regexp('string');
>--- 927,1007 ----
>   %! ## Matlab gives [1,0] here but that seems wrong.
>   %! assert (size(t), [1,1])
>
>! %!testif HAVE_PCRE
>   %! ## This test is expected to fail if PCRE is not installed
>! %! [s, e, te, m, t, nm] = regexp('short test 
>string','(?<word1>\w*t)\s*(?<word2>\w*t)');
>! %! assert (s,1)
>! %! assert (e,10)
>! %! assert (size(te), [1,1])
>! %! assert (te{1}, [1 5; 7, 10])
>! %! assert (m{1},'short test')
>! %! assert (size(t),[1,1])
>! %! assert (t{1}{1},'short')
>! %! assert (t{1}{2},'test')
>! %! assert (size(nm), [1,1])
>! %! assert (!isempty(fieldnames(nm)))
>! %! assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %! assert (nm.word1,'short')
>! %! assert (nm.word2,'test')
>
>! %!testif HAVE_PCRE
>   %! ## This test is expected to fail if PCRE is not installed
>! %! [nm, m, te, e, s, t] = regexp('short test 
>string','(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 
>'tokenExtents', 'end', 'start', 'tokens');
>! %! assert (s,1)
>! %! assert (e,10)
>! %! assert (size(te), [1,1])
>! %! assert (te{1}, [1 5; 7, 10])
>! %! assert (m{1},'short test')
>! %! assert (size(t),[1,1])
>! %! assert (t{1}{1},'short')
>! %! assert (t{1}{2},'test')
>! %! assert (size(nm), [1,1])
>! %! assert (!isempty(fieldnames(nm)))
>! %! assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %! assert (nm.word1,'short')
>! %! assert (nm.word2,'test')
>
>! %!testif HAVE_PCRE
>   %! ## This test is expected to fail if PCRE is not installed
>! %! [t, nm] = regexp("John Davis\nRogers, 
>James",'(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)','tokens','names');
>! %! assert (size(t), [1,2]);
>! %! assert (t{1}{1},'John');
>! %! assert (t{1}{2},'Davis');
>! %! assert (t{2}{1},'Rogers');
>! %! assert (t{2}{2},'James');
>! %! assert (size(nm), [1,1]);
>! %! assert (nm.first{1},'John');
>! %! assert (nm.first{2},'James');
>! %! assert (nm.last{1},'Davis');
>! %! assert (nm.last{2},'Rogers');
>
>   %!assert(regexp("abc\nabc",'.'),[1:7])
>   %!assert(regexp("abc\nabc",'.','dotall'),[1:7])
>! %!testif HAVE_PCRE
>! %! assert(regexp("abc\nabc",'(?s).'),[1:7])
>! %! assert(regexp("abc\nabc",'.','dotexceptnewline'),[1,2,3,5,6,7])
>! %! assert(regexp("abc\nabc",'(?-s).'),[1,2,3,5,6,7])
>
>   %!assert(regexp("caseCaSe",'case'),1)
>   %!assert(regexp("caseCaSe",'case',"matchcase"),1)
>   %!assert(regexp("caseCaSe",'case',"ignorecase"),[1,5])
>! %!testif HAVE_PCRE
>! %! assert(regexp("caseCaSe",'(?-i)case'),1)
>! %! assert(regexp("caseCaSe",'(?i)case'),[1,5])
>
>   %!assert (regexp("abc\nabc",'c$'),7)
>   %!assert (regexp("abc\nabc",'c$',"stringanchors"),7)
>! %!testif HAVE_PCRE
>! %! assert (regexp("abc\nabc",'(?-m)c$'),7)
>! %! assert (regexp("abc\nabc",'c$',"lineanchors"),[3,7])
>! %! assert (regexp("abc\nabc",'(?m)c$'),[3,7])
>
>   %!assert (regexp("this word",'s w'),4)
>   %!assert (regexp("this word",'s w','literalspacing'),4)
>! %!testif HAVE_PCRE
>! %! assert (regexp("this word",'(?-x)s w','literalspacing'),4)
>! %! assert (regexp("this word",'s w','freespacing'),zeros(1,0))
>! %! assert (regexp("this word",'(?x)s w'),zeros(1,0))
>
>   %!error regexp('string', 'tri', 'BadArg');
>   %!error regexp('string');
>***************
>*** 1117,1195 ****
>   %! ## Matlab gives [1,0] here but that seems wrong.
>   %! assert (size(t), [1,1])
>
>! %!test
>   %! ## This test is expected to fail if PCRE is not installed
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   [s, e, te, m, t, nm] = regexpi('ShoRt Test 
>String','(?<word1>\w*t)\s*(?<word2>\w*t)');
>! %!   assert (s,1)
>! %!   assert (e,10)
>! %!   assert (size(te), [1,1])
>! %!   assert (te{1}, [1 5; 7, 10])
>! %!   assert (m{1},'ShoRt Test')
>! %!   assert (size(t),[1,1])
>! %!   assert (t{1}{1},'ShoRt')
>! %!   assert (t{1}{2},'Test')
>! %!   assert (size(nm), [1,1])
>! %!   assert (!isempty(fieldnames(nm)))
>! %!   assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %!   assert (nm.word1,'ShoRt')
>! %!   assert (nm.word2,'Test')
>! %! endif
>
>! %!test
>   %! ## This test is expected to fail if PCRE is not installed
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   [nm, m, te, e, s, t] = regexpi('ShoRt Test 
>String','(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 
>'tokenExtents', 'end', 'start', 'tokens');
>! %!   assert (s,1)
>! %!   assert (e,10)
>! %!   assert (size(te), [1,1])
>! %!   assert (te{1}, [1 5; 7, 10])
>! %!   assert (m{1},'ShoRt Test')
>! %!   assert (size(t),[1,1])
>! %!   assert (t{1}{1},'ShoRt')
>! %!   assert (t{1}{2},'Test')
>! %!   assert (size(nm), [1,1])
>! %!   assert (!isempty(fieldnames(nm)))
>! %!   assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %!   assert (nm.word1,'ShoRt')
>! %!   assert (nm.word2,'Test')
>! %! endif
>
>   %!assert(regexpi("abc\nabc",'.'),[1:7])
>   %!assert(regexpi("abc\nabc",'.','dotall'),[1:7])
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert(regexpi("abc\nabc",'(?s).'),[1:7])
>! %!   assert(regexpi("abc\nabc",'.','dotexceptnewline'),[1,2,3,5,6,7])
>! %!   assert(regexpi("abc\nabc",'(?-s).'),[1,2,3,5,6,7])
>! %! endif
>
>   %!assert(regexpi("caseCaSe",'case'),[1,5])
>   %!assert(regexpi("caseCaSe",'case',"matchcase"),1)
>   %!assert(regexpi("caseCaSe",'case',"ignorecase"),[1,5])
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert(regexpi("caseCaSe",'(?-i)case'),1)
>! %!   assert(regexpi("caseCaSe",'(?i)case'),[1,5])
>! %! endif
>
>   %!assert (regexpi("abc\nabc",'c$'),7)
>   %!assert (regexpi("abc\nabc",'c$',"stringanchors"),7)
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert (regexpi("abc\nabc",'(?-m)c$'),7)
>! %!   assert (regexpi("abc\nabc",'c$',"lineanchors"),[3,7])
>! %!   assert (regexpi("abc\nabc",'(?m)c$'),[3,7])
>! %! endif
>
>   %!assert (regexpi("this word",'s w'),4)
>   %!assert (regexpi("this word",'s w','literalspacing'),4)
>! %!test
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   assert (regexpi("this word",'(?-x)s w','literalspacing'),4)
>! %!   assert (regexpi("this word",'s w','freespacing'),zeros(1,0))
>! %!   assert (regexpi("this word",'(?x)s w'),zeros(1,0))
>! %! endif
>
>   %!error regexpi('string', 'tri', 'BadArg');
>   %!error regexpi('string');
>--- 1103,1169 ----
>   %! ## Matlab gives [1,0] here but that seems wrong.
>   %! assert (size(t), [1,1])
>
>! %!testif HAVE_PCRE
>   %! ## This test is expected to fail if PCRE is not installed
>! %! [s, e, te, m, t, nm] = regexpi('ShoRt Test 
>String','(?<word1>\w*t)\s*(?<word2>\w*t)');
>! %! assert (s,1)
>! %! assert (e,10)
>! %! assert (size(te), [1,1])
>! %! assert (te{1}, [1 5; 7, 10])
>! %! assert (m{1},'ShoRt Test')
>! %! assert (size(t),[1,1])
>! %! assert (t{1}{1},'ShoRt')
>! %! assert (t{1}{2},'Test')
>! %! assert (size(nm), [1,1])
>! %! assert (!isempty(fieldnames(nm)))
>! %! assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %! assert (nm.word1,'ShoRt')
>! %! assert (nm.word2,'Test')
>
>! %!testif HAVE_PCRE
>   %! ## This test is expected to fail if PCRE is not installed
>! %! [nm, m, te, e, s, t] = regexpi('ShoRt Test 
>String','(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 
>'tokenExtents', 'end', 'start', 'tokens');
>! %! assert (s,1)
>! %! assert (e,10)
>! %! assert (size(te), [1,1])
>! %! assert (te{1}, [1 5; 7, 10])
>! %! assert (m{1},'ShoRt Test')
>! %! assert (size(t),[1,1])
>! %! assert (t{1}{1},'ShoRt')
>! %! assert (t{1}{2},'Test')
>! %! assert (size(nm), [1,1])
>! %! assert (!isempty(fieldnames(nm)))
>! %! assert (sort(fieldnames(nm)),{'word1';'word2'})
>! %! assert (nm.word1,'ShoRt')
>! %! assert (nm.word2,'Test')
>
>   %!assert(regexpi("abc\nabc",'.'),[1:7])
>   %!assert(regexpi("abc\nabc",'.','dotall'),[1:7])
>! %!testif HAVE_PCRE
>! %! assert(regexpi("abc\nabc",'(?s).'),[1:7])
>! %! assert(regexpi("abc\nabc",'.','dotexceptnewline'),[1,2,3,5,6,7])
>! %! assert(regexpi("abc\nabc",'(?-s).'),[1,2,3,5,6,7])
>
>   %!assert(regexpi("caseCaSe",'case'),[1,5])
>   %!assert(regexpi("caseCaSe",'case',"matchcase"),1)
>   %!assert(regexpi("caseCaSe",'case',"ignorecase"),[1,5])
>! %!testif HAVE_PCRE
>! %! assert(regexpi("caseCaSe",'(?-i)case'),1)
>! %! assert(regexpi("caseCaSe",'(?i)case'),[1,5])
>
>   %!assert (regexpi("abc\nabc",'c$'),7)
>   %!assert (regexpi("abc\nabc",'c$',"stringanchors"),7)
>! %!testif HAVE_PCRE
>! %! assert (regexpi("abc\nabc",'(?-m)c$'),7)
>! %! assert (regexpi("abc\nabc",'c$',"lineanchors"),[3,7])
>! %! assert (regexpi("abc\nabc",'(?m)c$'),[3,7])
>
>   %!assert (regexpi("this word",'s w'),4)
>   %!assert (regexpi("this word",'s w','literalspacing'),4)
>! %!testif HAVE_PCRE
>! %! assert (regexpi("this word",'(?-x)s w','literalspacing'),4)
>! %! assert (regexpi("this word",'s w','freespacing'),zeros(1,0))
>! %! assert (regexpi("this word",'(?x)s w'),zeros(1,0))
>
>   %!error regexpi('string', 'tri', 'BadArg');
>   %!error regexpi('string');
>***************
>*** 1532,1544 ****
>   %! t = regexprep(xml,'<[!?][^>]*>','','tokenize');
>   %! assert(t,' <tag v="hello">some stuff</tag>')
>
>! %!test  # Capture replacement
>! %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_PCRE")))
>! %!   data = "Bob Smith\nDavid Hollerith\nSam Jenkins";
>! %!   result = "Smith, Bob\nHollerith, David\nJenkins, Sam";
>! %!   t = regexprep(data,'(?m)^(\w+)\s+(\w+)$','$2, $1');
>! %!   assert(t,result)
>! %! end
>
>   # Return the original if no match
>   %!assert(regexprep('hello','world','earth'),'hello')
>--- 1506,1516 ----
>   %! t = regexprep(xml,'<[!?][^>]*>','','tokenize');
>   %! assert(t,' <tag v="hello">some stuff</tag>')
>
>! %!testif HAVE_PCRE # Capture replacement
>! %! data = "Bob Smith\nDavid Hollerith\nSam Jenkins";
>! %! result = "Smith, Bob\nHollerith, David\nJenkins, Sam";
>! %! t = regexprep(data,'(?m)^(\w+)\s+(\w+)$','$2, $1');
>! %! assert(t,result)
>
>   # Return the original if no match
>   %!assert(regexprep('hello','world','earth'),'hello')
>
>2007-12-03  David Bateman  <dbateman at free.fr>
>
>	* testfun/test.m: Add "testif" type to allow for conditional tests.
>
>2007-12-03  David Bateman  <dbateman at free.fr>
>
>	* DLD-FUNCTIONS/regexp.cc: Use "%!testif" blocks for conditional
>	tests on PCRE.



More information about the Octave-maintainers mailing list