Skip to content

Commit d1e40b7

Browse files
committed
add initEnv as subfunction to unit test
1 parent 1e3ff2f commit d1e40b7

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

tests/test_setTargetPositionInSequence.m

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
function test_suite = test_setTargetPositionInSequence %#ok<*STOUT>
22

3-
if isOctave()
4-
pkg('load','statistics');
5-
end
3+
initEnv()
64

75
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
86
test_functions = localfunctions(); %#ok<*NASGU>
@@ -30,3 +28,50 @@ function test_setTargetPositionInSequenceBasic()
3028
assertTrue(all(interval(:) > 1));
3129

3230
end
31+
32+
function initEnv
33+
34+
octaveVersion = '4.0.3';
35+
matlabVersion = '8.6.0';
36+
37+
installlist = {'statistics', 'image'};
38+
39+
if isOctave
40+
41+
% Exit if min version is not satisfied
42+
if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=')
43+
error('Minimum required Octave version: %s', octaveVersion);
44+
end
45+
46+
for ii = 1:length(installlist)
47+
try
48+
% Try loading Octave packages
49+
disp(['loading ' installlist{ii}]);
50+
pkg('load', installlist{ii});
51+
52+
catch
53+
errorcount = 1;
54+
while errorcount % Attempt twice in case installation fails
55+
try
56+
pkg('install', '-forge', installlist{ii});
57+
pkg('load', installlist{ii});
58+
errorcount = 0;
59+
catch err
60+
errorcount = errorcount + 1;
61+
if errorcount > 2
62+
error(err.message);
63+
end
64+
end
65+
end
66+
end
67+
end
68+
69+
else % MATLAB ----------------------------
70+
71+
if verLessThan('matlab', matlabVersion)
72+
error('Sorry, minimum required version is R2017b. :(');
73+
end
74+
75+
end
76+
77+
end

0 commit comments

Comments
 (0)