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
test:
./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);
if (HAS_ID(pt)) {
for(i = 1; i <= pt->number_of_slots; i++, pi++) {
if ((int)*pr == i) {
if (*(int *)pr == i) {
*pi = pr;
pr += pt->record_size;
}

View File

@@ -3,14 +3,23 @@ module Pit
def should_not_segfault
`#{@pit} p -c test`
`#{@pit} t -c test`
10.times do |i|
`#{@pit} n -c note#{i+1}`
(1..12).each do |i|
`#{@pit} n -c note#{i}`
end
5.times do |i|
`#{@pit} n -d #{i+1}`
(1..6).each do |i|
`#{@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
`#{@pit} n -c note11`
`#{@pit} l`.should.match /created note 11/m
end
end
end

View File

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

View File

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

View File

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