Code covered by the BSD License  

Highlights from
Test Tools - Utilities for unit tests

from Test Tools - Utilities for unit tests by Jay St. Pierre
Tools that facilitate debugging or writing unit test for MATLAB functions.

out=check_err(fct_call, err_string)
function out=check_err(fct_call, err_string)
%CHECK_ERR checks for an expected error
%     Usage: CHECK_ERR(fct_call, err_string).  The LASTERR string will be
%     checked to see if the expected "err_string" is a substring of LASTERR,
%     and a nice "unit test" type pass/fail text will be output to the
%     screen.  The fct_call string is evaluated in the base workspace.

% $Source: /home/stpierre/cvsroot/matlab/tools/test_tools/check_err.m,v $
% $Revision: 1.3 $
% $Date: 2009-07-26 20:41:24 $

% Copyright (c) 2000-2009, Jay A. St. Pierre.  All rights reserved.

if nargin~=2
  error('check_err() requires two input arguments')
elseif ~ischar(fct_call)
  error('fct_call must be a string (it will be evaluated internally)')
elseif ~ischar(err_string)
  error('err_string must be a string')
end

disp(['Function Call: ', fct_call, 10])
disp('Expected Error:')
disp([err_string, 10])
evalin('base', fct_call, 'out=1;');

if findstr(lasterr, err_string)
  disp('error == expected_error   ***PASSED***')
  disp(' ')
  out=0;
else
  disp('error ~= expected_error   ***FAILED***')
  disp(' ')
  lasterr
  disp(' ')
  err_string %#ok<NOPRT>
  disp(' ')
  out=1;
end

Contact us at files@mathworks.com