-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated 'clojure-native' of https://github.com/hiredman/cucumber-jvm …
…to apply cleanly to master HEAD Changed cucumber.runtime.clj to implement cucumber.runtime.clj.Backend#loadGlue Implemented getSnippet to return the same snippets as ClojureBackend.java did Fixed a problem with creating TagExpression in add-hook-definition Added additional feature to execute clojure-snippet Added Before and After step definitions to execute add-hook-definition
- Loading branch information
Showing
15 changed files
with
262 additions
and
292 deletions.
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
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,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)))) |
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)))))) |
103 changes: 0 additions & 103 deletions
103
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.
Oops, something went wrong.