mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Tests: Merge bug.438 with sorting.t
This commit is contained in:
parent
c3423243d8
commit
00ee5dd7a3
2 changed files with 65 additions and 109 deletions
105
test/bug.438.t
105
test/bug.438.t
|
@ -1,105 +0,0 @@
|
|||
#! /usr/bin/env perl
|
||||
################################################################################
|
||||
##
|
||||
## Copyright 2006 - 2015, 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 => 12;
|
||||
|
||||
# Ensure environment has no influence.
|
||||
delete $ENV{'TASKDATA'};
|
||||
delete $ENV{'TASKRC'};
|
||||
|
||||
use File::Basename;
|
||||
my $ut = basename ($0);
|
||||
my $rc = $ut . '.rc';
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', $rc)
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"dateformat=SNHDMY\n",
|
||||
"report.foo.columns=entry,start,end,description\n",
|
||||
"report.foo.dateformat=SNHDMY\n",
|
||||
"confirmation=off\n";
|
||||
close $fh;
|
||||
}
|
||||
|
||||
# Bug #438: Reports sorting by end, start, and entry are ordered incorrectly, if
|
||||
# time is included.
|
||||
|
||||
if (open my $fh, '>', 'pending.data')
|
||||
{
|
||||
my $entry = time () - 3600; # An hour ago.
|
||||
|
||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000001" status:"pending" description:"one older" entry:"$entry"]\n};
|
||||
$entry++;
|
||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000002" status:"pending" description:"one newer" entry:"$entry"]\n};
|
||||
|
||||
my $start = $entry + 10;
|
||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000003" status:"pending" description:"two older" entry:"$entry" start:"$start"]\n};
|
||||
$start++;
|
||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000004" status:"pending" description:"two newer" entry:"$entry" start:"$start"]\n};
|
||||
|
||||
my $end = $start + 10;
|
||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000005" status:"completed" description:"three older" entry:"$entry" end:"$end"]\n};
|
||||
$end++;
|
||||
print $fh qq{[uuid:"00000000-0000-0000-0000-000000000006" status:"completed" description:"three newer" entry:"$entry" end:"$end"]\n};
|
||||
|
||||
close $fh;
|
||||
}
|
||||
|
||||
# Sorting by entry +/-
|
||||
my $output = qx{../src/task rc:$rc rc.report.foo.sort:entry+ foo 2>&1};
|
||||
ok ($? == 0, "$ut: entry foo");
|
||||
like ($output, qr/one older.+one newer/ms, "$ut: sort:entry+ -> older newer");
|
||||
|
||||
$output = qx{../src/task rc:$rc rc.report.foo.sort:entry- foo 2>&1};
|
||||
ok ($? == 0, "$ut: entry foo");
|
||||
like ($output, qr/one newer.+one older/ms, "$ut: sort:entry- -> newer older");
|
||||
|
||||
# Sorting by start +/-
|
||||
$output = qx{../src/task rc:$rc rc.report.foo.sort:start+ foo 2>&1};
|
||||
ok ($? == 0, "$ut: start foo");
|
||||
like ($output, qr/two older.+two newer/ms, "$ut: sort:start+ -> older newer");
|
||||
|
||||
$output = qx{../src/task rc:$rc rc.report.foo.sort:start- foo 2>&1};
|
||||
ok ($? == 0, "$ut: start foo");
|
||||
like ($output, qr/two newer.+two older/ms, "$ut: sort:start- -> newer older");
|
||||
|
||||
# Sorting by end +/-
|
||||
$output = qx{../src/task rc:$rc rc.report.foo.sort:end+ foo 2>&1};
|
||||
ok ($? == 0, "$ut: end foo");
|
||||
like ($output, qr/three older.+three newer/ms, "$ut: sort:end+ -> older newer");
|
||||
|
||||
$output = qx{../src/task rc:$rc rc.report.foo.sort:end- foo 2>&1};
|
||||
ok ($? == 0, "$ut: end foo");
|
||||
like ($output, qr/three newer.+three older/ms, "$ut: sort:end- -> newer older");
|
||||
|
||||
# Cleanup.
|
||||
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
|
||||
exit 0;
|
||||
|
|
@ -30,6 +30,7 @@ import sys
|
|||
import os
|
||||
import re
|
||||
import unittest
|
||||
import time
|
||||
# Ensure python finds the local simpletap module
|
||||
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
@ -43,11 +44,12 @@ class MetaTests(type):
|
|||
filter used.
|
||||
"""
|
||||
@staticmethod
|
||||
def _make_function(filter, expectations):
|
||||
def _make_function(prefix, filter, expectations):
|
||||
def test(self):
|
||||
# ### Body of the usual test_testcase ### #
|
||||
code, out, err = self.t(
|
||||
("rc.report.list.sort:{0}".format(filter), "list")
|
||||
("rc.report.{0}.sort:{1}".format(self._report, filter),
|
||||
self._report)
|
||||
)
|
||||
|
||||
for expected in expectations:
|
||||
|
@ -55,7 +57,7 @@ class MetaTests(type):
|
|||
self.assertRegexpMatches(out, regex)
|
||||
|
||||
# Title of test in report
|
||||
test.__doc__ = "sort:{0}".format(filter)
|
||||
test.__doc__ = "{0} sort:{1}".format(prefix, filter)
|
||||
|
||||
# Rename the function according to its parameters
|
||||
# Name of function must start with test_ to be ran by unittest
|
||||
|
@ -71,7 +73,7 @@ class MetaTests(type):
|
|||
tests = dct.get("TESTS")
|
||||
|
||||
for filter, expectations in tests.iteritems():
|
||||
func = meta._make_function(filter, expectations)
|
||||
func = meta._make_function(name, filter, expectations)
|
||||
|
||||
# Ensure function exists only once
|
||||
try:
|
||||
|
@ -94,6 +96,9 @@ class TestSorting(TestCase):
|
|||
def setUpClass(cls):
|
||||
cls.t = Task()
|
||||
|
||||
# Report to use when running this class's tests
|
||||
cls._report = "list"
|
||||
|
||||
cls.t(("add", "zero"))
|
||||
cls.t(("add", "priority:H", "project:A", "due:yesterday", "one"))
|
||||
cls.t(("add", "priority:M", "project:B", "due:today", "two"))
|
||||
|
@ -223,6 +228,62 @@ class TestSorting(TestCase):
|
|||
}
|
||||
|
||||
|
||||
class TestBug438(TestCase):
|
||||
__metaclass__ = MetaTests
|
||||
|
||||
# Bug #438: Reports sorting by end, start, and entry are ordered
|
||||
# incorrectly, if time is included.
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.t = Task()
|
||||
|
||||
# Report to use when running this class's tests
|
||||
cls._report = "foo"
|
||||
|
||||
cls.t.config("dateformat", "SNHDMY")
|
||||
cls.t.config("report.foo.columns", "entry,start,end,description")
|
||||
cls.t.config("report.foo.dateformat", "SNHDMY")
|
||||
|
||||
# Preparing data:
|
||||
# 2 tasks created in the past, 1 second apart
|
||||
# 2 tasks created in the past, and started 10 seconds later
|
||||
# 2 tasks created in the past, and finished 20 seconds later
|
||||
|
||||
stamp = int(time.time())
|
||||
cls.t(("add", "one older",
|
||||
"entry:{0}".format(stamp)))
|
||||
stamp += 1
|
||||
cls.t(("add", "one newer",
|
||||
"entry:{0}".format(stamp)))
|
||||
|
||||
start = stamp + 10
|
||||
cls.t(("add", "two older",
|
||||
"entry:{0}".format(stamp),
|
||||
"start:{0}".format(start)))
|
||||
start += 1
|
||||
cls.t(("add", "two newer",
|
||||
"entry:{0}".format(stamp),
|
||||
"start:{0}".format(start)))
|
||||
|
||||
end = start + 10
|
||||
cls.t(("log", "three older",
|
||||
"entry:{0}".format(stamp),
|
||||
"end:{0}".format(end)))
|
||||
end += 1
|
||||
cls.t(("log", "three newer",
|
||||
"entry:{0}".format(stamp),
|
||||
"end:{0}".format(end)))
|
||||
|
||||
TESTS = {
|
||||
"entry+": ["one older.+one newer"],
|
||||
"entry-": ["one newer.+one older"],
|
||||
"start+": ["two older.+two newer"],
|
||||
"start-": ["two newer.+two older"],
|
||||
"end+": ["three older.+three newer"],
|
||||
"end-": ["three newer.+three older"],
|
||||
}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from simpletap import TAPTestRunner
|
||||
unittest.main(testRunner=TAPTestRunner())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue