-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Clojure native #138
Closed
Closed
Clojure native #138
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ee42979
first pass at clojure native backend
hiredman 3e81094
clean up the pom
hiredman 8a45465
delete old clojure backend
hiredman b5a5a04
Merge remote branch 'origin/master' into clojure-native
hiredman 3f7b2f2
track interface change
hiredman 4718430
lein plugin for running cukes
hiredman ac66f53
run lein plugin in project's jvm, not lein's
hiredman 94ae4d9
misc hackery to deal with file paths vs. classpaths, etc
hiredman 63ef1fb
don't try and compile the lein plugin
hiredman 9cdf7a6
Merge remote branch 'origin/master' into clojure-native
hiredman 3ed096c
more than one world, who knew?
hiredman ad8c7a9
before and after hooks
hiredman d4ffedd
make 'lein cuke' suitable for 'lein interactive'
hiredman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,66 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-jvm</artifactId> | ||
<relativePath>../pom.xml</relativePath> | ||
<version>1.0.0.RC2-SNAPSHOT</version> | ||
</parent> | ||
<parent> | ||
<groupId>info.cukes</groupId> | ||
<artifactId>cucumber-jvm</artifactId> | ||
<relativePath>../pom.xml</relativePath> | ||
<version>1.0.0.RC2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>cucumber-clojure</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Cucumber-JVM: Clojure</name> | ||
<artifactId>cucumber-clojure</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<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>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<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>junit</groupId> | ||
<artifactId>junit</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
(ns cucumber.runtime.clj | ||
(:import (cucumber.runtime CucumberException | ||
JdkPatternArgumentMatcher | ||
StepDefinition | ||
HookDefinition) | ||
(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 world (atom nil)) | ||
|
||
(defn load-script [path] | ||
(try | ||
(RT/load (str "cucumber/" (.replaceAll path ".clj$" "")) true) | ||
(catch Throwable t | ||
(throw (CucumberException. t))))) | ||
|
||
(defn- -init [resource-loader] | ||
[[] (atom {:resource-loader resource-loader})]) | ||
|
||
(defn- -buildWorld [cljb glue-paths a-world] | ||
(reset! world a-world) | ||
(doseq [path glue-paths | ||
resource (.resources (:resource-loader @(.state cljb)) path ".clj")] | ||
;; scripts are loaded with this namespace as the current namespace | ||
;; to give access to the macros defined below | ||
;; you can still use (ns ...) as normal | ||
(binding [*ns* (create-ns 'cucumber.runtime.clj)] | ||
(load-script (.getPath resource))))) | ||
|
||
(defn- -disposeWorld [cljb]) | ||
|
||
;; Snippets don't have a nice interface to extend :( | ||
(defn- -getSnippet [cljb step] | ||
"snippet!") | ||
|
||
(defn add-step-definition [pattern fun location] | ||
(.addStepDefinition | ||
@world | ||
(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 [_] | ||
pattern)))) | ||
|
||
(defmulti add-hook-definition (fn [t & _] t)) | ||
|
||
(defmethod add-hook-definition :before [_ tag-expression hook-fun] | ||
(let [te (TagExpression. (list* (seq tag-expression)))] | ||
(.addBeforeHook | ||
@world | ||
(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. (list* (seq tag-expression))) | ||
max-parameter-count (->> hook-fun class .getDeclaredMethods | ||
(filter #(= "invoke" (.getName %))) | ||
(map #(count (.getParameterTypes %))) | ||
(apply max))] | ||
(.addBeforeHook | ||
@world | ||
(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] | ||
`(add-hook-definition :before [] ~fun)) | ||
|
||
(defmacro After [fun] | ||
`(add-hook-definition :after [] ~fun)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))))) |
90 changes: 0 additions & 90 deletions
90
clojure/src/main/java/cucumber/runtime/clojure/ClojureBackend.java
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
clojure/src/main/java/cucumber/runtime/clojure/ClojureHook.java
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
clojure/src/main/java/cucumber/runtime/clojure/ClojureHookDefinition.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO is done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is, I forgot to delete it