From 1f2ddba84726d4144e141edd88576b539a63e0d9 Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Wed, 4 Aug 2010 22:53:44 -0700 Subject: [PATCH] First incarnation of Ruby-based pit test suite --- Makefile | 4 ++ src/args.c | 2 +- src/db.c | 3 +- test/{should.rb => pit_should.rb} | 21 ++++---- test/pit_test.rb | 80 ++++++++++++++++++++++++++++++ test/test.pitfile | Bin 0 -> 5300 bytes 6 files changed, 98 insertions(+), 12 deletions(-) rename test/{should.rb => pit_should.rb} (72%) create mode 100755 test/pit_test.rb create mode 100644 test/test.pitfile diff --git a/Makefile b/Makefile index c012f47..b1d8282 100644 --- a/Makefile +++ b/Makefile @@ -79,3 +79,7 @@ clean: rmdir $(OBJDIR) rmdir $(BINDIR) +.PHONY : test +test: + ./test/pit_test.rb + rm -f ./test/.pitfile diff --git a/src/args.c b/src/args.c index b8e6b68..962ae24 100644 --- a/src/args.c +++ b/src/args.c @@ -111,7 +111,7 @@ time_t pit_arg_date(char **arg, char *required) strcpy(format, "%m/%d/%Y %H:%M"); /* 10/10/1992 19:30 */ } } else { - if (strlen(*arg) > 12) { + if (strlen(*arg) >= 12) { if (alpha_date) { strcpy(format, "%b %d, %Y %H"); /* Oct 10, 1992 19 */ } else { diff --git a/src/db.c b/src/db.c index 8dd2587..5425b29 100644 --- a/src/db.c +++ b/src/db.c @@ -12,7 +12,8 @@ static char *pit_file_name() static char file_name[128]; if (!*file_name) { - strcpy(file_name, expand_path(PITFILE, file_name)); + char *penv = getenv("PITFILE"); + strcpy(file_name, expand_path(penv ? penv : PITFILE, file_name)); } return file_name; diff --git a/test/should.rb b/test/pit_should.rb similarity index 72% rename from test/should.rb rename to test/pit_should.rb index 0cf0334..b7385df 100644 --- a/test/should.rb +++ b/test/pit_should.rb @@ -1,6 +1,6 @@ class Hand < RuntimeError def oops(msg) - puts "\n#{msg} in #{self.backtrace[-1].sub(':', ' line ')}" + puts "\n#{msg} in #{self.backtrace[1].sub(':', ' line ')}" end end @@ -42,17 +42,18 @@ class String end end -"123".should.equal "123" -"123".should.equal "321" +if $0 == __FILE__ + "123".should.equal "123" + "123".should.equal "321" -"123".should_not.equal "321" -"123".should_not.equal "123" + "123".should_not.equal "321" + "123".should_not.equal "123" -"abc".should.match /B/i -"abc".should.match /xyz/ - -"abc".should_not.match /xyz/ -"abc".should_not.match /abc/ + "abc".should.match /B/i + "abc".should.match /xyz/ + "abc".should_not.match /xyz/ + "abc".should_not.match /abc/ +end diff --git a/test/pit_test.rb b/test/pit_test.rb new file mode 100755 index 0000000..95933f7 --- /dev/null +++ b/test/pit_test.rb @@ -0,0 +1,80 @@ +#!/usr/bin/env ruby +# +BASE = File.dirname(File.expand_path(__FILE__)) +require "#{BASE}/pit_should" + +class PitTestRunner + def self.run + runner = self.new + runner.public_methods.grep(/^should_/).each do |method| + runner.send(:before) if runner.respond_to?(:before) + runner.send(method) + runner.send(:after) if runner.respond_to?(:after) + end + puts + end + + def initialize + @pit = "#{BASE.sub(/test$/, 'bin')}/pit" + if File.executable?(@pit) + ENV['PITFILE'] = "#{BASE}/test.pitfile" + puts "Testing #{@pit} with #{ENV['PITFILE']}" + else + raise("\nCould not run #{@pit}") + end + end + + def before + `#{@pit} init -f` + `#{@pit} project -c test` + end + + def should_parse_alpha_dates + `#{@pit} task -c test -d "dec 1, 2011 19:30"` + `#{@pit} task`.should.match /Dec 01, 2011 19:30/m + `#{@pit} task -c test -d "dec 1, 2012 1:15pm"` + `#{@pit} task`.should.match /Dec 01, 2012 13:15/m + `#{@pit} task -c test -d "dec 1, 2013 11"` + `#{@pit} task`.should.match /Dec 01, 2013 11:00/m + `#{@pit} task -c test -d "dec 1, 2013 7pm"` + `#{@pit} task`.should.match /Dec 01, 2013 19:00/m + `#{@pit} task -c test -d "dec 1, 2013"` + `#{@pit} task`.should.match /Dec 01, 2013 /m + `#{@pit} task -c test -d "dec 1 5:55"` + `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 05:55/m + `#{@pit} task -c test -d "dec 1 2:40pm"` + `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 14:40/m + # `#{@pit} task -c test -d "dec 1 5"` + # `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 05:00/m + # `#{@pit} task -c test -d "dec 1 3pm"` + # `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 15:00/m + `#{@pit} task -c test -d "dec 1"` + `#{@pit} task`.should.match /Dec 01, #{Time.now.year} /m + end + + def should_parse_slash_dates + `#{@pit} task -c test -d "12/1/2011 19:30"` + `#{@pit} task`.should.match /Dec 01, 2011 19:30/m + `#{@pit} task -c test -d "12/1/2012 1:15pm"` + `#{@pit} task`.should.match /Dec 01, 2012 13:15/m + `#{@pit} task -c test -d "12/1/2013 11"` + `#{@pit} task`.should.match /Dec 01, 2013 11:00/m + `#{@pit} task -c test -d "12/1/2013 7pm"` + `#{@pit} task`.should.match /Dec 01, 2013 19:00/m + `#{@pit} task -c test -d "12/1/2013"` + `#{@pit} task`.should.match /Dec 01, 2013 /m + `#{@pit} task -c test -d "12/1 5:55"` + `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 05:55/m + `#{@pit} task -c test -d "12/1 2:40pm"` + `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 14:40/m + # `#{@pit} task -c test -d "12/1 5"` + # `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 05:00/m + # `#{@pit} task -c test -d "12/1 3pm"` + # `#{@pit} task`.should.match /Dec 01, #{Time.now.year} 15:00/m + `#{@pit} task -c test -d "12/1"` + `#{@pit} task`.should.match /Dec 01, #{Time.now.year} /m + end + +end + +PitTestRunner.run diff --git a/test/test.pitfile b/test/test.pitfile new file mode 100644 index 0000000000000000000000000000000000000000..50e686d6bdb8dda113e37d06ba396a3b189fca70 GIT binary patch literal 5300 zcmd^>KTZNc6o*m#gPy`8SXx?{kQhRcif)5jOn`;36ALP+xPxB8!pe#hP*ZvUYPB@# ze3{2&2|JCE8Jgdlo%aTQ-wrdcS#KXyoX@ElzZpF@O5!#hs9tJP3q_~7E}ZzIhe=nf z2k{GQTfTSJ>fC-$q44-L`S76LRhQ3y=Q13nnM9Ed$AhGApIqIn8g^tO_@IYo3jh1= zyPdx_ty>%67p(^7`*Qx&vTkjJU-T$2-_IZAd>;qqd%Aus^}bI6^Zj!7{&UXT9sV1! zzfsQrP|mf*vYc=3wNQLdE9HFizORjO?t6EiFy`KK^Uq8IN~#|?=F7S$(opA__1Go`B4`WGwBt6^n1SisFQ2P6vL0c(U%`} zF)@=~;Ya`J%a1y_W=t{s=wp5PQ5O?4=@owTN51^1lWWEl!;ik&mmhU8F_T{5_XRj+ Bqg?<1 literal 0 HcmV?d00001