Skip to content

Commit

Permalink
Test generator and comparison
Browse files Browse the repository at this point in the history
Add output regression check to "rake test"

rake gen - generate .decode for every .rd file
rake test - compare decode of .rd with .decode content
  • Loading branch information
kkaempf committed Dec 20, 2017
1 parent 6f4bd20 commit 8dd2f05
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
29 changes: 29 additions & 0 deletions tasks/gen.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$:.push(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'ruida'

#
# generate test results in ../rd
#
task :gen do
rd_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'rd'))
Dir.open(rd_dir).each do |path|
next unless path =~ /(.*)\.rd$/
name = $1
puts name
inp = File.open(File.join(rd_dir,path), 'r')
out = File.open(File.join(rd_dir,"#{name}.decode"), 'w+')
inp.binmode
out.binmode
rd = Ruida::Data.new inp.read
begin
parser = Ruida::Parser.new rd
parser.each do |c|
out.puts c
end
rescue Exception => e
STDERR.puts e
end
out.close
inp.close
end
end
17 changes: 16 additions & 1 deletion tasks/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ require 'ruida'
task :test do
rd_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'rd'))
Dir.open(rd_dir).each do |path|
next unless path =~ /.*\.rd$/
next unless path =~ /(.*)\.rd$/
name = $1
puts path
file = File.open(File.join(rd_dir,path), 'r')
file.binmode
decoded = []
File.foreach(File.join(rd_dir,"#{name}.decode")) do |line|
decoded << line.chomp
end
rd = Ruida::Data.new file.read
lnum = 0
begin
parser = Ruida::Parser.new rd
parser.each do |c|
expected = decoded[lnum]
lnum += 1
unless expected == c.to_s
STDERR.puts "Fail in #{path}##{lnum}:"
STDERR.puts "Expected: #{expected.inspect}"
STDERR.puts "Got: #{c.to_s.inspect}"
break
end
end
rescue Exception => e
STDERR.puts e
end
file.close
end
end

0 comments on commit 8dd2f05

Please sign in to comment.