Skip to content

Commit 64ead85

Browse files
committed
add more tests
1 parent 1545d4d commit 64ead85

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

tests/test_DocTest.m

+5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717

1818
initTestSuite;
1919

20+
more = DocTestSuite('DocTest');
21+
assertTrue(more.numTestCases() > 5);
22+
test_suite.add(more);
23+
2024
end
2125

26+
2227
function test_thisDoctest
2328
dt = DocTest('test_DocTest');
2429
assertEqual(dt.numTestCases(), 2);

xunit/DocTest.m

+37-10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545

4646
function num = numTestCases(self)
4747
% The number of test cases in this doctest
48+
%
49+
% >> dt = DocTest('help'); % it has no test cases
50+
% >> dt.numTestCases()
51+
% ans = 0
4852
num = numel(self.Examples);
4953
end
5054

@@ -56,8 +60,6 @@ function print(self, numLeadingBlanks)
5660
function DOCTEST__all_passed = run(DOCTEST__self, DOCTEST__monitor)
5761
% Run all the tests in this unit of documentation.
5862
%
59-
60-
%
6163
% All the variables in this function begin with DOCTEST__.
6264
% That's because the namespace of this function and of the
6365
% doctest that's being run are intermingled. This is
@@ -66,6 +68,14 @@ function print(self, numLeadingBlanks)
6668
% variables when writing a doctest. It does make it hard to
6769
% read, though...
6870
%
71+
% This is a test that shows whether all the variables that are
72+
% predefined in a doctest start with the DOCTEST__ prefix:
73+
% >> all_names = who();
74+
% >> sum(cell2mat(strfind(all_names, 'DOCTEST__'))) == length(all_names)
75+
% ans = 1
76+
%
77+
78+
6979
if nargin < 2
7080
DOCTEST__monitor = CommandWindowTestRunDisplay();
7181
end
@@ -106,18 +116,22 @@ function print(self, numLeadingBlanks)
106116
end
107117

108118
function did_pass = compare_or_exception(self, want, got, testnum)
109-
% Matches two strings together... they should be identical, except that the
110-
% first one can contain '***', which matches anything in the second string.
119+
% Matches two strings together... they should be identical,
120+
% except that the first one can contain '***', which matches
121+
% anything in the second string. Also, spacing differences are
122+
% ignored (one or more vertical or horizontal spaces are
123+
% collapsed down to one space).
111124
%
112-
% But there are also some tricksy things that Matlab does to strings. Such
113-
% as add hyperlinks to help. This doctest tests that condition.
125+
% But there are also some tricksy things that Matlab does to
126+
% strings. Such as add hyperlinks to help. This doctest tests
127+
% that condition.
114128
%
115129
% >> disp('Hi there! <a href="matlab:help help">foo</a>')
116130
% Hi there! foo
117131
%
118132
%
119-
% They also sometimes backspace over things for no apparent reason. This
120-
% doctest recreates that condition.
133+
% They also sometimes backspace over things for no apparent
134+
% reason. This doctest recreates that condition.
121135
%
122136
% >> sprintf('There is no letter x here: x\x08')
123137
%
@@ -126,14 +140,27 @@ function print(self, numLeadingBlanks)
126140
% There is no letter x here:
127141
%
128142
%
129-
% All of the doctests should pass, and they manipulate this function.
143+
% The comparison is space-insensitive:
144+
% >> 3
145+
%
146+
% ans =
147+
%
148+
% 3
149+
%
150+
% >> 3
151+
% ans = 3
152+
%
153+
%
154+
% All of the doctests should pass, and they manipulate this
155+
% function.
130156
%
131157

132158
want = regexprep(want, '\s+', ' ');
133159
got = regexprep(got, '\s+', ' ');
134160

135161
% This looks bad, like hardcoding for lower-case "a href"
136-
% and a double quote... but that's what MATLAB looks for too.
162+
% and a double quote... but that's what MATLAB looks for too:
163+
% an <A HREF won't work, only <a href.
137164
got = regexprep(got, '<a +href=".*?>', '');
138165
got = regexprep(got, '</a>', '');
139166

0 commit comments

Comments
 (0)