-
Notifications
You must be signed in to change notification settings - Fork 0
/
testUpdatedDependencyOptions.m
84 lines (66 loc) · 3.55 KB
/
testUpdatedDependencyOptions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
% UPDATED DEPENDENCIES UNIT TESTS FOR LOADORRUN
%% Put testing files on the path
if ~exist('twoOut', 'file')
addpath('testing');
end
%% Test updated dependency -- call from top
options = struct();
options.onDependencyChange = 'warn';
options.defaultArgs = {[]}; % ignore first 'options' arg but not second numeric arg.
val = loadOrRun(@dependencyTop, {options, 1}, options);
assert(val == 2);
assert(exist(fullfile('.cache', 'dependencyBottom-1.mat'), 'file') > 0);
assert(exist(fullfile('.cache', 'dependencyTop-1.mat'), 'file') > 0);
% Modify 'bottom' (update it's timestamp with 'touch')
pause(1);
!touch testing/dependencyBottom.m
sourceInfo = dir(fullfile('testing', 'dependencyBottom.m'));
cacheInfo = dir(fullfile('.cache', 'dependencyBottom-1.mat'));
assert(cacheInfo.datenum < sourceInfo.datenum, 'something went wrong with system call ''touch''');
val = loadOrRun(@dependencyTop, {options, 1}, options);
assert(val == 2);
% Warning should have been issued, and .mat file should NOT have been recomputed
sourceInfo = dir(fullfile('testing', 'dependencyBottom.m'));
cacheInfo = dir(fullfile('.cache', 'dependencyBottom-1.mat'));
assert(cacheInfo.datenum < sourceInfo.datenum, 'in ''warn'' mode, dependency change should not trigger an update');
options.onDependencyChange = 'autoremove';
pause(1);
val = loadOrRun(@dependencyTop, {options, 1}, options);
assert(val == 2);
sourceInfo = dir(fullfile('testing', 'dependencyBottom.m'));
cacheInfoBottom = dir(fullfile('.cache', 'dependencyBottom-1.mat'));
assert(cacheInfoBottom.datenum > sourceInfo.datenum, 'in ''autoremove'' mode, dependency change SHOULD trigger an update');
cacheInfoTop = dir(fullfile('.cache', 'dependencyTop-1.mat'));
assert(cacheInfoTop.datenum > sourceInfo.datenum, 'in ''autoremove'' mode, dependency change SHOULD trigger an update');
rmdir('.cache', 's');
rmdir('.meta', 's');
%% Test updated dependency -- call from bottom
options = struct();
options.onDependencyChange = 'warn';
options.defaultArgs = {[]}; % ignore first 'options' arg but not second numeric arg.
val = loadOrRun(@dependencyTop, {options, 1}, options);
assert(val == 2);
assert(exist(fullfile('.cache', 'dependencyBottom-1.mat'), 'file') > 0);
assert(exist(fullfile('.cache', 'dependencyTop-1.mat'), 'file') > 0);
% Modify 'bottom' (update it's timestamp with 'touch')
pause(1);
!touch testing/dependencyBottom.m
sourceInfo = dir(fullfile('testing', 'dependencyBottom.m'));
cacheInfo = dir(fullfile('.cache', 'dependencyTop-1.mat'));
assert(cacheInfo.datenum < sourceInfo.datenum, 'something went wrong with system call ''touch''');
% Directly call bottom of call stack
options.defaultArgs = {};
val = loadOrRun(@dependencyBottom, {1}, options);
assert(val == 2);
% Warning should have been issued, and both .mat files should still exist
assert(exist(fullfile('.cache', 'dependencyTop-1.mat'), 'file') > 0, 'in ''warn'' mode, dependency change should not trigger an update');
assert(exist(fullfile('.cache', 'dependencyBottom-1.mat'), 'file') > 0, 'in ''warn'' mode, dependency change should not trigger an update');
options.onDependencyChange = 'autoremove';
pause(1);
val = loadOrRun(@dependencyBottom, {1}, options);
assert(val == 2);
cacheInfo = dir(fullfile('.cache', 'dependencyBottom-1.mat'));
assert(cacheInfo.datenum > sourceInfo.datenum, 'in ''autoremove'' mode, cache for ''bottom'' should have been updated!');
assert(exist(fullfile('.cache', 'dependencyTop-1.mat'), 'file') > 0, 'expected behavior is that calling ''bottom'' does not auto-remove ''top'' (but it will be removed by a call to ''top'')');
rmdir('.cache', 's');
rmdir('.meta', 's');