Skip to content

Commit 0ce20fc

Browse files
committed
Release 0.2.0.
2 parents 3974363 + 0d43cce commit 0ce20fc

4 files changed

Lines changed: 65 additions & 39 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.1
1+
0.2.0

ld-patch.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
2525
gem.required_ruby_version = '>= 2.0.0'
2626
gem.requirements = []
2727
gem.add_runtime_dependency 'rdf', '~> 1.1', '>= 1.1.15'
28-
gem.add_runtime_dependency 'ebnf', '~> 0.3', '>= 0.3.9'
28+
gem.add_runtime_dependency 'ebnf', '~> 1.0'
2929
gem.add_runtime_dependency 'sparql', '~> 1.1', '>= 1.1.7'
3030
gem.add_runtime_dependency 'sxp', '~> 0.1'
3131
gem.add_runtime_dependency 'rdf-xsd', '~> 1.1'
@@ -34,7 +34,7 @@ Gem::Specification.new do |gem|
3434
gem.add_development_dependency 'linkeddata', '~> 1.1'
3535
gem.add_development_dependency 'rdf-spec', '~> 1.1'
3636
gem.add_development_dependency 'open-uri-cached', '~> 0.0', '>= 0.0.5'
37-
gem.add_development_dependency 'rspec', '~> 3.2.0'
37+
gem.add_development_dependency 'rspec', '~> 3.2'
3838
gem.add_development_dependency 'rspec-its', '~> 1.2'
3939
gem.add_development_dependency 'yard' , '~> 0.8'
4040
gem.add_development_dependency 'webmock', '~> 1.17'

script/tc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ def run_tc(t, options)
8484
}
8585
end
8686

87+
options[:result_count][result] ||= 0
88+
options[:result_count][result] += 1
89+
8790
STDERR.puts "#{"test result:" unless options[:quiet]} #{result}"
8891
end
8992

9093
options = {
91-
output: STDOUT,
92-
validate: true,
93-
verbose: false,
94+
output: STDOUT,
95+
validate: true,
96+
verbose: false,
9497
}
9598
suite = "rdfxml"
9699
opts = GetoptLong.new(
@@ -125,14 +128,19 @@ opts.each do |opt, arg|
125128
end
126129

127130
earl_preamble(options) if options[:earl]
131+
result_count = {}
128132

129133
%w(manifest.ttl manifest-syntax.ttl turtle/manifest-ldpatch.ttl).each do |variant|
130134
manifest = Fixtures::SuiteTest::BASE + variant
131135

132136
Fixtures::SuiteTest::Manifest.open(manifest) do |m|
133137
m.entries.each do |tc|
134138
next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)}
135-
run_tc(tc, options)
139+
run_tc(tc, options.merge(result_count: result_count))
136140
end
137141
end
138-
end
142+
end
143+
144+
result_count.each do |result, count|
145+
puts "#{result}: #{count}"
146+
end

spec/suite_helper.rb

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ module File
99
REMOTE_PATH = "https://raw.githubusercontent.com/pchampin/ld-patch-testsuite/master/"
1010
LOCAL_PATH = ::File.expand_path("../testsuite", __FILE__) + '/'
1111

12+
class << self
13+
alias_method :original_open_file, :open_file
14+
end
15+
1216
##
1317
# Override to use Patron for http and https, Kernel.open otherwise.
1418
#
@@ -19,42 +23,56 @@ module File
1923
# @return [IO] File stream
2024
# @yield [IO] File stream
2125
def self.open_file(filename_or_url, options = {}, &block)
22-
case filename_or_url.to_s
23-
when /^file:/
26+
case
27+
when filename_or_url.to_s =~ /^file:/
2428
path = filename_or_url[5..-1]
2529
Kernel.open(path.to_s, options, &block)
26-
when /^#{REMOTE_PATH}/
27-
begin
28-
#puts "attempt to open #{filename_or_url} locally"
29-
local_filename = filename_or_url.to_s.sub(REMOTE_PATH, LOCAL_PATH)
30-
if ::File.exist?(local_filename)
31-
response = ::File.open(local_filename)
32-
#puts "use #{filename_or_url} locally"
33-
case filename_or_url.to_s
34-
when /\.ttl$/
35-
def response.content_type; 'text/turtle'; end
36-
when /\.ldpatch$/
37-
def response.content_type; 'text/ldpatch'; end
38-
end
39-
40-
if block_given?
41-
begin
42-
yield response
43-
ensure
44-
response.close
45-
end
46-
else
47-
response
48-
end
30+
when (filename_or_url.to_s =~ %r{^#{REMOTE_PATH}} && Dir.exist?(LOCAL_PATH))
31+
localpath = RDF::URI(filename_or_url).dup
32+
localpath.query = nil
33+
localpath = localpath.to_s.sub(REMOTE_PATH, LOCAL_PATH)
34+
response = begin
35+
::File.open(localpath)
36+
rescue Errno::ENOENT => e
37+
raise IOError, e.message
38+
end
39+
document_options = {
40+
base_uri: RDF::URI(filename_or_url),
41+
charset: Encoding::UTF_8,
42+
code: 200,
43+
headers: {}
44+
}
45+
#puts "use #{filename_or_url} locally"
46+
document_options[:headers][:content_type] = case filename_or_url.to_s
47+
when /\.ttl$/ then 'text/turtle'
48+
when /\.ldpatch$/ then 'text/ldpatch'
49+
else 'unknown'
50+
end
51+
52+
document_options[:headers][:content_type] = response.content_type if response.respond_to?(:content_type)
53+
# For overriding content type from test data
54+
document_options[:headers][:content_type] = options[:contentType] if options[:contentType]
55+
56+
remote_document = RDF::Util::File::RemoteDocument.new(response.read, document_options)
57+
if block_given?
58+
yield remote_document
59+
else
60+
remote_document
61+
end
62+
else
63+
original_open_file(filename_or_url, options) do |rd|
64+
# Override content_type
65+
if options[:contentType]
66+
rd.headers[:content_type] = options[:contentType]
67+
rd.instance_variable_set(:@content_type, options[:contentType].split(';').first)
68+
end
69+
70+
if block_given?
71+
yield rd
4972
else
50-
Kernel.open(filename_or_url.to_s, options.fetch(:headers, {}), &block)
73+
rd
5174
end
52-
rescue Errno::ENOENT #, OpenURI::HTTPError
53-
# Not there, don't run tests
54-
StringIO.new("")
5575
end
56-
else
57-
Kernel.open(filename_or_url.to_s, options.fetch(:headers, {}), &block)
5876
end
5977
end
6078
end

0 commit comments

Comments
 (0)