Test: Merge bug.634.t with undo.t

This commit is contained in:
Renato Alves 2015-07-22 13:00:52 +01:00
parent 28cae3a8cb
commit 3c89d61a53
2 changed files with 20 additions and 66 deletions

View file

@ -1,61 +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 => 2;
# 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",
"confirmation=no\n";
close $fh;
}
# Bug 634: confirmation=off not honored by undo
# Setup: Add a task
qx{../src/task rc:$rc add Test 2>&1};
# Result: Attempt to undo add with confirmation=off
my $output = qx{echo 'n' | ../src/task rc:$rc rc.confirmation=off undo 2>&1};
like ($output, qr/^Task removed.$/ms, "$ut: Task removed.");
unlike ($output, qr/Are you sure/ms, "$ut: Undo honors confirmation=off.");
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data), $rc;
exit 0;

View file

@ -42,22 +42,22 @@ class TestUndo(TestCase):
def test_add_undo(self): def test_add_undo(self):
"""'add' then 'undo'""" """'add' then 'undo'"""
code, out, err = self.t('add one') self.t('add one')
code, out, err = self.t('_get 1.status') code, out, err = self.t('_get 1.status')
self.assertEqual(out.strip(), 'pending') self.assertEqual(out.strip(), 'pending')
code, out, err = self.t('undo') self.t('undo')
code, out, err = self.t('_get 1.status') code, out, err = self.t('_get 1.status')
self.assertEqual(out.strip(), '') self.assertEqual(out.strip(), '')
def test_add_done_undo(self): def test_add_done_undo(self):
"""'add' then 'done' then 'undo'""" """'add' then 'done' then 'undo'"""
code, out, err = self.t('add two') self.t('add two')
code, out, err = self.t('_get 1.status') code, out, err = self.t('_get 1.status')
self.assertEqual(out.strip(), 'pending') self.assertEqual(out.strip(), 'pending')
code, out, err = self.t('1 done') self.t('1 done')
code, out, err = self.t('_get 1.status') code, out, err = self.t('_get 1.status')
self.assertEqual(out.strip(), 'completed') self.assertEqual(out.strip(), 'completed')
code, out, err = self.t('undo') self.t('undo')
code, out, err = self.t('_get 1.status') code, out, err = self.t('_get 1.status')
self.assertEqual(out.strip(), 'pending') self.assertEqual(out.strip(), 'pending')
@ -67,6 +67,21 @@ class TestUndo(TestCase):
code, out, err = self.t.runError("undo +tag") code, out, err = self.t.runError("undo +tag")
self.assertIn("The undo command does not allow further task modification.", err) self.assertIn("The undo command does not allow further task modification.", err)
class TestBug634(TestCase):
def setUp(self):
self.t = Task()
def test_undo_no_confirmation(self):
"""Undo honors confirmation=off"""
self.t("add Test")
# If a prompt happens, the test will timeout on input (exitcode != 0)
code, out, err = self.t("rc.confirmation=off undo")
self.assertIn("Task removed", out)
if __name__ == "__main__": if __name__ == "__main__":
from simpletap import TAPTestRunner from simpletap import TAPTestRunner
unittest.main(testRunner=TAPTestRunner()) unittest.main(testRunner=TAPTestRunner())