This repository has been archived by the owner on Dec 29, 2017. It is now read-only.
/
tc
executable file
·106 lines (95 loc) · 2.94 KB
/
tc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby
require 'rubygems'
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
require 'sparql/spec'
require File.expand_path(File.join(File.dirname(__FILE__), "..", 'spec', 'spec_helper'))
require 'getoptlong'
def run_tc(t, options = {})
options[:msg] ||= {}
options[:tests] ||= 0
options[:tests] += 1
STDOUT.write "run #{t.name}" unless options[:quiet]
puts "\n" + t.action.sse_string if options[:verbose]
graphs = t.graphs
query = t.action.sse_string
expected = t.solutions
graphs.each {|k, s| puts "#{k}:\n#{s[:data]}\n"} if options[:verbose]
result = sparql_query(:graphs => graphs, :query => query, :base_uri => t.action.query_file,
:repository => "sparql-spec", :form => t.form, :to_hash => false)
puts "result: #{result.inspect}" if options[:verbose]
case t.form
when :select, :create, :describe
if result.isomorphic_with?(expected)
STDOUT.write(options[:quiet] ? "." : " ok\n")
else
options[:failures] ||= {}
options[:failures][t] = %{
expected:\n#{expected.inspect}
actual:\n#{result.inspect}
}
options[:failures][t] += "\nmissing:\n#{(expected - result).inspect}" unless (expected - result).empty?
options[:failures][t] += "\nextra:\n#{(expected - result).inspect}" unless (result - expected).empty?
STDOUT.write(options[:quiet] ? "F" : (" failed" + options[:failures][t]))
end
when :ask
if result
STDOUT.write(options[:quiet] ? "." : " ok\n")
else
options[:failures] ||= {}
options[:failures][t] = "\nFailed"
STDOUT.write(options[:quiet] ? "F" : " failed\n")
end
end
rescue Exception => e
if options[:quiet]
STDOUT.write("E")
options[:exceptions] ||= {}
options[:exceptions][t] = e.message
else
STDOUT.puts("\n#{e.message}")
STDOUT.puts e.backtrace
end
end
options = {
:verbose => false,
:quite => false,
:validate => false,
}
suite = "rdfxml"
opts = GetoptLong.new(
["--dbg", GetoptLong::NO_ARGUMENT],
["--verbose", GetoptLong::NO_ARGUMENT],
["--quiet", GetoptLong::NO_ARGUMENT],
)
opts.each do |opt, arg|
case opt
when '--validate' then options[:validate] = true
when '--verbose' then options[:verbose] = true
when '--quiet' then options[:quiet] = true
when '--dbg' then ENV['EXEC_DEBUG'] = "true"
end
end
test_cases = SPARQL::Spec.load_sparql1_0_tests
test_cases.each do |tc|
next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
run_tc(tc, options)
end
if options[:quiet]
puts ""
if options[:exceptions]
puts "\nExceptions:"
options[:exceptions].each do |t, m|
puts "#{t.name}: #{m}"
end
end
if options[:failures]
puts "\nFailures"
options[:failures].each do |t, m|
puts "#{t.name}:#{m}"
end
end
msg = "#{options[:tests]} Tests"
msg += ", #{options[:failures].length} Failures" if options[:failures]
msg += ", #{options[:exceptions].length} Exceptions" if options[:exceptions]
puts msg
end