Skip to content

Commit

Permalink
add a little support for disabling dependencies in checkDependency.
Browse files Browse the repository at this point in the history
this test will also serve to add a little coverage for simulateODE
  • Loading branch information
RussTedrake committed Apr 27, 2015
1 parent 9ae2738 commit 76692bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 11 additions & 5 deletions systems/plants/test/simulinkDependency.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
function simulinkDependency
% tests that I can load the RBM without loading simulink

if ~checkDependency('simulink')
disp('no worries. you don''t even have simulink installed');
return;
end
checkDependency('simulink');

if verLessThan('matlab','8.3') % 2014a
disp('I know it doesn''t work on 2012b, but haven''t tested 2013');
Expand All @@ -24,7 +21,16 @@
error('oops. simulink got loaded');
end

xtraj = simulate(r,[0 1]);
checkDependency('simulink','disable');
xtraj = simulate(r,[0 1]); % this should run w/ simulateODE

a = strfind(inmem,'Simulink');
if ~isempty([a{:}])
error('oops. simulink got loaded');
end

checkDependency('simulink','enable');
xtraj = simulate(r,[0 1]); % this should run w/ simulink

a = strfind(inmem,'Simulink');
if isempty([a{:}])
Expand Down
15 changes: 14 additions & 1 deletion util/checkDependency.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
function ok = checkDependency(dep,minimum_version)
function ok = checkDependency(dep,command)
% Drake code which depends on an external library or program should
% check that dependency by calling this function.
% example:
% checkDependency('snopt')
% or
% if (~checkDependency('snopt')) error('my error'); end
%
% @param dep the name of the dependency to check
% @param command can be 'disable', 'enable'
% % todo: consider supporting a minimum_version

persistent conf;

ldep = lower(dep);
conf_var = [ldep,'_enabled'];

if (nargin>1)
if strcmp(command,'disable')
conf.(conf_var) = false;
return;
elseif strcmp(command,'enable')
conf.(conf_var) = [];
end
end

already_checked = isfield(conf,conf_var) && ~isempty(conf.(conf_var));
if already_checked
ok = conf.(conf_var);
Expand Down

0 comments on commit 76692bc

Please sign in to comment.