From 1753a4810ab39cbf2c2c79914a95a3a340fd6dc0 Mon Sep 17 00:00:00 2001 From: Mike Dvorkin Date: Sat, 14 Aug 2010 22:13:09 -0700 Subject: [PATCH] Wrote more tests, fixed another nasty bug --- Makefile | 2 +- src/table.c | 2 +- test/pit_note.rb | 21 +++++++++++++++------ test/pit_project.rb | 33 +++++++++++++++++---------------- test/pit_task.rb | 13 ++++++++----- test/pit_test.rb | 1 + 6 files changed, 43 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 1be1a2b..e973dae 100644 --- a/Makefile +++ b/Makefile @@ -92,4 +92,4 @@ clean: .PHONY : test test: ./test/pit_test.rb - rm -f ./test/.pitfile + rm -f ./test/test.pitfile diff --git a/src/table.c b/src/table.c index ca23df3..55f54cc 100644 --- a/src/table.c +++ b/src/table.c @@ -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; } diff --git a/test/pit_note.rb b/test/pit_note.rb index dfd46cc..293507b 100644 --- a/test/pit_note.rb +++ b/test/pit_note.rb @@ -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 diff --git a/test/pit_project.rb b/test/pit_project.rb index 79b34cb..1b2244d 100644 --- a/test/pit_project.rb +++ b/test/pit_project.rb @@ -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 diff --git a/test/pit_task.rb b/test/pit_task.rb index 863c8d5..aa8ad7e 100644 --- a/test/pit_task.rb +++ b/test/pit_task.rb @@ -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 diff --git a/test/pit_test.rb b/test/pit_test.rb index 99a8bc8..c3eca2b 100755 --- a/test/pit_test.rb +++ b/test/pit_test.rb @@ -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)