%% Create a directory "foo", add it to the path and store
%% a foo.m there
mkdir ('foo');
mkdir ('bar');
copyfile ('base.m', 'foo/foo.m');
addpath (fullfile (pwd (), 'foo'));
addpath (pwd ());


fname = 'foo.m';
try
  copyfile ('base.m', fname);
  rehash
  disp (sprintf ('\n * Deleting ''%s'' before ''which (''foo'')'' returns', fname))
  delete (fname);
  which ('foo')
catch
  disp (lasterr);
end

try
  copyfile ('base.m', fname);
  rehash
  disp (sprintf ('\n * Deleting ''%s'' before ''exist (''foo.m'', ''file'')'' returns', fname))
  delete (fname);
  exist ('foo.m', 'file')
catch
  disp (lasterr);
end

try
  copyfile ('base.m', fname);
  rehash
  disp (sprintf ('\n * Deleting ''%s'' before ''run (''foo'')'' returns', fname))
  delete (fname);
  run ('foo');
catch
  disp (lasterr);
end

try
  copyfile ('base.m', fname);
  rehash
  disp (sprintf ('\n * Deleting ''%s'' before bare ''foo'' returns', fname))
  delete (fname);
  foo;
catch
  disp (lasterr);
end

try
  copyfile ('base.m', fname);
  rehash
  disp (sprintf ('\n * Modifying ''%s'' before bare ''foo'' returns', fname))
  system ('echo "disp (''modified'')" >> foo.m');
  foo;
catch
  disp (lasterr);
end


rmpath (fullfile (pwd (), 'foo'));
rmpath (pwd ());
