cat CodeWarsTestRunner.scala ExampleTestUsingCodeWarsTestRunner.scala | scala -cp <scalatest-jarfile>
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!") | |
| } | |
| } | |
| } |