Skip to content

Commit e3b794a

Browse files
committed
Updates for test suite locations.
1 parent b005c59 commit e3b794a

4 files changed

Lines changed: 48 additions & 56 deletions

File tree

script/tc

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def earl_preamble(**options)
4444
end
4545

4646
def run_tc(tc, **options)
47-
STDERR.write "run #{tc.name}"
47+
STDERR.write "run #{tc.name} "
4848

4949
if options[:verbose]
5050
puts "\nTestCase: #{tc.inspect}"
5151
puts "\nInput:\n" + tc.input
52-
puts "\nExpected:\n" + tc.expected
52+
puts "\nExpected:\n" + tc.expected if tc.expected
5353
end
5454

5555
logger = options[:live] ? Logger.new(STDERR) : RDF::Spec.logger
@@ -61,6 +61,7 @@ def run_tc(tc, **options)
6161
options = {
6262
base_uri: tc.base,
6363
validate: true,
64+
rdfstar: true,
6465
logger: logger
6566
}.merge(options)
6667

@@ -86,11 +87,14 @@ def run_tc(tc, **options)
8687
end
8788
end
8889

89-
STDERR.puts "Result: #{graph.dump(:ntriples)}" if options[:verbose]
90+
STDERR.puts "Result:\n#{graph.dump(:ntriples)}" if options[:verbose]
9091

9192
if tc.evaluate? && result.nil?
9293
output_graph = RDF::Repository.load(tc.result, format: :ntriples, base_uri: tc.base, rdfstar: true)
9394
result = graph.isomorphic_with?(output_graph) ? "passed" : "failed"
95+
elsif tc.c14n? && result.nil?
96+
c14n = RDF::NTriples::Writer.buffer {|w| w << graph}
97+
result = c14n == tc.expected ? "passed" : "failed"
9498
else
9599
result ||= "passed"
96100
end
@@ -142,7 +146,6 @@ OPT_ARGS = [
142146
["--ntriples", GetoptLong::NO_ARGUMENT, "Run N-Triples tests"],
143147
["--output", "-o", GetoptLong::REQUIRED_ARGUMENT, "Output to specified file"],
144148
["--quiet", "-q", GetoptLong::NO_ARGUMENT, "Minimal output"],
145-
["--rdfstar", GetoptLong::NO_ARGUMENT, "Run RDF-star tests"],
146149
["--skip-slow", "-s", GetoptLong::NO_ARGUMENT, "Avoid files taking too much time"],
147150
["--validate", GetoptLong::NO_ARGUMENT, "Validate input"],
148151
["--verbose", "-v", GetoptLong::NO_ARGUMENT, "Verbose output"],
@@ -185,22 +188,25 @@ opts.each do |opt, arg|
185188
when '--quiet'
186189
options[:quiet] = true
187190
options[:level] = Logger::FATAL
188-
when '--rdfstar' then options[:rdfstar] = true
189191
when '--skip-slow' then options[:slow] = true
190192
when '--validate' then options[:validate] = true
191193
when '--verbose' then options[:verbose] = true
192194
# when '--write-manifests' then options[:write_manifests] = true
193195
end
194196
end
195197

196-
manifests = if options[:rdfstar]
197-
%w{nt/syntax turtle/syntax turtle/eval}.map do
198-
|man| "https://w3c.github.io/rdf-star/tests/#{man}/"
199-
end
200-
elsif options[:ntriples]
201-
[Fixtures::SuiteTest::BASE + "rdf11/rdf-n-triples/"]
198+
manifests = if options[:ntriples]
199+
[
200+
Fixtures::SuiteTest::BASE + "rdf11/rdf-n-triples/",
201+
Fixtures::SuiteTest::BASE + "rdf12/rdf-n-triples/syntax/",
202+
Fixtures::SuiteTest::BASE + "rdf12/rdf-n-triples/c14n/",
203+
]
202204
else
203-
[Fixtures::SuiteTest::BASE + "rdf11/rdf-turtle/"]
205+
[
206+
Fixtures::SuiteTest::BASE + "rdf11/rdf-turtle/",
207+
Fixtures::SuiteTest::BASE + "rdf12/rdf-turtle/syntax/",
208+
Fixtures::SuiteTest::BASE + "rdf12/rdf-turtle/eval/",
209+
]
204210
end.map {|m| "#{m}manifest.ttl"}
205211

206212
earl_preamble(**options) if options[:earl]

spec/ntriples_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
describe "w3c N-Triples tests" do
77
require 'suite_helper'
88

9-
%w(rdf11/rdf-n-triples/manifest.ttl).each do |man|
9+
%w(rdf11/rdf-n-triples/manifest.ttl rdf12/rdf-n-triples/c14n/manifest.ttl).each do |man|
1010
Fixtures::SuiteTest::Manifest.open(Fixtures::SuiteTest::BASE + man) do |m|
1111
describe m.comment do
1212
m.entries.each do |t|
@@ -37,6 +37,9 @@
3737
if t.evaluate?
3838
output_graph = RDF::Graph.load(t.result, format: :ntriples, base_uri: t.base)
3939
expect(graph).to be_equivalent_graph(output_graph, t)
40+
elsif t.c14n?
41+
c14n = RDF::NTriples::Writer.buffer {|w| w << graph}
42+
expect(c14n).to eql t.expected
4043
else
4144
expect(graph).to be_a(RDF::Enumerable)
4245
end

spec/star_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
require 'spec_helper'
33

44
describe RDF::Turtle::Reader do
5-
# W3C Turtle Test suite from http://w3c.github.io/rdf-tests/turtle/manifest.ttl
5+
# W3C Turtle Test suite from http://w3c.github.io/rdf-tests/rdf/rdf12/
66
describe "w3c turtle tests" do
77
require 'suite_helper'
88

9-
%w(nt/syntax turtle/syntax turtle/eval).each do |man|
10-
Fixtures::SuiteTest::Manifest.open("https://w3c.github.io/rdf-star/tests/#{man}/manifest.ttl") do |m|
9+
%w(
10+
rdf12/rdf-n-triples/syntax/manifest.ttl
11+
rdf12/rdf-turtle/syntax/manifest.ttl
12+
rdf12/rdf-turtle/eval/manifest.ttl).each do |man|
13+
Fixtures::SuiteTest::Manifest.open(Fixtures::SuiteTest::BASE + man) do |m|
1114
describe [m.label, m.comment].compact.join(': ') do
1215
m.entries.each do |t|
1316
specify "#{t.name}: #{t.comment}" do

spec/suite_helper.rb

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ module RDF::Util
88
module File
99
REMOTE_PATH = "https://w3c.github.io/rdf-tests/rdf/"
1010
LOCAL_PATH = ::File.expand_path("../w3c-rdf-tests/rdf/", __FILE__) + '/'
11-
REMOTE_PATH_STAR = "https://w3c.github.io/rdf-star/"
12-
LOCAL_PATH_STAR = ::File.expand_path("../w3c-rdf-star/", __FILE__) + '/'
1311

1412
class << self
1513
alias_method :original_open_file, :open_file
@@ -55,38 +53,6 @@ def self.open_file(filename_or_url, **options, &block)
5553
# For overriding content type from test data
5654
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
5755

58-
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
59-
if block_given?
60-
yield remote_document
61-
else
62-
remote_document
63-
end
64-
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH_STAR}} && Dir.exist?(LOCAL_PATH_STAR))
65-
#puts "attempt to open #{filename_or_url} locally"
66-
localpath = filename_or_url.to_s.sub(REMOTE_PATH_STAR, LOCAL_PATH_STAR)
67-
response = begin
68-
::File.open(localpath)
69-
rescue Errno::ENOENT => e
70-
raise IOError, e.message
71-
end
72-
document_options = {
73-
base_uri: RDF::URI(filename_or_url),
74-
charset: Encoding::UTF_8,
75-
code: 200,
76-
headers: {}
77-
}
78-
#puts "use #{filename_or_url} locally"
79-
document_options[:headers][:content_type] = case filename_or_url.to_s
80-
when /\.ttl$/ then 'text/turtle'
81-
when /\.nt$/ then 'application/n-triples'
82-
when /\.jsonld$/ then 'application/ld+json'
83-
else 'unknown'
84-
end
85-
86-
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
87-
# For overriding content type from test data
88-
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
89-
9056
remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options)
9157
if block_given?
9258
yield remote_document
@@ -96,6 +62,8 @@ def self.open_file(filename_or_url, **options, &block)
9662
else
9763
original_open_file(filename_or_url, **options, &block)
9864
end
65+
rescue IOError => e
66+
raise IOError, "Error opening #{filename_or_url.inspect}: #{e.message}"
9967
end
10068
end
10169
end
@@ -112,6 +80,7 @@ module SuiteTest
11280
"rdft": "http://www.w3.org/ns/rdftest#",
11381
11482
"label": "rdfs:label",
83+
"baseIri": {"@id": "mf:assumedTestBase", "@type": "@id"},
11584
"comment": "rdfs:comment",
11685
"entries": {"@id": "mf:entries", "@container": "@list"},
11786
"name": "mf:name",
@@ -125,6 +94,8 @@ module SuiteTest
12594
"rdft:TestTurtleNegativeSyntax",
12695
"rdft:TestNTriplesPositiveSyntax",
12796
"rdft:TestNTriplesNegativeSyntax",
97+
"rdft:TestNTriplesPositiveC14N",
98+
"rdft:TestNTriplesNegativeC14N",
12899
"rdft:TestTurtleEval",
129100
"rdft:TestTurtleNegativeEval"
130101
]
@@ -150,15 +121,20 @@ def self.from_jsonld(json)
150121

151122
def entries
152123
# Map entries to resources
153-
attributes['entries'].map {|e| Entry.new(e)}
124+
attributes['entries'].map {|e| Entry.new(e, base_iri: attributes['baseIri'])}
154125
end
155126
end
156127

157128
class Entry < JSON::LD::Resource
158129
attr_accessor :logger
159130

131+
def initialize(json, base_iri:)
132+
@base_iri = base_iri
133+
super
134+
end
135+
160136
def base
161-
RDF::URI(action)
137+
RDF::URI(@base_iri || action)
162138
end
163139

164140
# Alias data and query
@@ -167,23 +143,23 @@ def input
167143
end
168144

169145
def expected
170-
@expected ||= RDF::Util::File.open_file(result) {|f| f.read}
146+
@expected ||= RDF::Util::File.open_file(result) {|f| f.read} if result
171147
end
172148

173149
def evaluate?
174150
Array(attributes['@type']).join(" ").match(/Eval/)
175151
end
176152

177153
def syntax?
178-
Array(attributes['@type']).join(" ").match(/Syntax/)
154+
!!Array(attributes['@type']).join(" ").match(/Syntax/)
179155
end
180156

181157
def entailment?
182-
Array(attributes['@type']).join(" ").match(/Entailment/)
158+
!!Array(attributes['@type']).join(" ").match(/Entailment/)
183159
end
184160

185161
def ntriples?
186-
Array(attributes['@type']).join(" ").match(/NTriples/)
162+
!!Array(attributes['@type']).join(" ").match(/NTriples/)
187163
end
188164

189165
def positive_test?
@@ -194,6 +170,10 @@ def negative_test?
194170
!positive_test?
195171
end
196172

173+
def c14n?
174+
!!Array(attributes['@type']).join(" ").match(/C14N/)
175+
end
176+
197177
def inspect
198178
super.sub('>', "\n" +
199179
" syntax?: #{syntax?.inspect}\n" +

0 commit comments

Comments
 (0)