|
| 1 | +package nebula.plugin.clojure |
| 2 | + |
| 3 | +class ClojureRunSpec extends BaseIntegrationTestKitSpec { |
| 4 | + |
| 5 | + private final APP_CLJ = '''\ |
| 6 | + (ns test.nebula.app) |
| 7 | +
|
| 8 | + (defn hello |
| 9 | + [name] |
| 10 | + (println "Hello," name)) |
| 11 | +
|
| 12 | + (defn greet-world |
| 13 | + [] |
| 14 | + (println "Hello, World!")) |
| 15 | + '''.stripIndent() |
| 16 | + |
| 17 | + def 'clojureRun task can be created and registered'() { |
| 18 | + given: |
| 19 | + buildFile << '''\ |
| 20 | + plugins { |
| 21 | + id 'com.netflix.nebula.clojure' |
| 22 | + } |
| 23 | +
|
| 24 | + repositories { mavenCentral() } |
| 25 | +
|
| 26 | + dependencies { |
| 27 | + implementation 'org.clojure:clojure:1.10.3' |
| 28 | + } |
| 29 | + '''.stripIndent() |
| 30 | + |
| 31 | + settingsFile << 'rootProject.name="clojure-run-test"' |
| 32 | + |
| 33 | + def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula') |
| 34 | + clojurefiles.mkdirs() |
| 35 | + new File(clojurefiles, 'app.clj').text = APP_CLJ |
| 36 | + |
| 37 | + when: |
| 38 | + def result = runTasks('tasks', '--all') |
| 39 | + |
| 40 | + then: |
| 41 | + noExceptionThrown() |
| 42 | + result.output.contains('clojureRun') |
| 43 | + } |
| 44 | + |
| 45 | + def 'clojureRun task accepts --fn command line option'() { |
| 46 | + given: |
| 47 | + buildFile << '''\ |
| 48 | + plugins { |
| 49 | + id 'com.netflix.nebula.clojure' |
| 50 | + } |
| 51 | +
|
| 52 | + repositories { mavenCentral() } |
| 53 | +
|
| 54 | + dependencies { |
| 55 | + implementation 'org.clojure:clojure:1.10.3' |
| 56 | + } |
| 57 | + '''.stripIndent() |
| 58 | + |
| 59 | + settingsFile << 'rootProject.name="clojure-run-with-fn"' |
| 60 | + |
| 61 | + def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula') |
| 62 | + clojurefiles.mkdirs() |
| 63 | + new File(clojurefiles, 'app.clj').text = APP_CLJ |
| 64 | + |
| 65 | + when: |
| 66 | + def result = runTasks('clojureRun', '--fn=test.nebula.app/greet-world') |
| 67 | + |
| 68 | + then: |
| 69 | + noExceptionThrown() |
| 70 | + result.output.contains('Hello, World!') |
| 71 | + } |
| 72 | + |
| 73 | + def 'clojureRun task can be configured with fn property'() { |
| 74 | + given: |
| 75 | + buildFile << '''\ |
| 76 | + plugins { |
| 77 | + id 'com.netflix.nebula.clojure' |
| 78 | + } |
| 79 | +
|
| 80 | + repositories { mavenCentral() } |
| 81 | +
|
| 82 | + dependencies { |
| 83 | + implementation 'org.clojure:clojure:1.10.3' |
| 84 | + } |
| 85 | +
|
| 86 | + tasks.named('clojureRun') { |
| 87 | + fn = 'test.nebula.app/greet-world' |
| 88 | + } |
| 89 | + '''.stripIndent() |
| 90 | + |
| 91 | + settingsFile << 'rootProject.name="clojure-run-configured"' |
| 92 | + |
| 93 | + def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula') |
| 94 | + clojurefiles.mkdirs() |
| 95 | + new File(clojurefiles, 'app.clj').text = APP_CLJ |
| 96 | + |
| 97 | + when: |
| 98 | + def result = runTasks('clojureRun') |
| 99 | + |
| 100 | + then: |
| 101 | + noExceptionThrown() |
| 102 | + result.output.contains('Hello, World!') |
| 103 | + } |
| 104 | + |
| 105 | + def 'clojureRun task works with fn property using Provider API'() { |
| 106 | + given: |
| 107 | + buildFile << '''\ |
| 108 | + plugins { |
| 109 | + id 'com.netflix.nebula.clojure' |
| 110 | + } |
| 111 | +
|
| 112 | + repositories { mavenCentral() } |
| 113 | +
|
| 114 | + dependencies { |
| 115 | + implementation 'org.clojure:clojure:1.10.3' |
| 116 | + } |
| 117 | +
|
| 118 | + tasks.named('clojureRun') { |
| 119 | + fn.set('test.nebula.app/greet-world') |
| 120 | + } |
| 121 | + '''.stripIndent() |
| 122 | + |
| 123 | + settingsFile << 'rootProject.name="clojure-run-provider-api"' |
| 124 | + |
| 125 | + def clojurefiles = new File(projectDir, 'src/main/clojure/test/nebula') |
| 126 | + clojurefiles.mkdirs() |
| 127 | + new File(clojurefiles, 'app.clj').text = APP_CLJ |
| 128 | + |
| 129 | + when: |
| 130 | + def result = runTasks('clojureRun') |
| 131 | + |
| 132 | + then: |
| 133 | + noExceptionThrown() |
| 134 | + result.output.contains('Hello, World!') |
| 135 | + } |
| 136 | +} |
0 commit comments