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 0000000..50e686d Binary files /dev/null and b/test/test.pitfile differ