Commits

Anonymous committed 8f660fb

Add support for classes
Add handling for Matlab putting in hyperlinks, and when matlab prints something then backspaces over it.

Comments (0)

Files changed (4)

  
   doctest func_name
   doctest('func_name')
+  doctest class_name
+  doctest('class_name')
  
   Example:
   Say you have a function that adds 7 to things:
   'add7(3)' and make sure that it gets back 'ans = 10'.
  
   If the output of some function will change each time you call it, for
-  instance if it includes a random number, you can put *** (three
-  asterisks) where the changing element should be.  This acts as a
+  instance if it includes a random number or a stack trace, you can put ***
+  (three asterisks) where the changing element should be.  This acts as a
   wildcard, and will match anything.
  
   LIMITATIONS:
   because I haven't found a good way to mark these subsequent lines as
   part-of-the-source-code rather than part-of-the-result.
   
+
 function match = compare(want, got)
 % Matches two strings together... they should be identical, except that the
 % first one can contain '***', which matches anything in the second string.
+
+got = regexprep(got, '<a href=.*?>', '');
+got = regexprep(got, '</a>', '');
+got = regexprep(got, '.\x08', ''); % WHY do they need backspaces?  huh.
+
+want = strtrim(want);
+got = strtrim(got);
+any(got == '{')
+if isempty(want) && isempty(got)
+    match = 1;
+    return
+end
+
 want_escaped = regexptranslate('escape', want);
 want_re = regexprep(want_escaped, '(\\\*){3}', '.*');
 
-function doctest(func_name, verbose)
+function doctest(func_or_class)
 % Run examples embedded in documentation
 %
 % doctest func_name
 % doctest('func_name')
+% doctest class_name
+% doctest('class_name')
 %
 % Example:
 % Say you have a function that adds 7 to things:
 % 'add7(3)' and make sure that it gets back 'ans = 10'.
 %
 % If the output of some function will change each time you call it, for
-% instance if it includes a random number, you can put *** (three
-% asterisks) where the changing element should be.  This acts as a
+% instance if it includes a random number or a stack trace, you can put ***
+% (three asterisks) where the changing element should be.  This acts as a
 % wildcard, and will match anything.
 %
 % LIMITATIONS:
 % part-of-the-source-code rather than part-of-the-result.
 % 
 
-docstring = help(func_name);
+to_test = { func_or_class };
 
-if nargin < 2
-    verbose = 0;
-else
-    verbose = 1;
+theMethods = methods(func_or_class);
+for I = 1:length(theMethods) % might be 0
+    to_test = [ to_test; ...
+        sprintf('%s.%s', func_or_class, theMethods{I}) ];
 end
 
+to_test
 
-test_anything(run_doctests(docstring), verbose);
+result = [];
+
+for I = 1:length(to_test)
+    result = [result, do_test(to_test{I})];
+end
+    
+test_anything(result, 1);
+
 
 end
 
+function result = do_test(func_name)
+docstring = help(func_name);
+
+result = run_doctests(docstring);
+
+end
+
     
     got_unspaced = regexprep(got, '\s+', ' ');
     
+
+    
     results(I).source = matches(I).source;
-    results(I).want = want_unspaced;
-    results(I).got = got_unspaced;
+    results(I).want = strtrim(want_unspaced);
+    results(I).got = strtrim(got_unspaced);
     results(I).pass = compare(want_unspaced, got_unspaced);
     
 end