45
45
46
46
function num = numTestCases(self )
47
47
% The number of test cases in this doctest
48
+ %
49
+ % >> dt = DocTest('help'); % it has no test cases
50
+ % >> dt.numTestCases()
51
+ % ans = 0
48
52
num = numel(self .Examples );
49
53
end
50
54
@@ -56,8 +60,6 @@ function print(self, numLeadingBlanks)
56
60
function DOCTEST__all_passed = run(DOCTEST__self , DOCTEST__monitor )
57
61
% Run all the tests in this unit of documentation.
58
62
%
59
-
60
- %
61
63
% All the variables in this function begin with DOCTEST__.
62
64
% That's because the namespace of this function and of the
63
65
% doctest that's being run are intermingled. This is
@@ -66,6 +68,14 @@ function print(self, numLeadingBlanks)
66
68
% variables when writing a doctest. It does make it hard to
67
69
% read, though...
68
70
%
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
+
69
79
if nargin < 2
70
80
DOCTEST__monitor = CommandWindowTestRunDisplay();
71
81
end
@@ -106,18 +116,22 @@ function print(self, numLeadingBlanks)
106
116
end
107
117
108
118
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).
111
124
%
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.
114
128
%
115
129
% >> disp('Hi there! <a href="matlab:help help">foo</a>')
116
130
% Hi there! foo
117
131
%
118
132
%
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.
121
135
%
122
136
% >> sprintf('There is no letter x here: x\x08')
123
137
%
@@ -126,14 +140,27 @@ function print(self, numLeadingBlanks)
126
140
% There is no letter x here:
127
141
%
128
142
%
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.
130
156
%
131
157
132
158
want = regexprep(want , ' \s+' , ' ' );
133
159
got = regexprep(got , ' \s+' , ' ' );
134
160
135
161
% 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.
137
164
got = regexprep(got , ' <a +href=".*?>' , ' ' );
138
165
got = regexprep(got , ' </a>' , ' ' );
139
166
0 commit comments