Skip to content

Commit

Permalink
making ignoreExitCode a configurable parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Storey committed Dec 14, 2012
1 parent 3767683 commit 4fc9fd3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/groovy/com/eriwen/gradle/js/tasks/JsHintTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class JsHintTask extends SourceTask {

@OutputFile def dest

def ignoreExitCode = true;

File getDest() {
project.file(dest)
}
Expand All @@ -39,6 +41,6 @@ class JsHintTask extends SourceTask {
new File(project.buildDir, TMP_DIR), JSHINT_PATH)
final List<String> args = [jshintJsFile.canonicalPath]
args.addAll(source.files.collect { it.canonicalPath })
rhino.execute(args, [ignoreExitCode: true, out: new FileOutputStream(dest as File)])
rhino.execute(args, [ignoreExitCode: ignoreExitCode, out: new FileOutputStream(dest as File)])
}
}
81 changes: 81 additions & 0 deletions src/test/groovy/com/eriwen/gradle/js/JsHintTaskTest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.eriwen.gradle.js

import org.gradle.api.Project
import org.gradle.process.internal.ExecException
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification

class JsHintTaskTest extends Specification {

@Rule TemporaryFolder dir = new TemporaryFolder();

Project project = ProjectBuilder.builder().build()
def task
def src

def setup() {
project.apply(plugin: JsPlugin)
task = project.tasks.jshint
src = dir.newFolder()
task.source = src
task.dest = dir.newFile()
}

def "build ignores result by default"() {
given:
addValidFile()
addInvalidFile()

when:
task.run();


then:
notThrown ExecException
}

def "build passes with only valid files"() {
given:
task.ignoreExitCode = false;
addValidFile()

when:
task.run();

then:
notThrown ExecException
}

def "build fails with invalid files"() {
given:
task.ignoreExitCode = false;
addValidFile()
addInvalidFile()

when:
task.run();

then:
ExecException e = thrown()
}


def addValidFile() {
addFile("valid.js", "var a = 5;")
}

def addInvalidFile() {
// no semicolon, jshint should fail
addFile("invalid.js", "var a = 5")
}

def addFile(name,contents) {
def file = new File(src,name)
file << contents
}

}


0 comments on commit 4fc9fd3

Please sign in to comment.