Wrote more tests, fixed another nasty bug

This commit is contained in:
Mike Dvorkin
2010-08-14 22:13:09 -07:00
parent f8ba6a911b
commit 1753a4810a
6 changed files with 43 additions and 29 deletions

View File

@@ -92,4 +92,4 @@ clean:
.PHONY : test .PHONY : test
test: test:
./test/pit_test.rb ./test/pit_test.rb
rm -f ./test/.pitfile rm -f ./test/test.pitfile

View File

@@ -298,7 +298,7 @@ PTable pit_table_load(FILE *file)
read += fread(pt->slots, pt->record_size, pt->number_of_records, file); read += fread(pt->slots, pt->record_size, pt->number_of_records, file);
if (HAS_ID(pt)) { if (HAS_ID(pt)) {
for(i = 1; i <= pt->number_of_slots; i++, pi++) { for(i = 1; i <= pt->number_of_slots; i++, pi++) {
if ((int)*pr == i) { if (*(int *)pr == i) {
*pi = pr; *pi = pr;
pr += pt->record_size; pr += pt->record_size;
} }

View File

@@ -3,14 +3,23 @@ module Pit
def should_not_segfault def should_not_segfault
`#{@pit} p -c test` `#{@pit} p -c test`
`#{@pit} t -c test` `#{@pit} t -c test`
10.times do |i| (1..12).each do |i|
`#{@pit} n -c note#{i+1}` `#{@pit} n -c note#{i}`
end end
5.times do |i| (1..6).each do |i|
`#{@pit} n -d #{i+1}` `#{@pit} n -d #{i}`
end
`#{@pit} n -c note13`
`#{@pit} l`.should.match /created note 13/m
end
def should_handle_all_notes
`#{@pit} p -c test`
`#{@pit} t -c test`
(1..128).each do |n|
`#{@pit} n -c note#{n}`
`#{@pit} n -e #{n} xxx`
end end
`#{@pit} n -c note11`
`#{@pit} l`.should.match /created note 11/m
end end
end end
end end

View File

@@ -6,25 +6,26 @@ module Pit
`#{@pit} project`.should.match /\* 1: \(.+\) \|active| test \(0 tasks\)/ `#{@pit} project`.should.match /\* 1: \(.+\) \|active| test \(0 tasks\)/
end end
def should_do_cascading_delete def should_do_cascading_project_delete
def should_do_cascading_delete 12.times do |p|
3.times do |p|
`#{@pit} project -c project#{p}` `#{@pit} project -c project#{p}`
3.times do |t| `#{@pit} project`.should.match /\* #{p+1}:/m
12.times do |t|
`#{@pit} task -c project#{p}_task#{t}` `#{@pit} task -c project#{p}_task#{t}`
3.times do |n| `#{@pit} task`.should.match /\* #{p*12 + t+1}:/m
12.times do |n|
`#{@pit} note -c project#{p}_task#{t}_note#{n}` `#{@pit} note -c project#{p}_task#{t}_note#{n}`
`#{@pit} note`.should.match /\* #{p*144 + t*12 + n+1}:/m
end end
end end
end end
`#{@pit} project`.should.match /\* 3:/m `#{@pit} project`.should.match /\* 12:/m
`#{@pit} project -d` `#{@pit} project -d`
`#{@pit} project`.should_not.match /[\s|\*] 3:/m `#{@pit} project`.should_not.match /[\s|\*] 12:/m
`#{@pit} project`.should.match /\s 2:/m `#{@pit} project`.should.match /\s 11:/m
`#{@pit} project -d 2` `#{@pit} project -d 2`
`#{@pit} project`.should_not.match /[\s|\*] 2:/m `#{@pit} project`.should_not.match /[\s|\*] 2:/m
`#{@pit} project`.should.match /\s 1:/m `#{@pit} project`.should.match /\s 1:/m
end end
end end
end
end end

View File

@@ -1,21 +1,24 @@
module Pit module Pit
module Task module Task
def should_do_cascading_delete def should_do_cascading_task_delete
`#{@pit} project -c project` `#{@pit} project -c project`
5.times do |t| 12.times do |t|
`#{@pit} task -c task#{t}` `#{@pit} task -c task#{t}`
5.times do |n| `#{@pit} task`.should.match /\* #{t+1}:/m
12.times do |n|
`#{@pit} note -c task#{t}_note#{n}` `#{@pit} note -c task#{t}_note#{n}`
`#{@pit} note`.should.match /\* #{t*12 + n+1}:/m
end end
end end
`#{@pit} task`.should.match /\* 5:/m `#{@pit} task`.should.match /\* 12:/m
`#{@pit} note -e 21 hello21` `#{@pit} note -e 21 hello21`
`#{@pit} note -d 21` `#{@pit} note -d 21`
`#{@pit} note -e 22 hello22` `#{@pit} note -e 22 hello22`
`#{@pit} note -d 22` `#{@pit} note -d 22`
`#{@pit} task -d` `#{@pit} task -d`
`#{@pit} task`.should_not.match /[\s|\*] 5:/m `#{@pit} task`.should_not.match /[\s|\*] 12:/m
end end
end end
end end

View File

@@ -10,6 +10,7 @@ require "#{BASE}/pit_note"
class PitTestRunner class PitTestRunner
def self.run def self.run
runner = self.new runner = self.new
STDOUT.sync = true
runner.public_methods.grep(/^should_/).each do |method| runner.public_methods.grep(/^should_/).each do |method|
runner.send(:before) if runner.respond_to?(:before) runner.send(:before) if runner.respond_to?(:before)
runner.send(method) runner.send(method)