Permalink
Browse files

Shell-based test runner in spec/run-suite. Example runner in test/rdf…

…-rdfa.
  • Loading branch information...
1 parent 22d90c0 commit f99d19aafdb9baf249160d397ea773e0eb300295 @gkellogg gkellogg committed May 14, 2012
Showing with 196 additions and 29 deletions.
  1. +1 −2 Gemfile
  2. +21 −27 Gemfile.lock
  3. +12 −0 README.markdown
  4. +63 −0 bin/rdf-rdfa
  5. +99 −0 bin/run-suite
View
@@ -7,8 +7,7 @@ gem 'rake'
gem 'haml'
gem 'json'
gem 'sinatra'
-gem 'rdf-rdfxml', :git => "git://github.com/gkellogg/rdf-rdfxml.git", :require => 'rdf/rdfxml'
-gem 'rdf-rdfa', :git => "git://github.com/gkellogg/rdf-rdfa.git", :require => 'rdf/rdfa'
+gem 'rdf-rdfa', :git => "git://github.com/ruby-rdf/rdf-rdfa.git", :require => 'rdf/rdfa'
gem 'json-ld', :git => "git://github.com/gkellogg/json-ld.git", :require => 'json/ld'
gem 'sinatra-simple-assets', :require => 'sinatra/simple_assets'
gem 'sinatra-respond_to', :git => "git://github.com/gkellogg/sinatra-respond_to.git", :require => 'sinatra/respond_to'
View
@@ -1,31 +1,13 @@
GIT
remote: git://github.com/gkellogg/json-ld.git
- revision: 7f0098ffd63e5050dc8501cfadf8dc72fd62fd63
+ revision: 05aad91acbb6e1fa126192641c9cf4bbfa0225ba
specs:
json-ld (0.1.2)
backports
json (>= 1.6.5)
rdf (>= 0.3.5)
GIT
- remote: git://github.com/gkellogg/rdf-rdfa.git
- revision: ef991ad8399e722b47b1c2b3e59e3019f1469210
- specs:
- rdf-rdfa (0.3.10.1)
- haml (>= 3.0.0)
- htmlentities (>= 4.3.0)
- rdf (>= 0.3.3)
- rdf-xsd (>= 0.3.5)
-
-GIT
- remote: git://github.com/gkellogg/rdf-rdfxml.git
- revision: b0850defb277f3e8d35232d807883f5f80251bc7
- specs:
- rdf-rdfxml (0.3.6)
- rdf (>= 0.3.4)
- rdf-xsd (>= 0.3.5)
-
-GIT
remote: git://github.com/gkellogg/sinatra-browserid.git
revision: ef33f0d9efbdf2df0fc68fa66622057d1f4a05d8
specs:
@@ -40,6 +22,16 @@ GIT
sinatra-respond_to (0.8.0)
sinatra (~> 1.3)
+GIT
+ remote: git://github.com/ruby-rdf/rdf-rdfa.git
+ revision: 28e5441bb47add903c1a563da7a6391d299dd4da
+ specs:
+ rdf-rdfa (0.3.12)
+ haml (>= 3.0.0)
+ htmlentities (>= 4.3.0)
+ rdf (>= 0.3.3)
+ rdf-xsd (>= 0.3.5)
+
GEM
remote: http://rubygems.org/
specs:
@@ -84,21 +76,24 @@ GEM
rdf-json (0.3.0)
json_pure (>= 1.4.2)
rdf (~> 0.3.0)
- rdf-microdata (0.2.3.1)
+ rdf-microdata (0.2.4)
htmlentities (>= 4.3.0)
json (>= 1.6.1)
rdf (>= 0.3.4)
rdf-xsd (>= 0.3.4)
- rdf-n3 (0.3.6)
+ rdf-n3 (0.3.7)
rdf (>= 0.3.4)
- rdf-trig (0.1.2)
+ rdf-rdfxml (0.3.7)
+ rdf (>= 0.3.4)
+ rdf-xsd (>= 0.3.5)
+ rdf-trig (0.1.3)
rdf (>= 0.3.4)
rdf-turtle (>= 0.1.1)
rdf-trix (0.3.0)
rdf (~> 0.3.0)
- rdf-turtle (0.1.1)
+ rdf-turtle (0.1.2)
rdf (>= 0.3.4)
- rdf-xsd (0.3.5)
+ rdf-xsd (0.3.6)
nokogiri (>= 1.5.0)
rdf (>= 0.3.4)
shotgun (0.9)
@@ -111,12 +106,12 @@ GEM
cssmin (~> 1.0.2)
sinatra (~> 1.3.0)
uglifier (~> 1.2.0)
- sparql (0.1.1)
+ sparql (0.3.0)
builder (>= 3.0.0)
json (>= 1.5.1)
rdf (>= 0.3.5)
rdf-xsd (>= 0.3.5)
- sparql-client (>= 0.0.11)
+ sparql-client (>= 0.1.0)
sxp (>= 0.0.14)
sparql-client (0.1.0)
json_pure (>= 1.6.5)
@@ -143,7 +138,6 @@ DEPENDENCIES
rack-cache
rake
rdf-rdfa!
- rdf-rdfxml!
shotgun
sinatra
sinatra-browserid!
View
@@ -89,6 +89,18 @@ Running the website locally should be as simple as the following:
This will create an instance, usually running on port 9393. If you access as http://localhost:9393/test-suite/, it will re-write test URIs to http://rdfa.info/test-suite/ so that processors can see any tests that are already uploaded. If you want to run with a local endpoint, run with something else such as http://127.0.0.1/test-suite/, which will inhibit the URI rewriting.
+### Command line runner
+
+By implementing a command-line runner, the tests can be run using spec/run-suite. This allows a processor that does not implement an HTTP-based distiller to run through test cases using a shell commant.
+
+To use this, implement a shell command accepting input RDFa on standard input generating Turtle or N-Triples on standard output. It should also accept the --host-language, --version and --url options.
+
+For example, to run with the Ruby RDFa processor, invoke the following:
+
+ spec/run-suite spec/rdf-rdfa
+
+See spec/run-suite --help for more on the test runner.
+
## How to add a unit test
In order to add a unit test, you must follow these steps:
View
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+# RDFa runner for Ruby. Invokes an RDFa to Turtle parser and
+# returns results to standard out.
+#
+# See --help for more
+require 'rubygems'
+require 'rdf/rdfa'
+require 'rdf/turtle'
+require 'getoptlong'
+
+options = {
+ :base_uri => nil,
+ :format => :turtle,
+ :host_language => "xhtml1",
+ :output => STDOUT,
+ :rdfagraph => [:output],
+ :version => "rdfa1.1",
+}
+opts = GetoptLong.new(
+ ["--help", "-?", GetoptLong::NO_ARGUMENT],
+ ["--host-language", "-h", GetoptLong::OPTIONAL_ARGUMENT],
+ ["--format", GetoptLong::REQUIRED_ARGUMENT],
+ ["--output", "-o", GetoptLong::REQUIRED_ARGUMENT],
+ ["--rdfagraph", GetoptLong::REQUIRED_ARGUMENT],
+ ["--uri", GetoptLong::REQUIRED_ARGUMENT],
+ ["--version", "-v", GetoptLong::OPTIONAL_ARGUMENT]
+)
+
+def help(options)
+ puts %(The script takes the standard input and generates Turtle on standard output.
+
+Usage: #{$0} [options] [rdfa input]
+Options:
+ --format: Format for output, defaults to #{options[:format].inspect}
+ --host-language: Run for specified host language, defaults to #{options[:host_language]}"
+ --rdfagraph: output, processor or output,processor
+ --version: Version of processor to use (rdf1.0, rdf1.1). Defaults to #{options[:version]}
+ --uri: Base URI to use when parsing
+)
+ exit(0)
+end
+
+opts.each do |opt, arg|
+ case opt
+ when '--help' then help(options)
+ when '--format' then options[:format] = arg.to_sym
+ when '--host-language' then options[:host_language] = arg
+ when '--output' then options[:output] = File.open(arg, "w")
+ when '--rdfagraph' then options[:rdfagraph] = arg.split(',').map(&:to_sym)
+ when '--uri' then options[:base_uri] = arg
+ when '--version' then options[:version] = arg
+ end
+end
+
+processor_graph = RDF::Graph.new if options[:rdfagraph].include?(:processor)
+
+r = if ARGV.empty?
+ RDF::RDFa::Reader.new(STDIN, options)
+else
+ RDF::RDFa::Reader.open(ARGV.first, options)
+end
+g = RDF::Graph.new << r
+options[:output].puts g.dump(options[:format], options.merge(:prefixes => r.prefixes))
View
@@ -0,0 +1,99 @@
+#!/usr/bin/env ruby
+# Run the RDFa test suite against a specified runner.
+#
+# Expects the runner to take STDIN and generate Turtle/N-Triples to STDOUT
+# Passes the options --uri, --host-language, --version
+#
+# Runs each test associated with the RDFa version and Host Language.
+#
+# See --help for more
+require 'rubygems'
+require "bundler/setup"
+$:.unshift(File.expand_path("../../lib", __FILE__))
+
+require 'crazyivan/core'
+require 'getoptlong'
+
+options = {
+ :format => :turtle,
+ :host_language => "xhtml1",
+ :version => "rdfa1.1",
+}
+opts = GetoptLong.new(
+ ["--help", "-?", GetoptLong::NO_ARGUMENT],
+ ["--format", GetoptLong::REQUIRED_ARGUMENT],
+ ["--host-language", "-h", GetoptLong::OPTIONAL_ARGUMENT],
+ ["--verbose", GetoptLong::NO_ARGUMENT],
+ ["--version", GetoptLong::REQUIRED_ARGUMENT],
+ ["--num", GetoptLong::REQUIRED_ARGUMENT]
+)
+
+def help(options)
+ puts %(Invokes runner for each test case and indicates test pass/fail.
+
+Usage: #{$0} runner [options]
+Options:
+ --format: Format for output, defaults to #{options[:format].inspect}
+ --host-language: Run for specified host language, defaults to #{options[:host_language]}"
+ --num: Run only specified test number
+ --verbose: Show input and expected output
+ --version: Version of processor to use (rdf1.0, rdf1.1). Defaults to #{options[:version]}
+)
+ exit(0)
+end
+
+opts.each do |opt, arg|
+ case opt
+ when '--help' then help(options)
+ when '--format' then options[:format] = arg.to_sym
+ when '--host-language' then options[:host_language] = arg
+ when '--num' then options[:num] = arg
+ when '--verbose' then options[:verbose] = true
+ when '--version' then options[:version] = arg
+ end
+end
+
+help(options) unless ARGV.length > 0
+
+crazy_ivan = CrazyIvan::StandAlone.new
+
+::JSON.parse(crazy_ivan.send(:manifest_json))['@graph'].each do |tc|
+ next unless tc["versions"].include?(options[:version])
+ next unless tc["hostLanguages"].include?(options[:host_language])
+ next if options[:num] && tc["num"] != options[:num]
+
+ STDOUT.write "#{tc["num"]}: "
+ uri = crazy_ivan.send(:get_test_url, options[:version], options[:host_language], tc["num"])
+ content = crazy_ivan.send(:get_test_content, options[:version], options[:host_language], tc["num"])
+ sparql = crazy_ivan.send(:get_test_content, options[:version], options[:host_language], tc["num"], "sparql")
+
+ if options[:verbose]
+ STDOUT.puts ":\n#{content}\n"
+ STDOUT.puts "query: \n#{sparql}\n"
+ end
+
+ runner_args = ARGV[0].split(/\s+/) + [
+ "--host-language", options[:host_language],
+ "--version", options[:version],
+ "--uri", uri
+ ]
+
+ if tc["queryParam"]
+ tc["queryParam"].each do |p|
+ arg, value = p.split('=')
+ runner_args << "--#{arg}"
+ runner_args << value if value
+ end
+ end
+
+ IO.popen(runner_args, "r+") do |io|
+ io.write(content)
+ io.close_write
+ out = io.read
+ graph = RDF::Graph.new << RDF::Turtle::Reader.new(out, :base_uri => uri)
+ result = SPARQL.execute(sparql, graph)
+ STDOUT.write "result: " if options[:verbose]
+ expected = tc["expectedResults"] ? RDF::Literal::TRUE : RDF::Literal::FALSE
+ STDOUT.puts result == expected ? "passed" : "failed"
+ end
+end

0 comments on commit f99d19a

Please sign in to comment.