Skip to content

Commit

Permalink
Updated test settings in build.sbt to run hooks before and after tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff May committed Feb 3, 2016
1 parent 9f2a2ea commit 6a4834b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
31 changes: 31 additions & 0 deletions build.sbt
Expand Up @@ -38,3 +38,34 @@ scalacOptions in ThisBuild := Seq(
"-Xfuture"
)

lazy val cleanup = settingKey[Boolean]("Set to false to disable cleaning up after each test")
cleanup := true
addCommandAlias("cleanupOn", "set cleanup := true")
addCommandAlias("cleanupOff", "set cleanup := false")

// call setup and teardown hooks before and after any tests run
testOptions ++= Seq(
Tests.Setup {
classLoader: ClassLoader =>
val cleanDBAfterTests = cleanup.value
sys.props += "NEO4J_TEST_CLEANUP_AFTER" -> cleanDBAfterTests.toString
if (cleanDBAfterTests) {
println(AnsiColor.GREEN +
"""All tests will cleanup their changes to their namespace in the database after they finish.
|Note: The tests will cleanup their own namespace from previous test runs before they run.""".stripMargin
+ AnsiColor.RESET)
}
else {
// This can cause tests to fail on the second run
println(AnsiColor.BLUE +
"""Tests will NOT cleanup their changes to their namespace in the database after they finish.
|Note: The tests will cleanup their own namespace from previous test runs before they run.""".stripMargin
+ AnsiColor.RESET)
}
classLoader.loadClass("me.jeffmay.neo4j.client.SetupBeforeTests").newInstance()
},
Tests.Cleanup {
classLoader: ClassLoader =>
classLoader.loadClass("me.jeffmay.neo4j.client.CleanupAfterTests").newInstance()
}
)
49 changes: 49 additions & 0 deletions project/AnsiColor.scala
@@ -0,0 +1,49 @@

object AnsiColor {
/** Foreground color for ANSI black */
final val BLACK = "\u001b[30m"
/** Foreground color for ANSI red */
final val RED = "\u001b[31m"
/** Foreground color for ANSI green */
final val GREEN = "\u001b[32m"
/** Foreground color for ANSI yellow */
final val YELLOW = "\u001b[33m"
/** Foreground color for ANSI blue */
final val BLUE = "\u001b[34m"
/** Foreground color for ANSI magenta */
final val MAGENTA = "\u001b[35m"
/** Foreground color for ANSI cyan */
final val CYAN = "\u001b[36m"
/** Foreground color for ANSI white */
final val WHITE = "\u001b[37m"

/** Background color for ANSI black */
final val BLACK_B = "\u001b[40m"
/** Background color for ANSI red */
final val RED_B = "\u001b[41m"
/** Background color for ANSI green */
final val GREEN_B = "\u001b[42m"
/** Background color for ANSI yellow */
final val YELLOW_B = "\u001b[43m"
/** Background color for ANSI blue */
final val BLUE_B = "\u001b[44m"
/** Background color for ANSI magenta */
final val MAGENTA_B = "\u001b[45m"
/** Background color for ANSI cyan */
final val CYAN_B = "\u001b[46m"
/** Background color for ANSI white */
final val WHITE_B = "\u001b[47m"

/** Reset ANSI styles */
final val RESET = "\u001b[0m"
/** ANSI bold */
final val BOLD = "\u001b[1m"
/** ANSI underlines */
final val UNDERLINED = "\u001b[4m"
/** ANSI blink */
final val BLINK = "\u001b[5m"
/** ANSI reversed */
final val REVERSED = "\u001b[7m"
/** ANSI invisible */
final val INVISIBLE = "\u001b[8m"
}

0 comments on commit 6a4834b

Please sign in to comment.