File: oldest.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 (143 lines) | stat: -rwxr-xr-x 5,434 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
#! /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 => 54;

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

# Create the rc file.
if (open my $fh, '>', 'oldest.rc')
{
  print $fh "data.location=.\n";
  close $fh;
  ok (-r 'oldest.rc', 'Created oldest.rc');
}

# Add 11 tasks.  Oldest should show 1-10, newest should show 2-11.
qx{../src/task rc:oldest.rc add one 2>&1};
diag ("3 second delay");
sleep 1;
qx{../src/task rc:oldest.rc add two 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add three 2>&1};
sleep 1;
my $output = qx{../src/task rc:oldest.rc oldest 2>&1};
like ($output, qr/one/,               'oldest: one');
like ($output, qr/two/,               'oldest: two');
like ($output, qr/three/,             'oldest: three');
like ($output, qr/one.*two.*three/ms, 'oldest: sort');

$output = qx{../src/task rc:oldest.rc newest 2>&1};
like ($output, qr/three/,             'newest: three');
like ($output, qr/two/,               'newest: two');
like ($output, qr/one/,               'newest: one');
like ($output, qr/three.*two.*one/ms, 'newest: sort');

qx{../src/task rc:oldest.rc add four 2>&1};
diag ("7 second delay");
sleep 1;
qx{../src/task rc:oldest.rc add five 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add six 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add seven 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add eight 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add nine 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add ten 2>&1};
sleep 1;
qx{../src/task rc:oldest.rc add eleven 2>&1};

$output = qx{../src/task rc:oldest.rc oldest 2>&1};
like   ($output, qr/one/,    'oldest: one');   # 10
like   ($output, qr/two/,    'oldest: two');
like   ($output, qr/three/,  'oldest: three');
like   ($output, qr/four/,   'oldest: four');
like   ($output, qr/five/,   'oldest: five');
like   ($output, qr/six/,    'oldest: six');
like   ($output, qr/seven/,  'oldest: seven');
like   ($output, qr/eight/,  'oldest: eight');
like   ($output, qr/nine/,   'oldest: nine');
like   ($output, qr/ten/,    'oldest: ten');
unlike ($output, qr/eleven/, 'no: eleven');   # 20

$output = qx{../src/task rc:oldest.rc oldest limit:3 2>&1};
like   ($output, qr/one/,    'oldest: one');
like   ($output, qr/two/,    'oldest: two');
like   ($output, qr/three/,  'oldest: three');
unlike ($output, qr/four/,   'no: four');
unlike ($output, qr/five/,   'no: five');
unlike ($output, qr/six/,    'no: six');
unlike ($output, qr/seven/,  'no: seven');
unlike ($output, qr/eight/,  'no: eight');
unlike ($output, qr/nine/,   'no: nine');
unlike ($output, qr/ten/,    'no: ten');    # 30
unlike ($output, qr/eleven/, 'no: eleven');

$output = qx{../src/task rc:oldest.rc newest 2>&1};
unlike ($output, qr/one/,    'no: one');
like   ($output, qr/two/,    'newest: two');
like   ($output, qr/three/,  'newest: three');
like   ($output, qr/four/,   'newest: four');
like   ($output, qr/five/,   'newest: five');
like   ($output, qr/six/,    'newest: six');
like   ($output, qr/seven/,  'newest: seven');
like   ($output, qr/eight/,  'newest: eight');
like   ($output, qr/nine/,   'newest: nine');   # 40
like   ($output, qr/ten/,    'newest: ten');
like   ($output, qr/eleven/, 'newest: eleven');

$output = qx{../src/task rc:oldest.rc newest limit:3 2>&1};
unlike ($output, qr/one/,    'no: one');
unlike ($output, qr/two/,    'no: two');
unlike ($output, qr/three/,  'no: three');
unlike ($output, qr/four/,   'no: four');
unlike ($output, qr/five/,   'no: five');
unlike ($output, qr/six/,    'no: six');
unlike ($output, qr/seven/,  'no: seven');
unlike ($output, qr/eight/,  'no: eight');    # 50
like   ($output, qr/nine/,   'newest: nine');
like   ($output, qr/ten/,    'newest: ten');
like   ($output, qr/eleven/, 'newest: eleven');

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

exit 0;