File: dependencies.t

package info (click to toggle)
task 2.3.0%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,728 kB
  • ctags: 4,813
  • sloc: cpp: 34,267; perl: 18,509; python: 298; sh: 257; makefile: 73; ruby: 32
file content (272 lines) | stat: -rwxr-xr-x 12,001 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#! /usr/bin/env perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006-2014, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################

use strict;
use warnings;
use Test::More tests => 49;

# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};

# Create the rc file.
if (open my $fh, '>', 'dep.rc')
{
  print $fh "data.location=.\n";
  print $fh "dependency.confirmation=yes\n";
  print $fh "report.depreport.columns=id,depends,description\n";
  print $fh "report.depreport.labels=ID,Depends,Description\n";
  print $fh "report.depreport.filter=status:pending\n";
  print $fh "report.depreport.sort=depends+\n";
  close $fh;

  # [1]
  ok (-r 'dep.rc', 'Created dep.rc');
}

qx{../src/task rc:dep.rc add One 2>&1};
qx{../src/task rc:dep.rc add Two 2>&1};

# [2]
my $output = qx{../src/task rc:dep.rc 1 modify dep:-2 2>&1 >/dev/null};
like ($output, qr/Could not delete a dependency on task 2 - not found\./, 'dependencies - remove nonexistent dependency');

# [3]
$output = qx{../src/task rc:dep.rc 1 modify dep:99 2>&1 >/dev/null};
like ($output, qr/Could not create a dependency on task 99 - not found\./, 'dependencies - add dependency for nonexistent task');

# [4]
$output = qx{../src/task rc:dep.rc 99 modify dep:1 2>&1 >/dev/null};
like ($output, qr/No tasks specified\./, 'dependencies - add dependency to nonexistent task');

# [5,6] t 1 dep:2; t info 1 => blocked by 2
$output = qx{../src/task rc:dep.rc 1 modify dep:2 2>&1; ../src/task rc:dep.rc info 1 2>&1};
like ($output, qr/This task blocked by\s+2 Two\nUUID/, 'dependencies - trivial blocked');
unlike ($output, qr/This task is blocking\n/,          'dependencies - trivial blocked');

# [7,8] t info 2 => blocking 1
$output = qx{../src/task rc:dep.rc info 2 2>&1};
unlike ($output, qr/This task blocked by/,              'dependencies - trivial blocking');
like ($output, qr/This task is blocking\s+1 One\nUUID/, 'dependencies - trivial blocking');

# [9] t 1 dep:2 (again)
$output = qx{../src/task rc:dep.rc 1 modify dep:2 2>&1 >/dev/null};
like ($output, qr/Task 1 already depends on task 2\./, 'dependencies - add already existing dependency');

# [10,11] t 1 dep:1 => error
$output = qx{../src/task rc:dep.rc 1 modify dep:1 2>&1};
like   ($output, qr/A task cannot be dependent on itself\./, 'dependencies - cannot depend on self');
unlike ($output, qr/Modified 1 task\./,                      'dependencies - cannot depend on self');

# [12,13] t 1 dep:2; t 2 dep:1 => error
$output = qx{../src/task rc:dep.rc 2 modify dep:1 2>&1};
like   ($output, qr/Circular dependency detected and disallowed\./, 'dependencies - trivial circular');
unlike ($output, qr/Modified 1 task\./,                             'dependencies - trivial circular');

# [14,15] t 1 dep:2; t 2 dep:3; t 1 dep:3 => not circular
qx{../src/task rc:dep.rc 1 modify dep:2 2>&1};
qx{../src/task rc:dep.rc add Three 2>&1};
qx{../src/task rc:dep.rc 2 modify dep:3 2>&1};
$output = qx{../src/task rc:dep.rc 1 modify dep:3 2>&1};
unlike ($output, qr/Circular dependency detected and disallowed\./, 'dependencies - diamond, non-circular');
like   ($output, qr/Modified 1 task\./,                             'dependencies - diamond, non-circular');

# [16]
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data for a fresh start');

qx{../src/task rc:dep.rc add One 2>&1};
qx{../src/task rc:dep.rc add Two 2>&1};
qx{../src/task rc:dep.rc add Three 2>&1};
qx{../src/task rc:dep.rc add Four 2>&1};
qx{../src/task rc:dep.rc add Five 2>&1};

qx{../src/task rc:dep.rc 5 modify dep:4 2>&1; ../src/task rc:dep.rc 4 modify dep:3 2>&1; ../src/task rc:dep.rc 3 modify dep:2 2>&1; ../src/task rc:dep.rc 2 modify dep:1 2>&1};

# [17,18] 5 dep 4 dep 3 dep 2 dep 1 dep 5 => error
$output = qx{../src/task rc:dep.rc 1 modify dep:5 2>&1 >/dev/null};
like   ($output, qr/Circular dependency detected and disallowed\./, 'dependencies - nontrivial circular');
unlike ($output, qr/Modified 1 task\./,                             'dependencies - nontrivial circular');

# [19]
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data for a fresh start');

qx{../src/task rc:dep.rc add One 2>&1};
qx{../src/task rc:dep.rc add Two 2>&1};
qx{../src/task rc:dep.rc add Three 2>&1};
qx{../src/task rc:dep.rc add Four 2>&1};
qx{../src/task rc:dep.rc add Five 2>&1};
qx{../src/task rc:dep.rc add Six recurring due:tomorrow recur:daily 2>&1};

# [20]
qx{../src/task rc:dep.rc ls 2>&1}; # To force handleRecurrence call.
$output = qx{echo 'y' | ../src/task rc:dep.rc 6 modify dep:5 2>&1};
like ($output, qr/Modified \d+ task/, 'dependencies - recurring task depending on another task');

# [21]
$output = qx{../src/task rc:dep.rc 4 modify dep:5 2>&1};
like ($output, qr/Modified \d+ task/, 'dependencies - task depending on recurring task');

# [22] t 1 dep:2,3,4; t 1 dep:-2,-4,5; t info 1 => blocked by 3,5
$output = qx{../src/task rc:dep.rc 1 modify dep:2,3,4 2>&1; ../src/task rc:dep.rc 1 modify dep:-2,-4,5 2>&1; ../src/task rc:dep.rc info 1 2>&1};
like ($output, qr/This task blocked by\s+3 Three\n\s+5 Five\nUUID/, 'dependencies - multiple dependencies modified');

# [23,24]
$output = qx{../src/task rc:dep.rc 3,5 do 2>&1; ../src/task rc:dep.rc info 1 2>&1};
unlike ($output, qr/This task blocked by/, 'dependencies - task info reflects completed dependencies');
unlike ($output, qr/This task is blocking/, 'dependencies - task info reflects completed dependencies');

# [25]
$output = qx{../src/task rc:dep.rc depreport 2>&1};
like ($output, qr/\s1\s+One\s+/, 'dependencies - depends report column reflects completed dependencies');

# [26]
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data for a fresh start');

qx{../src/task rc:dep.rc add One 2>&1};
qx{../src/task rc:dep.rc add Two 2>&1};
qx{../src/task rc:dep.rc add Three 2>&1};
qx{../src/task rc:dep.rc add Four 2>&1};

qx{../src/task rc:dep.rc 1 modify dep:3,4 2>&1};
qx{../src/task rc:dep.rc 2 do 2>&1};

# [27]
$output = qx{../src/task rc:dep.rc depreport 2>&1};
like ($output, qr/\s1\s+2 3\s+One\s+/, 'dependencies - depends report column reflects changed IDs');

# [28]
qx{../src/task rc:dep.rc 3 do 2>&1};
$output = qx{../src/task rc:dep.rc depreport 2>&1};
like ($output, qr/\s1\s+2\s+One\s+/, 'dependencies - depends report column reflects completed dependencies');

# [29]
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data for a fresh start');

qx{../src/task rc:dep.rc add One 2>&1};
qx{../src/task rc:dep.rc add Two 2>&1};
qx{../src/task rc:dep.rc add Three 2>&1};
qx{../src/task rc:dep.rc add Four 2>&1};

qx{../src/task rc:dep.rc 2 modify dep:1 2>&1; ../src/task rc:dep.rc 3 modify dep:2 2>&1; ../src/task rc:dep.rc 4 modify dep:3 2>&1};

# [30,31]
$output = qx{echo 'y' | ../src/task rc:dep.rc 2 do 2>&1};
like ($output, qr/fixed/, 'dependencies - user prompted to fix broken chain after completing a blocked task');
like ($output, qr/is blocked by/, 'dependencies - user nagged for completing a blocked task');

# [32]
$output = qx{echo 'y' | ../src/task rc:dep.rc 1 do 2>&1};
unlike ($output, qr/fixed/, 'dependencies - user not prompted to fix broken chain when the head of the chain is marked as complete');

# [33]
$output = qx{echo 'y' | ../src/task rc:dep.rc 4 del 2>&1};
unlike ($output, qr/fixed/, 'dependencies - user not prompted to fix broken chain when the tail of the chain is deleted');

# [34]
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data for a fresh start');

qx{../src/task rc:dep.rc add One 2>&1};
qx{../src/task rc:dep.rc add Two 2>&1};
qx{../src/task rc:dep.rc add Three 2>&1};
qx{../src/task rc:dep.rc add Four 2>&1};
qx{../src/task rc:dep.rc add Five 2>&1};

qx{../src/task rc:dep.rc 2 modify dep:1 2>&1};
qx{../src/task rc:dep.rc 3 modify dep:2 2>&1};
qx{../src/task rc:dep.rc 4 modify dep:3 2>&1};
qx{../src/task rc:dep.rc 5 modify dep:4 2>&1};

# [35]
qx{echo 'y' | ../src/task rc:dep.rc 2 do 2>&1};
$output = qx{../src/task rc:dep.rc depreport 2>&1};
like ($output, qr/\s1\s+One\s*\n\s2\s+1\s+Three\s*\n\s3\s+2\s+Four\s*\n\s4\s+3\s+Five/, 'dependencies - fixed chain after completing a blocked task');

# [36]
qx{echo "Y\nY\n" | ../src/task rc:dep.rc 2 del 2>&1};
$output = qx{../src/task rc:dep.rc depreport 2>&1};
like ($output, qr/\s1\s+One\s*\n\s2\s+1\s+Four\s*\n\s3\s+2\s+Five/, 'dependencies - fixed chain after deleting a blocked task');

# [37]
qx{../src/task rc:dep.rc 2 modify dep:-1 2>&1};
$output = qx{../src/task rc:dep.rc depreport 2>&1};
like ($output, qr/\s1\s+One\s*\n\s2\s+Four\s*\n\s3\s+2\s+Five/, 'dependencies - chain should not be automatically repaired after manually removing a dependency');

# [38]
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data for a fresh start');

# Bug when adding a range of dependencies - 'task 3 mod dep:1-2' interprets the
# range 1-2 as the id 1

qx{../src/task rc:dep.rc add test1 2>&1};
qx{../src/task rc:dep.rc add test2 2>&1};
qx{../src/task rc:dep.rc add test3 2>&1};
qx{../src/task rc:dep.rc add test4 2>&1};
qx{../src/task rc:dep.rc add test5 2>&1};
$output = qx{../src/task rc:dep.rc 5 info 2>&1};
my ($uuid) = $output =~ /UUID\s+(\S+)/;

# [39-43] test a comma-separated list of IDs, UUIDs, and ID ranges for creation
qx{../src/task rc:dep.rc add test6 dep:1-3,4,$uuid 2>&1};
$output = qx{../src/task rc:dep.rc 6 info 2>&1};
like ($output, qr/test1/ms, 'Dependency appearing for task1');
like ($output, qr/test2/ms, 'Dependency appearing for task2');
like ($output, qr/test3/ms, 'Dependency appearing for task3');
like ($output, qr/test4/ms, 'Dependency appearing for task4');
like ($output, qr/test5/ms, 'Dependency appearing for task5');

# [44-48] test a comma-separated list of IDs, UUIDs, and ID ranges for deletion
qx{../src/task rc:dep.rc 6 mod dep:-1-3,-4,-$uuid 2>&1};
$output = qx{../src/task rc:dep.rc 6 info 2>&1};
unlike ($output, qr/test1/ms, 'Dependency not appearing for task1');
unlike ($output, qr/test2/ms, 'Dependency not appearing for task2');
unlike ($output, qr/test3/ms, 'Dependency not appearing for task3');
unlike ($output, qr/test4/ms, 'Dependency not appearing for task4');
unlike ($output, qr/test5/ms, 'Dependency not appearing for task5');

# TODO - test dependency.confirmation config variable
# TODO - test undo on backing out chain gap repair
# TODO - test undo on backing out choice to not perform chain gap repair
# TODO - test blocked task completion nag
# TODO - test depend.any and depend.none report filters

# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data dep.rc);
ok (! -r 'pending.data'   &&
    ! -r 'completed.data' &&
    ! -r 'undo.data'      &&
    ! -r 'backlog.data'   &&
    ! -r 'dep.rc', 'Cleanup');

exit 0;