From 9470e9af17f42630182f37c950a1196576eae749 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 16 Mar 2011 00:53:29 -0400 Subject: [PATCH] New 'ids' command, and stdin reading - New 'ids' command that returns a filtered set of task ID numbers, instead of the actual tasks. For advanced pipeline use. - Now supplements the command line with data read from standard input, which allows commands like: echo 'add Pay the bills' | task --- ChangeLog | 6 ++++- NEWS | 7 +++-- src/Cmd.cpp | 2 ++ src/Context.cpp | 22 ++++++++++++++++ src/command.cpp | 30 +++++++++++++++++++++ src/main.cpp | 2 +- src/main.h | 1 + src/report.cpp | 4 +++ src/util.cpp | 55 +++++++++++++++++++++++++++++++++++++++ src/util.h | 1 + test/bug.605.t.postponed | 2 +- test/bug.634.t | 2 +- test/bug.bulk.t | 4 +-- test/confirmation.t | 30 ++++++++++----------- test/delete.t | 2 +- test/dependencies.t | 12 ++++----- test/hook.format-prompt.t | 2 +- test/hook.pre-completed.t | 4 +-- test/rc.t | 18 ++++++------- test/sequence.t | 8 +++--- test/shell.t | 4 +-- test/undo.t | 5 ++-- 22 files changed, 173 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc5a7d3ed..684dc6feb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,9 +3,13 @@ 2.0.0 () + autoconf eliminated. + + New 'ids' command that returns a filtered set of task ID numbers, instead + of the actual tasks. For advanced pipeline use. + + Now supplements the command line with data read from standard input, which + allows commands like: echo 'add Pay the bills' | task + + Added feature #700, which adds tab-completion of built-in tags. + Corrected sorting to use std::stable_sort instead of std::sort, which is not guaranteed stable (thanks to Stefan Hacker). - + Added feature #700, which adds tab-completion of built-in tags. ------ old releases ------------------------------ diff --git a/NEWS b/NEWS index 68da31550..dbb060f32 100644 --- a/NEWS +++ b/NEWS @@ -1,14 +1,17 @@ New Features in taskwarrior 2.0.0 - - + - New 'ids' command that returns a filtered set of task ID numbers, instead + of the actual tasks. For advanced pipeline use. + - Now supplements the command line with data read from standard input, which + allows commands like: echo 'add Pay the bills' | task Please refer to the ChangeLog file for full details. There are too many to list here. New commands in taskwarrior 2.0.0 - - + - "ids" command that accepts filters, and returns an ID sequence. New configuration options in taskwarrior 2.0.0 diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 1a6a42f11..cc4d232a4 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -149,6 +149,7 @@ void Cmd::load () commands.push_back ("burndown.weekly"); commands.push_back ("burndown.monthly"); commands.push_back ("count"); + commands.push_back ("ids"); // Commands whose names are localized. commands.push_back (context.stringtable.get (CMD_ADD, "add")); @@ -258,6 +259,7 @@ bool Cmd::isReadOnlyCommand () command == "burndown.weekly" || command == "burndown.monthly" || command == "count" || + command == "ids" || command == context.stringtable.get (CMD_CALENDAR, "calendar") || command == context.stringtable.get (CMD_COLORS, "colors") || command == context.stringtable.get (CMD_DIAGNOSTICS, "diagnostics") || diff --git a/src/Context.cpp b/src/Context.cpp index e66b2d0c8..cbff74dfa 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "Context.h" #include "Directory.h" #include "File.h" @@ -84,6 +85,26 @@ void Context::initialize (int argc, char** argv) args.push_back (argv[i]); } + // Capture any stdin args. + struct timeval tv; + fd_set fds; + tv.tv_sec = 0; + tv.tv_usec = 0; + FD_ZERO (&fds); + FD_SET (STDIN_FILENO, &fds); + select (STDIN_FILENO + 1, &fds, NULL, NULL, &tv); + if (FD_ISSET (0, &fds)) + { + std::string arg; + while (std::cin >> arg) + { + if (arg == "--") + break; + + args.push_back (arg); + } + } + initialize (); // Hook system init, plus post-start event occurring at the first possible @@ -263,6 +284,7 @@ int Context::dispatch (std::string &out) else if (cmd.command == "pull") { handlePull (out); } else if (cmd.command == "diagnostics") { handleDiagnostics (out); } else if (cmd.command == "count") { rc = handleCount (out); } + else if (cmd.command == "ids") { rc = handleIds (out); } else if (cmd.command == "_projects") { rc = handleCompletionProjects (out); } else if (cmd.command == "_tags") { rc = handleCompletionTags (out); } else if (cmd.command == "_commands") { rc = handleCompletionCommands (out); } diff --git a/src/command.cpp b/src/command.cpp index 4ba1ea6a0..fb9b5f4ca 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -2398,6 +2398,36 @@ int handleCount (std::string& outs) return rc; } +//////////////////////////////////////////////////////////////////////////////// +int handleIds (std::string& outs) +{ + int rc = 0; + + if (context.hooks.trigger ("pre-ids-command")) + { + // Scan the pending tasks, applying any filter. + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + handleRecurrence (); + context.tdb.load (tasks, context.filter); + context.tdb.commit (); + context.tdb.unlock (); + + // Find number of matching tasks. + std::vector ids; + foreach (task, tasks) + if (task->id) + ids.push_back (task->id); + + std::sort (ids.begin (), ids.end ()); + outs = compressIds (ids) + "\n"; + + context.hooks.trigger ("post-ids-command"); + } + + return rc; +} + //////////////////////////////////////////////////////////////////////////////// #ifdef FEATURE_SHELL void handleShell () diff --git a/src/main.cpp b/src/main.cpp index 0662e962c..80ae4771a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -64,7 +64,7 @@ int main (int argc, char** argv) { context.initialize (argc, argv); -/* From 2.0.0 +/* From old 2.0.0 std::string::size_type task = context.program.find ("/task"); std::string::size_type t = context.program.find ("/t"); std::string::size_type cal = context.program.find ("/cal"); diff --git a/src/main.h b/src/main.h index cf7fe84c0..cd1c57761 100644 --- a/src/main.h +++ b/src/main.h @@ -84,6 +84,7 @@ int handleAnnotate (std::string&); int handleDenotate (std::string&); int handleDuplicate (std::string&); int handleCount (std::string&); +int handleIds (std::string&); void handleUndo (); void handleMerge (std::string&); void handlePush (std::string&); diff --git a/src/report.cpp b/src/report.cpp index 053a4e5ed..69ed26425 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -244,6 +244,10 @@ int shortUsage (std::string& outs) table.addCell (row, 1, "task count [filter]"); table.addCell (row, 2, "Shows only the number of matching tasks."); + row = table.addRow (); + table.addCell (row, 1, "task ids [filter]"); + table.addCell (row, 2, "Shows only the IDs of matching tasks, in the form of a range."); + row = table.addRow (); table.addCell (row, 1, "task version"); table.addCell (row, 2, "Shows the task version number."); diff --git a/src/util.cpp b/src/util.cpp index a2da529cf..f01239011 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -577,3 +577,58 @@ std::string renderAttribute (const std::string& name, const std::string& value) } //////////////////////////////////////////////////////////////////////////////// +// The vector must be sorted first. This is a modified version of the run- +// length encoding algorithm. +// +// This function converts the vector: +// +// [1, 3, 4, 6, 7, 8, 9, 11] +// +// to ths string: +// +// 1,3-4,6-9,11 +// +std::string compressIds (const std::vector & ids) +{ + std::stringstream result; + + int range_start = 0; + int range_end = 0; + + for (int i = 0; i < ids.size (); ++i) + { + if (i + 1 == ids.size ()) + { + if (result.str ().length ()) + result << ","; + + if (range_start < range_end) + result << ids[range_start] << "-" << ids[range_end]; + else + result << ids[range_start]; + } + else + { + if (ids[range_end] + 1 == ids[i + 1]) + { + ++range_end; + } + else + { + if (result.str ().length ()) + result << ","; + + if (range_start < range_end) + result << ids[range_start] << "-" << ids[range_end]; + else + result << ids[range_start]; + + range_start = range_end = i + 1; + } + } + } + + return result.str (); +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/util.h b/src/util.h index d09235544..4108b052c 100644 --- a/src/util.h +++ b/src/util.h @@ -72,6 +72,7 @@ bool taskDiff (const Task&, const Task&); std::string taskDifferences (const Task&, const Task&); std::string taskInfoDifferences (const Task&, const Task&); std::string renderAttribute (const std::string&, const std::string&); +std::string compressIds (const std::vector &); #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/test/bug.605.t.postponed b/test/bug.605.t.postponed index ae06fc4f6..36429b9a8 100755 --- a/test/bug.605.t.postponed +++ b/test/bug.605.t.postponed @@ -44,7 +44,7 @@ if (open my $fh, '>', 'bug.rc') qx{../src/task rc:bug.rc add One project:p1}; # Delete the task and note the completion status of the project -my $output = qx{echo 'y' | ../src/task rc:bug.rc del 1}; +my $output = qx{echo '-- y' | ../src/task rc:bug.rc del 1}; like ($output, qr/is 100\% complete/ms, 'Empty project correctly reported as being 100% completed.'); # Cleanup. diff --git a/test/bug.634.t b/test/bug.634.t index 9ae10469b..52d24f85b 100755 --- a/test/bug.634.t +++ b/test/bug.634.t @@ -45,7 +45,7 @@ if (open my $fh, '>', 'bug.rc') qx{../src/task rc:bug.rc add Test}; # Result: Attempt to undo add with confirmation=off -my $output = qx{echo 'n' |../src/task rc:bug.rc rc.confirmation=off undo}; +my $output = qx{echo '-- n' |../src/task rc:bug.rc rc.confirmation=off undo}; unlike ($output, qr/Are you sure/ms, 'Undo honours confirmation=off.'); # Cleanup. diff --git a/test/bug.bulk.t b/test/bug.bulk.t index 0ae3b7686..cc4e1a222 100755 --- a/test/bug.bulk.t +++ b/test/bug.bulk.t @@ -49,10 +49,10 @@ qx{../src/task rc:bulk.rc add t4 due:thursday}; qx{../src/task rc:bulk.rc add t5 due:friday}; qx{../src/task rc:bulk.rc add t6 due:saturday}; -my $output = qx{echo "quit"|../src/task rc:bulk.rc pro:p1 pri:M 4 5 6}; +my $output = qx{echo "-- quit"|../src/task rc:bulk.rc pro:p1 pri:M 4 5 6}; like ($output, qr/Modified 0 tasks/, '"quit" prevents any further modifications'); -$output = qx{echo "All"|../src/task rc:bulk.rc pro:p1 pri:M 4 5 6}; +$output = qx{echo "-- All"|../src/task rc:bulk.rc pro:p1 pri:M 4 5 6}; unlike ($output, qr/Task 4 "t4"\n - No changes were made/, 'Task 4 modified'); unlike ($output, qr/Task 5 "t5"\n - No changes were made/, 'Task 5 modified'); unlike ($output, qr/Task 6 "t6"\n - No changes were made/, 'Task 6 modified'); diff --git a/test/confirmation.t b/test/confirmation.t index 292adca69..313cd7c19 100755 --- a/test/confirmation.t +++ b/test/confirmation.t @@ -42,7 +42,7 @@ if (open my $fh, '>', 'confirm.rc') # Create the response file. if (open my $fh, '>', 'response.txt') { - print $fh "\n\nn\n"; + print $fh "-- \n\nn\n"; close $fh; ok (-r 'response.txt', 'Created response.txt'); } @@ -50,49 +50,49 @@ if (open my $fh, '>', 'response.txt') qx{../src/task rc:confirm.rc add foo} for 1..10; # Test the various forms of "Yes". -my $output = qx{echo "Yes" | ../src/task rc:confirm.rc del 1}; +my $output = qx{echo "-- Yes" | ../src/task rc:confirm.rc del 1}; like ($output, qr/Permanently delete task 1 'foo'\? \(y\/n\)/, 'confirmation - Yes works'); unlike ($output, qr/Task not deleted\./, 'confirmation - Yes works'); -$output = qx{echo "ye" | ../src/task rc:confirm.rc del 2}; +$output = qx{echo "-- ye" | ../src/task rc:confirm.rc del 2}; like ($output, qr/Permanently delete task 2 'foo'\? \(y\/n\)/, 'confirmation - ye works'); unlike ($output, qr/Task not deleted\./, 'confirmation - ye works'); -$output = qx{echo "y" | ../src/task rc:confirm.rc del 3}; +$output = qx{echo "-- y" | ../src/task rc:confirm.rc del 3}; like ($output, qr/Permanently delete task 3 'foo'\? \(y\/n\)/, 'confirmation - y works'); unlike ($output, qr/Task not deleted\./, 'confirmation - y works'); -$output = qx{echo "YES" | ../src/task rc:confirm.rc del 4}; +$output = qx{echo "-- YES" | ../src/task rc:confirm.rc del 4}; like ($output, qr/Permanently delete task 4 'foo'\? \(y\/n\)/, 'confirmation - YES works'); unlike ($output, qr/Task not deleted\./, 'confirmation - YES works'); -$output = qx{echo "YE" | ../src/task rc:confirm.rc del 5}; +$output = qx{echo "-- YE" | ../src/task rc:confirm.rc del 5}; like ($output, qr/Permanently delete task 5 'foo'\? \(y\/n\)/, 'confirmation - YE works'); unlike ($output, qr/Task not deleted\./, 'confirmation - YE works'); -$output = qx{echo "Y" | ../src/task rc:confirm.rc del 6}; +$output = qx{echo "-- Y" | ../src/task rc:confirm.rc del 6}; like ($output, qr/Permanently delete task 6 'foo'\? \(y\/n\)/, 'confirmation - Y works'); unlike ($output, qr/Task not deleted\./, 'confirmation - Y works'); # Test the various forms of "no". -$output = qx{echo "no" | ../src/task rc:confirm.rc del 7}; +$output = qx{echo "-- no" | ../src/task rc:confirm.rc del 7}; like ($output, qr/Permanently delete task 7 'foo'\? \(y\/n\)/, 'confirmation - no works'); like ($output, qr/Task not deleted\./, 'confirmation - no works'); -$output = qx{echo "n" | ../src/task rc:confirm.rc del 7}; +$output = qx{echo "-- n" | ../src/task rc:confirm.rc del 7}; like ($output, qr/Permanently delete task 7 'foo'\? \(y\/n\)/, 'confirmation - n works'); like ($output, qr/Task not deleted\./, 'confirmation - n works'); -$output = qx{echo "NO" | ../src/task rc:confirm.rc del 7}; +$output = qx{echo "-- NO" | ../src/task rc:confirm.rc del 7}; like ($output, qr/Permanently delete task 7 'foo'\? \(y\/n\)/, 'confirmation - NO works'); like ($output, qr/Task not deleted\./, 'confirmation - NO works'); -$output = qx{echo "N" | ../src/task rc:confirm.rc del 7}; +$output = qx{echo "-- N" | ../src/task rc:confirm.rc del 7}; like ($output, qr/Permanently delete task 7 'foo'\? \(y\/n\)/, 'confirmation - N works'); like ($output, qr/Task not deleted\./, 'confirmation - N works'); # Test Yes for multiple changes -$output = qx{echo -e "y\nY\nY\nY\nY" | ../src/task rc:confirm.rc 7-10 +bar}; +$output = qx{echo -e "-- y\nY\nY\nY\nY" | ../src/task rc:confirm.rc 7-10 +bar}; like ($output, qr/Proceed with change\? \(yes\/no\/all\/quit\)/, 'multiple confirmations - Y works'); like ($output, qr/Task 7 "foo"/, 'multiple confirmations - Y works'); like ($output, qr/Task 8 "foo"/, 'multiple confirmations - Y works'); @@ -101,7 +101,7 @@ like ($output, qr/Task 10 "foo"/, 'multiple confirmations - Y works'); like ($output, qr/Modified 4 tasks/, 'multiple confirmations - Y works'); # Test no for multiple changes -$output = qx{echo -e "N\nn\nn\nn\nn" | ../src/task rc:confirm.rc 7-10 -bar}; +$output = qx{echo -e "-- N\nn\nn\nn\nn" | ../src/task rc:confirm.rc 7-10 -bar}; like ($output, qr/Proceed with change\? \(yes\/no\/all\/quit\)/, 'multiple confirmations - n works'); like ($output, qr/Task 7 "foo"/, 'multiple confirmations - n works'); like ($output, qr/Task 8 "foo"/, 'multiple confirmations - n works'); @@ -110,14 +110,14 @@ like ($output, qr/Task 10 "foo"/, 'multiple confirmations - n works'); like ($output, qr/Modified 0 tasks/, 'multiple confirmations - n works'); # Test All for multiple changes -$output = qx{echo -e "a\nA" | ../src/task rc:confirm.rc 7-10 -bar}; +$output = qx{echo -e "-- a\nA" | ../src/task rc:confirm.rc 7-10 -bar}; like ($output, qr/Proceed with change\? \(yes\/no\/all\/quit\)/, 'multiple confirmations - A works'); like ($output, qr/Task 7 "foo"/, 'multiple confirmations - A works'); unlike ($output, qr/Task 8 "foo"/, 'multiple confirmations - A works'); like ($output, qr/Modified 4 tasks/, 'multiple confirmations - A works'); # Test quit for multiple changes -$output = qx{echo "q" | ../src/task rc:confirm.rc 7-10 +bar}; +$output = qx{echo "-- q" | ../src/task rc:confirm.rc 7-10 +bar}; like ($output, qr/Proceed with change\? \(yes\/no\/all\/quit\)/, 'multiple confirmations - q works'); like ($output, qr/Task 7 "foo"/, 'multiple confirmations - q works'); unlike ($output, qr/Task 8 "foo"/, 'multiple confirmations - q works'); diff --git a/test/delete.t b/test/delete.t index af882e9f7..e7a275bfd 100755 --- a/test/delete.t +++ b/test/delete.t @@ -49,7 +49,7 @@ $output = qx{../src/task rc:delete.rc delete 1; ../src/task rc:delete.rc info 1} like ($output, qr/Status\s+Deleted\n/, 'Deleted'); ok (-r 'completed.data', 'completed.data created'); -$output = qx{echo 'y' | ../src/task rc:delete.rc undo; ../src/task rc:delete.rc info 1}; +$output = qx{echo '-- y' | ../src/task rc:delete.rc undo; ../src/task rc:delete.rc info 1}; like ($output, qr/Status\s+Pending\n/, 'Pending'); ok (-r 'completed.data', 'completed.data created'); diff --git a/test/dependencies.t b/test/dependencies.t index 061180d3e..ae6876ba0 100755 --- a/test/dependencies.t +++ b/test/dependencies.t @@ -175,16 +175,16 @@ qx{../src/task rc:dep.rc add Four}; qx{../src/task rc:dep.rc 2 dep:1; ../src/task rc:dep.rc 3 dep:2; ../src/task rc:dep.rc 4 dep:3}; # [30,31] -$output = qx{echo y | ../src/task rc:dep.rc do 2}; +$output = qx{echo '-- y' | ../src/task rc:dep.rc do 2}; 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 do 1}; +$output = qx{echo '-- y' | ../src/task rc:dep.rc do 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 del 4}; +$output = qx{echo '-- y' | ../src/task rc:dep.rc del 4}; unlike ($output, qr/fixed/, 'dependencies - user not prompted to fix broken chain when the tail of the chain is deleted'); # [34] @@ -203,17 +203,17 @@ qx{../src/task rc:dep.rc 4 dep:3}; qx{../src/task rc:dep.rc 5 dep:4}; # [35] -qx{echo y | ../src/task rc:dep.rc do 2}; +qx{echo '-- y' | ../src/task rc:dep.rc do 2}; $output = qx{../src/task rc:dep.rc depreport}; 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{printf "Y\nY\n" | ../src/task rc:dep.rc del 2}; +qx{echo "-- Y\nY\n" | ../src/task rc:dep.rc del 2}; $output = qx{../src/task rc:dep.rc depreport}; 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 dep:-1}; +qx{../src/task rc:dep.rc 2 dep:-1}; $output = qx{../src/task rc:dep.rc depreport}; 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'); diff --git a/test/hook.format-prompt.t b/test/hook.format-prompt.t index 836f3ff34..ac1d5c75c 100755 --- a/test/hook.format-prompt.t +++ b/test/hook.format-prompt.t @@ -56,7 +56,7 @@ if (open my $fh, '>', 'hook') my $output = qx{../src/task rc:hook.rc version}; if ($output =~ /PUC-Rio/) { - my $output = qx{echo "\\nquit\\n" | ../src/task rc:hook.rc shell}; + my $output = qx{echo "-- \\nquit\\n" | ../src/task rc:hook.rc shell}; like ($output, qr//, 'format-prompt hook prompt -> '); } else diff --git a/test/hook.pre-completed.t b/test/hook.pre-completed.t index 47177914d..4cbeb5cf8 100755 --- a/test/hook.pre-completed.t +++ b/test/hook.pre-completed.t @@ -54,12 +54,12 @@ if ($output =~ /PUC-Rio/) my $good = $ENV{'PWD'} . '/hook:good'; my $bad = $ENV{'PWD'} . '/hook:bad'; - qx{echo 'y'|../src/task rc:hook.rc config -- hook.pre-completed "$bad"}; + qx{echo '-- y'|../src/task rc:hook.rc config -- hook.pre-completed "$bad"}; qx{../src/task rc:hook.rc add foo}; $output = qx{../src/task rc:hook.rc done 1}; like ($output, qr/disallowed/, 'pre-completed hook rejected completion'); - qx{echo 'y'|../src/task rc:hook.rc config -- hook.pre-completed "$good"}; + qx{echo '-- y'|../src/task rc:hook.rc config -- hook.pre-completed "$good"}; $output = qx{../src/task rc:hook.rc done 1}; like ($output, qr/Marked 1 task as done/, 'pre-completed hook allowed completion'); } diff --git a/test/rc.t b/test/rc.t index aeaea2ced..8ef751d53 100755 --- a/test/rc.t +++ b/test/rc.t @@ -34,7 +34,7 @@ use Test::More tests => 15; # Create the rc file, using rc.name:value. unlink 'foo.rc'; rmtree 'foo', 0, 0; -qx{echo 'y'|../src/task rc:foo.rc rc.data.location:foo}; +qx{echo '-- y'|../src/task rc:foo.rc rc.data.location:foo}; ok (-r 'foo.rc', 'Created default rc file'); ok (-d 'foo', 'Created default data directory'); @@ -46,40 +46,40 @@ unlink 'foo.rc'; ok (!-r 'foo.rc', 'Removed foo.rc'); # Do it all again, with rc.name=value. -qx{echo 'y'|../src/task rc:foo.rc rc.data.location:foo}; +qx{echo '-- y'|../src/task rc:foo.rc rc.data.location:foo}; ok (-r 'foo.rc', 'Created default rc file'); ok (-d 'foo', 'Created default data directory'); # Add a setting. -qx{echo 'y'|../src/task rc:foo.rc config must_be_unique old}; +qx{echo '-- y'|../src/task rc:foo.rc config must_be_unique old}; my $output = qx{../src/task rc:foo.rc show}; like ($output, qr/^must_be_unique\s+old/ms, 'config setting a new value'); -qx{echo 'y'|../src/task rc:foo.rc config must_be_unique new}; +qx{echo '-- y'|../src/task rc:foo.rc config must_be_unique new}; $output = qx{../src/task rc:foo.rc show}; like ($output, qr/^must_be_unique\s+new/ms, 'config overwriting an existing value'); -qx{echo 'y'|../src/task rc:foo.rc config must_be_unique ''}; +qx{echo '-- y'|../src/task rc:foo.rc config must_be_unique ''}; $output = qx{../src/task rc:foo.rc show}; like ($output, qr/^must_be_unique/ms, 'config setting a blank value'); -qx{echo 'y'|../src/task rc:foo.rc config must_be_unique}; +qx{echo '-- y'|../src/task rc:foo.rc config must_be_unique}; $output = qx{../src/task rc:foo.rc show}; unlike ($output, qr/^must_be_unique/ms, 'config removing a value'); # 'report.:b' is designed to get past the config command checks for recognized # names. -qx{echo 'y'|../src/task rc:foo.rc config -- report.:b +c}; +qx{echo '-- y'|../src/task rc:foo.rc config -- report.:b +c}; $output = qx{../src/task rc:foo.rc show}; like ($output, qr/^report\.:b\s+\+c/ms, 'the -- operator is working'); # Make sure the value is accepted if it has multiple words. -qx{echo 'y'|../src/task rc:foo.rc config must_be_unique 'one two three'}; +qx{echo '-- y'|../src/task rc:foo.rc config must_be_unique 'one two three'}; $output = qx{../src/task rc:foo.rc show}; like ($output, qr/^must_be_unique\s+one two three/ms, 'config allows multi-word quoted values'); -qx{echo 'y'|../src/task rc:foo.rc config must_be_unique one two three}; +qx{echo '-- y'|../src/task rc:foo.rc config must_be_unique one two three}; $output = qx{../src/task rc:foo.rc show}; like ($output, qr/^must_be_unique\s+one two three/ms, 'config allows multi-word unquoted values'); diff --git a/test/sequence.t b/test/sequence.t index 61e61b79a..e9ddd2f37 100755 --- a/test/sequence.t +++ b/test/sequence.t @@ -47,8 +47,8 @@ my $output = qx{../src/task rc:seq.rc info 1}; like ($output, qr/Status\s+Completed/, 'sequence do 1'); $output = qx{../src/task rc:seq.rc info 2}; like ($output, qr/Status\s+Completed/, 'sequence do 2'); -qx{echo 'y'|../src/task rc:seq.rc undo}; -qx{echo 'y'|../src/task rc:seq.rc undo}; +qx{../src/task rc:seq.rc undo}; +qx{../src/task rc:seq.rc undo}; $output = qx{../src/task rc:seq.rc info 1}; like ($output, qr/Status\s+Pending/, 'sequence undo 1'); $output = qx{../src/task rc:seq.rc info 2}; @@ -60,8 +60,8 @@ $output = qx{../src/task rc:seq.rc info 1}; like ($output, qr/Status\s+Deleted/, 'sequence delete 1'); $output = qx{../src/task rc:seq.rc info 2}; like ($output, qr/Status\s+Deleted/, 'sequence delete 2'); -qx{echo 'y'|../src/task rc:seq.rc undo}; -qx{echo 'y'|../src/task rc:seq.rc undo}; +qx{../src/task rc:seq.rc undo}; +qx{../src/task rc:seq.rc undo}; $output = qx{../src/task rc:seq.rc info 1}; like ($output, qr/Status\s+Pending/, 'sequence undo 1'); $output = qx{../src/task rc:seq.rc info 2}; diff --git a/test/shell.t b/test/shell.t index 9bfdb09b4..38fa5b79d 100755 --- a/test/shell.t +++ b/test/shell.t @@ -41,11 +41,11 @@ if (open my $fh, '>', 'shell.rc') } # Test the prompt. -my $output = qx{echo "\\nquit\\n" | ../src/task rc:shell.rc shell}; +my $output = qx{echo "-- \\nquit\\n" | ../src/task rc:shell.rc shell}; like ($output, qr/testprompt>/, 'custom prompt is being used'); # Test a simple add, then info. -$output = qx{echo "add foo\ninfo 1\n" | ../src/task rc:shell.rc shell}; +$output = qx{echo "-- add foo\ninfo 1\n" | ../src/task rc:shell.rc shell}; like ($output, qr/Description\s+foo/, 'add/info working'); # Cleanup. diff --git a/test/undo.t b/test/undo.t index aebae9305..5fe181b17 100755 --- a/test/undo.t +++ b/test/undo.t @@ -34,7 +34,8 @@ use Test::More tests => 15; if (open my $fh, '>', 'undo.rc') { print $fh "data.location=.\n", - "echo.command=no\n"; + "echo.command=no\n", + "confirmation=no\n"; close $fh; ok (-r 'undo.rc', 'Created undo.rc'); } @@ -48,7 +49,7 @@ $output = qx{../src/task rc:undo.rc do 1; ../src/task rc:undo.rc info 1}; ok (-r 'completed.data', 'completed.data created'); like ($output, qr/Status\s+Completed\n/, 'Completed'); -$output = qx{echo 'y'|../src/task rc:undo.rc undo; ../src/task rc:undo.rc info 1}; +$output = qx{../src/task rc:undo.rc undo; ../src/task rc:undo.rc info 1}; ok (-r 'completed.data', 'completed.data created'); like ($output, qr/Status\s+Pending\n/, 'Pending');