-
Notifications
You must be signed in to change notification settings - Fork 7
/
tc
executable file
·173 lines (148 loc) · 4.82 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env ruby
require 'rubygems'
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
require "bundler/setup"
require 'rdf/rdfxml'
require 'rdf/turtle'
require 'rdf/isomorphic'
require File.expand_path(File.join(File.dirname(__FILE__), "..", 'spec', 'spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), "..", 'spec', 'suite_helper'))
require 'getoptlong'
ASSERTOR = "http://greggkellogg.net/foaf#me"
RUN_TIME = Time.now
def earl_preamble(options)
options[:output].puts %(@prefix earl: <http://www.w3.org/ns/earl#> .)
RDF::RDFXML::Reader.open(File.expand_path("../../etc/doap.rdf", __FILE__)) do |reader|
g = RDF::Graph.new << reader
options[:output].write g.dump(:ttl, prefixes: reader.prefixes)
end
options[:output].puts %(
<> foaf:primaryTopic <https://rubygems.org/gems/rdf-rdfxml> ;
dct:issued "#{RUN_TIME.xmlschema}"^^xsd:dateTime ;
foaf:maker <#{ASSERTOR}> .
<#{ASSERTOR}> a foaf:Person, earl:Assertor;
foaf:name "Gregg Kellogg";
foaf:title "Implementor";
foaf:homepage <http://greggkellogg.net/> .
)
end
def run_tc(tc, **options)
STDERR.write "run #{tc.name} "
if options[:verbose]
puts "\nTestCase: #{tc.inspect}"
puts "\nInput:\n" + tc.input
puts "\nExpected:\n" + tc.expected
end
begin
puts "open #{tc.action}" if options[:verbose]
options = {
base_uri: tc.base,
validate: tc.syntax?,
logger: tc.logger
}.merge(options)
reader = RDF::Reader.for(tc.action).new(tc.input, **options)
graph = RDF::Repository.new
result = nil
if tc.positive_test?
begin
graph << reader
rescue Exception => e
STDERR.puts "Unexpected exception: #{e.inspect}" if options[:verbose]
result = "failed"
end
else
begin
graph << reader
STDERR.puts "Expected exception" if options[:verbose]
result = "failed"
rescue RDF::ReaderError
result = "passed"
end
end
if tc.evaluate? && result.nil?
output_graph = RDF::Repository.load(tc.result, format: :ntriples, base_uri: tc.base)
result = graph.isomorphic_with?(output_graph) ? "passed" : "failed"
else
result ||= "passed"
end
rescue Interrupt
STDERR.puts "\nHalting"
exit(1)
rescue Exception => e
STDERR.puts "#{"exception:" unless options[:quiet]}: #{e}"
if options[:quiet]
return
else
raise
end
end
options[:output].puts("\nOutput:\n" + graph.dump(:ntriples, validate: false)) if options[:verbose]
if options[:earl]
options[:output].puts %{
[ a earl:Assertion;
earl:assertedBy <#{ASSERTOR}>;
earl:subject <https://rubygems.org/gems/rdf-rdfxml>;
earl:test <#{tc.id}>;
earl:result [
a earl:TestResult;
earl:outcome earl:#{result};
dc:date "#{RUN_TIME.xmlschema}"^^xsd:dateTime];
earl:mode earl:automatic ] .
}
end
options[:result_count][result] ||= 0
options[:result_count][result] += 1
puts "#{"test result:" unless options[:quiet]} #{result}"
end
logger = Logger.new(STDERR)
logger.level = Logger::WARN
logger.formatter = lambda {|severity, datetime, progname, msg| "#{severity}: #{msg}\n"}
options = {
output: STDOUT,
logger: logger
}
opts = GetoptLong.new(
["--help", "-?", GetoptLong::NO_ARGUMENT],
["--dbg", GetoptLong::NO_ARGUMENT],
["--earl", GetoptLong::NO_ARGUMENT],
["--quiet", "-q", GetoptLong::NO_ARGUMENT],
["--output", "-o", GetoptLong::REQUIRED_ARGUMENT],
["--verbose", "-v", GetoptLong::NO_ARGUMENT]
)
def help(options)
puts "Usage: #{$0} [options] [test-number ...]"
puts "Options:"
puts " --debug: Display detailed debug output"
puts " --earl: Generate EARL report"
puts " --quiet: Minimal output"
puts " --output: Output to specified file"
puts " --verbose: Verbose processing"
puts " --help,-?: This message"
exit(0)
end
opts.each do |opt, arg|
case opt
when '--help' then help(options)
when '--dbg' then logger.level = Logger::DEBUG
when '--earl' then options[:quiet] = options[:earl] = true
when '--output' then options[:output] = File.open(arg, "w")
when '--quiet' then options[:quiet] = true; logger.level = Logger::FATAL
when '--verbose' then options[:verbose] = true
end
end
manifests = [Fixtures::SuiteTest::BASE + "rdf11/rdf-xml/"].map {|m| "#{m}manifest.ttl"}
earl_preamble(options) if options[:earl]
result_count = {}
begin
manifests.each do |manifest|
Fixtures::SuiteTest::Manifest.open(manifest) do |m|
m.entries.each do |tc|
next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
run_tc(tc, result_count: result_count, **options)
end
end
end
end
result_count.each do |result, count|
puts "#{result}: #{count}"
end