From 3088e1ebe1f9624b1f303e2d8f5db1114d532944 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2009 02:06:13 -0500 Subject: [PATCH] Unit Tests - abbreviation, filter, benchmark - Added tests for attribute abbreviation. - Added tests for filter permutation testing. - Added benchmark for ongoing performance measurement. - Mentioned test suite in docs. Why not? --- ChangeLog | 2 + html/task.html | 2 + src/tests/abbreviation.t | 77 ++++++++++++++++ src/tests/benchmark.t | 96 +++++++++++++++++++ src/tests/filter.t | 193 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 370 insertions(+) create mode 100755 src/tests/abbreviation.t create mode 100755 src/tests/benchmark.t create mode 100755 src/tests/filter.t diff --git a/ChangeLog b/ChangeLog index 9ec97dcbb..4ab22d837 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ + Fixed bug with the task sort alogrithm, which led to an unstable sequence when there were only a handful of tasks. + Performance enhanced by eliminating unnecessary sorting. + + Task now has a large (and growing) test suite and bug regression tests + to help ensure higher quality releases. ------ old releases ------------------------------ diff --git a/html/task.html b/html/task.html index 81cae7bf0..a65a68a96 100644 --- a/html/task.html +++ b/html/task.html @@ -119,6 +119,8 @@
  • Fixed bug with the task sort alogrithm, which led to an unstable sequence when there were only a handful of tasks.
  • Performance enhanced by eliminating unnecessary sorting. +
  • Task now has a large (and growing) test suite and bug regression tests + to help ensure higher quality releases.

    diff --git a/src/tests/abbreviation.t b/src/tests/abbreviation.t new file mode 100755 index 000000000..4d9b27515 --- /dev/null +++ b/src/tests/abbreviation.t @@ -0,0 +1,77 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 15; + +# Create the rc file. +if (open my $fh, '>', 'abbrev.rc') +{ + print $fh "data.location=.\n"; + close $fh; + ok (-r 'abbrev.rc', 'Created abbrev.rc'); +} + +# Test the add command. +qx{../task rc:abbrev.rc add priority:H with}; +qx{../task rc:abbrev.rc add without}; + +my $output = qx{../task rc:abbrev.rc list priority:H}; +like ($output, qr/\bwith\b/, 'priority:H with'); +unlike ($output, qr/\bwithout\b/, 'priority:H without'); + +$output = qx{../task rc:abbrev.rc list priorit:H}; +like ($output, qr/\bwith\b/, 'priorit:H with'); +unlike ($output, qr/\bwithout\b/, 'priorit:H without'); + +$output = qx{../task rc:abbrev.rc list priori:H}; +like ($output, qr/\bwith\b/, 'priori:H with'); +unlike ($output, qr/\bwithout\b/, 'priori:H without'); + +$output = qx{../task rc:abbrev.rc list prior:H}; +like ($output, qr/\bwith\b/, 'prior:H with'); +unlike ($output, qr/\bwithout\b/, 'prior:H without'); + +$output = qx{../task rc:abbrev.rc list prio:H}; +like ($output, qr/\bwith\b/, 'prio:H with'); +unlike ($output, qr/\bwithout\b/, 'prio:H without'); + +$output = qx{../task rc:abbrev.rc list pri:H}; +like ($output, qr/\bwith\b/, 'pri:H with'); +unlike ($output, qr/\bwithout\b/, 'pri:H without'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'abbrev.rc'; +ok (!-r 'abbrev.rc', 'Removed abbrev.rc'); + +exit 0; + diff --git a/src/tests/benchmark.t b/src/tests/benchmark.t new file mode 100755 index 000000000..dd069deb4 --- /dev/null +++ b/src/tests/benchmark.t @@ -0,0 +1,96 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 4; + +# Create the rc file. +if (open my $fh, '>', 'bench.rc') +{ + print $fh "data.location=.\n", + "_forcecolor=1\n"; + close $fh; + ok (-r 'bench.rc', 'Created bench.rc'); +} + +# Do lots of things. Time it all. + +my @tags = qw(t_one t_two t_three t_four t_five t_six t_seven t_eight); +my @projects = qw(p_one p_two p_three p_foud p_five p_six p_seven p_eight); +my @priorities = qw(H M L); +my $description = 'This is a medium-sized description with no special characters'; + +# Start the clock. +my $start = time (); +diag ("start=$start"); + +# Make a mess. +for my $i (1 .. 1000) +{ + my $project = $projects[rand % 8]; + my $priority = $priorities[rand % 3]; + my $tag = $tags[rand % 8]; + + qx{../task rc:bench.rc add project:$project priority:$priority +$tag $i $description}; +} +diag ("1000 tasks added"); + +qx{../task rc:bench.rc /with/WITH/} for 1 .. 200; +qx{../task rc:bench.rc done $_} for 201 .. 400; +qx{../task rc:bench.rc start $_} for 401 .. 600; +diag ("600 tasks altered"); + +# Report it all. +qx{../task rc:bench.rc ls}; +qx{../task rc:bench.rc list}; +qx{../task rc:bench.rc list priority:H}; +qx{../task rc:bench.rc list +tag}; +qx{../task rc:bench.rc list project_A}; +qx{../task rc:bench.rc long}; +qx{../task rc:bench.rc completed}; +qx{../task rc:bench.rc history}; +qx{../task rc:bench.rc ghistory}; + +# Stop the clock. +my $stop = time (); +diag ("stop=$stop"); +diag ("total=" . ($stop - $start)); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'completed.data'; +ok (!-r 'completed.data', 'Removed completed.data'); + +unlink 'bench.rc'; +ok (!-r 'bench.rc', 'Removed bench.rc'); + +exit 0; + diff --git a/src/tests/filter.t b/src/tests/filter.t new file mode 100755 index 000000000..5fd4e918b --- /dev/null +++ b/src/tests/filter.t @@ -0,0 +1,193 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 108; + +# Create the rc file. +if (open my $fh, '>', 'filter.rc') +{ + print $fh "data.location=.\n"; + close $fh; + ok (-r 'filter.rc', 'Created filter.rc'); +} + +# Test the filters. +qx{../task rc:filter.rc add project:A priority:H +tag one foo}; +qx{../task rc:filter.rc add project:A priority:H two}; +qx{../task rc:filter.rc add project:A three}; +qx{../task rc:filter.rc add priority:H four}; +qx{../task rc:filter.rc add +tag five}; +qx{../task rc:filter.rc add six foo}; +qx{../task rc:filter.rc add priority:L seven bar foo}; + +my $output = qx{../task rc:filter.rc list}; +like ($output, qr/one/, 'a1'); +like ($output, qr/two/, 'a2'); +like ($output, qr/three/, 'a3'); +like ($output, qr/four/, 'a4'); +like ($output, qr/five/, 'a5'); +like ($output, qr/six/, 'a6'); +like ($output, qr/seven/, 'a7'); + +$output = qx{../task rc:filter.rc list project:A}; +like ($output, qr/one/, 'b1'); +like ($output, qr/two/, 'b2'); +like ($output, qr/three/, 'b3'); +unlike ($output, qr/four/, 'b4'); +unlike ($output, qr/five/, 'b5'); +unlike ($output, qr/six/, 'b6'); +unlike ($output, qr/seven/, 'b7'); + +$output = qx{../task rc:filter.rc list priority:H}; +like ($output, qr/one/, 'c1'); +like ($output, qr/two/, 'c2'); +unlike ($output, qr/three/, 'c3'); +like ($output, qr/four/, 'c4'); +unlike ($output, qr/five/, 'c5'); +unlike ($output, qr/six/, 'c6'); +unlike ($output, qr/seven/, 'c7'); + +$output = qx{../task rc:filter.rc list priority:}; +unlike ($output, qr/one/, 'd1'); +unlike ($output, qr/two/, 'd2'); +like ($output, qr/three/, 'd3'); +unlike ($output, qr/four/, 'd4'); +like ($output, qr/five/, 'd5'); +like ($output, qr/six/, 'd6'); +unlike ($output, qr/seven/, 'd7'); + +$output = qx{../task rc:filter.rc list foo}; +like ($output, qr/one/, 'e1'); +unlike ($output, qr/two/, 'e2'); +unlike ($output, qr/three/, 'e3'); +unlike ($output, qr/four/, 'e4'); +unlike ($output, qr/five/, 'e5'); +like ($output, qr/six/, 'e6'); +like ($output, qr/seven/, 'e7'); + +$output = qx{../task rc:filter.rc list foo bar}; +unlike ($output, qr/one/, 'f1'); +unlike ($output, qr/two/, 'f2'); +unlike ($output, qr/three/, 'f3'); +unlike ($output, qr/four/, 'f4'); +unlike ($output, qr/five/, 'f5'); +unlike ($output, qr/six/, 'f6'); +like ($output, qr/seven/, 'f7'); + +$output = qx{../task rc:filter.rc list +tag}; +like ($output, qr/one/, 'g1'); +unlike ($output, qr/two/, 'g2'); +unlike ($output, qr/three/, 'g3'); +unlike ($output, qr/four/, 'g4'); +like ($output, qr/five/, 'g5'); +unlike ($output, qr/six/, 'g6'); +unlike ($output, qr/seven/, 'g7'); + +$output = qx{../task rc:filter.rc list project:A priority:H}; +like ($output, qr/one/, 'h1'); +like ($output, qr/two/, 'h2'); +unlike ($output, qr/three/, 'h3'); +unlike ($output, qr/four/, 'h4'); +unlike ($output, qr/five/, 'h5'); +unlike ($output, qr/six/, 'h6'); +unlike ($output, qr/seven/, 'h7'); + +$output = qx{../task rc:filter.rc list project:A priority:}; +unlike ($output, qr/one/, 'i1'); +unlike ($output, qr/two/, 'i2'); +like ($output, qr/three/, 'i3'); +unlike ($output, qr/four/, 'i4'); +unlike ($output, qr/five/, 'i5'); +unlike ($output, qr/six/, 'i6'); +unlike ($output, qr/seven/, 'i7'); + +$output = qx{../task rc:filter.rc list project:A foo}; +like ($output, qr/one/, 'j1'); +unlike ($output, qr/two/, 'j2'); +unlike ($output, qr/three/, 'j3'); +unlike ($output, qr/four/, 'j4'); +unlike ($output, qr/five/, 'j5'); +unlike ($output, qr/six/, 'j6'); +unlike ($output, qr/seven/, 'j7'); + +$output = qx{../task rc:filter.rc list project:A +tag}; +like ($output, qr/one/, 'k1'); +unlike ($output, qr/two/, 'k2'); +unlike ($output, qr/three/, 'k3'); +unlike ($output, qr/four/, 'k4'); +unlike ($output, qr/five/, 'k5'); +unlike ($output, qr/six/, 'k6'); +unlike ($output, qr/seven/, 'k7'); + +$output = qx{../task rc:filter.rc list project:A priority:H foo}; +like ($output, qr/one/, 'l1'); +unlike ($output, qr/two/, 'l2'); +unlike ($output, qr/three/, 'l3'); +unlike ($output, qr/four/, 'l4'); +unlike ($output, qr/five/, 'l5'); +unlike ($output, qr/six/, 'l6'); +unlike ($output, qr/seven/, 'l7'); + +$output = qx{../task rc:filter.rc list project:A priority:H +tag}; +like ($output, qr/one/, 'm1'); +unlike ($output, qr/two/, 'm2'); +unlike ($output, qr/three/, 'm3'); +unlike ($output, qr/four/, 'm4'); +unlike ($output, qr/five/, 'm5'); +unlike ($output, qr/six/, 'm6'); +unlike ($output, qr/seven/, 'm7'); + +$output = qx{../task rc:filter.rc list project:A priority:H foo +tag}; +like ($output, qr/one/, 'n1'); +unlike ($output, qr/two/, 'n2'); +unlike ($output, qr/three/, 'n3'); +unlike ($output, qr/four/, 'n4'); +unlike ($output, qr/five/, 'n5'); +unlike ($output, qr/six/, 'n6'); +unlike ($output, qr/seven/, 'n7'); + +$output = qx{../task rc:filter.rc list project:A priority:H foo +tag baz}; +unlike ($output, qr/one/, 'n1'); +unlike ($output, qr/two/, 'n2'); +unlike ($output, qr/three/, 'n3'); +unlike ($output, qr/four/, 'n4'); +unlike ($output, qr/five/, 'n5'); +unlike ($output, qr/six/, 'n6'); +unlike ($output, qr/seven/, 'n7'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'filter.rc'; +ok (!-r 'filter.rc', 'Removed filter.rc'); + +exit 0; +