Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring clojure-native up to date with master HEAD #265

Merged
merged 14 commits into from
Mar 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 58 additions & 35 deletions clojure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,63 @@
<name>Cucumber-JVM: Clojure</name>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<!-- These dependencies are required in order to find classes when running in an IDE - they haven't been jar-jarred -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.java-diff-utils</groupId>
<artifactId>diffutils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<namespaces>
<namespace>cucumber.*</namespace>
</namespaces>
<sourceDirectories>
<sourceDirectory>src/main/clj</sourceDirectory>
</sourceDirectories>
<compileDeclaredNamespaceOnly>true</compileDeclaredNamespaceOnly>
</configuration>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
137 changes: 137 additions & 0 deletions clojure/src/main/clj/cucumber/runtime/clj.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
(ns cucumber.runtime.clj
(:import (cucumber.runtime CucumberException
JdkPatternArgumentMatcher
StepDefinition
HookDefinition)
(cucumber.runtime.snippets Snippet
SnippetGenerator)
(gherkin TagExpression)
(clojure.lang RT))
(:gen-class :name cucumber.runtime.clj.Backend
:implements [cucumber.runtime.Backend]
:constructors
{[cucumber.io.ResourceLoader] []}
:init init
:state state))

(def glue (atom nil))

(defn clojure-snippet []
(reify
Snippet
(template [_]
(str
"({0} #\"{1}\"\n"
" (fn [{3}]\n"
" '' {4}\n"
" ))\n"))
(arguments [_ argumentTypes]
(SnippetGenerator/untypedArguments argumentTypes))
(namedGroupStart [_] nil)
(namedGroupEnd [_] nil)
(escapePattern [_ pattern]
(str pattern))))

(def snippet-generator (SnippetGenerator. (clojure-snippet)))

(defn load-script [path]
(try
(RT/load (str (.replaceAll path ".clj$" "")) true)
(catch Throwable t
(throw (CucumberException. t)))))

(defn- -init [resource-loader]
[[] (atom {:resource-loader resource-loader})])

(defn -loadGlue [cljb a-glue glue-paths]
(reset! glue a-glue)
(doseq [path glue-paths
resource (.resources (:resource-loader @(.state cljb)) path ".clj")]
(binding [*ns* (create-ns 'cucumber.runtime.clj)]
(load-script (.getPath resource)))))

(defn- -buildWorld [cljb])

(defn- -disposeWorld [cljb])

(defn- -getSnippet [cljb step]
(.getSnippet snippet-generator step))

(defn- -setUnreportedStepExecutor [cljb executor]
"executor")

(defn add-step-definition [pattern fun location]
(.addStepDefinition
@glue
(reify
StepDefinition
(matchedArguments [_ step]
(.argumentsFrom (JdkPatternArgumentMatcher. pattern)
(.getName step)))
(getLocation [_]
(str (:file location) ":" (:line location)))
(getParameterTypes [_]
nil)
(execute [_ locale args]
(apply fun args))
(isDefinedAt [_ stack-trace-element]
(and (= (.getLineNumber stack-trace-element)
(:line location))
(= (.getFileName stack-trace-element)
(:file location))))
(getPattern [_]
(str pattern)))))

(defmulti add-hook-definition (fn [t & _] t))

(defmethod add-hook-definition :before [_ tag-expression hook-fun]
(let [te (TagExpression. tag-expression)]
(.addBeforeHook
@glue
(reify
HookDefinition
(execute [hd scenario-result]
(hook-fun))
(matches [hd tags]
(.eval te tags))
(getOrder [hd] 0)))))

(defmethod add-hook-definition :after [_ tag-expression hook-fun]
(let [te (TagExpression. tag-expression)
max-parameter-count (->> hook-fun class .getDeclaredMethods
(filter #(= "invoke" (.getName %)))
(map #(count (.getParameterTypes %)))
(apply max))]
(.addBeforeHook
@glue
(reify
HookDefinition
(execute [hd scenario-result]
(if (zero? max-parameter-count)
(hook-fun)
(hook-fun scenario-result)))
(matches [hd tags]
(.eval te tags))
(getOrder [hd] 0)))))

;; TODO: before and after hooks

(defmacro step-macros [& names]
(cons 'do
(for [name names]
`(defmacro ~name [pattern# fun#]
`(add-step-definition ~pattern# ~fun#
'~{:file *file*
:line (:line (meta ~'&form))})))))
(step-macros
Given When Then And But)

(defmacro Before [& fun]
(when (not (empty? fun))
(let [fun (first fun)]
`(add-hook-definition :before [] ~fun))))

(defmacro After [& fun]
(when (not (empty? fun))
(let [fun (first fun)]
`(add-hook-definition :after [] ~fun))))
28 changes: 28 additions & 0 deletions clojure/src/main/clj/leiningen/cuke.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(ns leiningen.cuke
(:require [leiningen.compile :as lc]
[leiningen.core :as c]))

(defn cuke
"runs cucumber"
[project]
;; basically a reimplimentation of cli.Main that doesn't annoyingly
;; call System/exit
(lc/eval-in-project
project
`(let [~'runtime (cucumber.runtime.Runtime.
(list* ["test/cucumber"])
(cucumber.io.FileResourceLoader.) false)
mformatter# (doto (cucumber.formatter.MultiFormatter.)
(.add (.createFormatter
(cucumber.formatter.FormatterFactory.)
"pretty" System/out)))
formatter# (.formatterProxy mformatter#)]
(.run ~'runtime
(list* ["test/cucumber/features"])
(list)
formatter#
(.reporterProxy mformatter#))
(.done formatter#)
(println)
~(when-not c/*interactive?*
`(System/exit (.exitStatus ~'runtime))))))
103 changes: 0 additions & 103 deletions clojure/src/main/java/cucumber/runtime/clojure/ClojureBackend.java

This file was deleted.

18 changes: 0 additions & 18 deletions clojure/src/main/java/cucumber/runtime/clojure/ClojureHook.java

This file was deleted.

Loading