Skip to content

Instantly share code, notes, and snippets.

@spencerwi
Last active September 17, 2016 18:48
Show Gist options
  • Save spencerwi/91aa4b5520434b8285d100b8cd1001c3 to your computer and use it in GitHub Desktop.
Save spencerwi/91aa4b5520434b8285d100b8cd1001c3 to your computer and use it in GitHub Desktop.
Codewars test harness for scala (using scalatest)

How to run

cat CodeWarsTestRunner.scala ExampleTestUsingCodeWarsTestRunner.scala | scala -cp <scalatest-jarfile>

Cool, what's the problem, why don't you just PR it?

Still sorting out how to make the scala repl not print verbose return types constantly and only print stuff that I println

import org.scalatest._;
import org.scalatest.events._;
class CodeWarsReporter extends Reporter {
def apply(event: Event) : Unit = event match {
case e: SuiteStarting => println(s"<DESCRIBE::> ${e.suiteName}")
case e: ScopeOpened => println(s"<DESCRIBE::> ${e.message}")
case e: TestStarting => println(s"<IT::>${e.testName}")
case e: TestSucceeded => {
println(s"<PASSED::>${e.testName}")
e.duration match {
case Some(time) => println(s"<COMPLETEDIN::>${time}")
case _ => ()
}
}
case e: TestFailed => {
println(s"<FAILED::>${e.message}");
e.duration match {
case Some(time) => println(s"<COMPLETEDIN::>${time}")
case _ => ()
}
}
case e: RunAborted => println(s"<ERROR::>${e.message}")
case _ => ()
}
}
class CodeWarsSpec extends FunSpec with Matchers {
override def run(testName: Option[String], args: Args) : Status = {
val rep = new CodeWarsReporter()
return super.run(testName, args.copy(reporter = rep))
}
}
class SomeTest extends CodeWarsSpec {
describe("Something") {
it("should work correctly") {
(2+2) should equal(4)
}
it("should handle failing tests") {
true should equal(false)
}
it("should handle exceptions") {
throw new RuntimeException("Exception got thrown!")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment