factor out resourceDir and resourceFile (centralize assumption about test pwd)

This commit is contained in:
Havoc Pennington 2011-11-27 20:10:06 -05:00
parent 0457e352fb
commit 907048fe2b
3 changed files with 12 additions and 10 deletions

View File

@ -17,9 +17,6 @@ import org.junit.runners.AllTests
class EquivalentsTest extends TestUtils {
private def equivDirs() = {
val resourceDir = new File("config/src/test/resources")
if (!resourceDir.exists())
throw new RuntimeException("This test can only be run from the project's root directory")
val rawEquivs = resourceDir.listFiles()
val equivs = rawEquivs.filter({ f => f.getName().startsWith("equiv") })
equivs

View File

@ -220,13 +220,6 @@ class PublicApiTest extends TestUtils {
}
}
private def resourceFile(filename: String) = {
val resourceDir = new File("config/src/test/resources")
if (!resourceDir.exists())
throw new RuntimeException("This test can only be run from the project's root directory")
new File(resourceDir, filename)
}
@Test
def defaultParseOptions() {
val d = ConfigParseOptions.defaults()

View File

@ -12,6 +12,7 @@ import com.typesafe.config.ConfigParseOptions
import com.typesafe.config.Config
import com.typesafe.config.ConfigSyntax
import com.typesafe.config.ConfigFactory
import java.io.File
abstract trait TestUtils {
protected def intercept[E <: Throwable: Manifest](block: => Unit): E = {
@ -431,4 +432,15 @@ abstract trait TestUtils {
// the parser; in the test suite we are often testing the parser,
// so we don't want to use the parser to build the expected result.
def path(elements: String*) = new Path(elements: _*)
val resourceDir = {
val f = new File("config/src/test/resources")
if (!f.exists())
throw new Exception("Tests must be run from the root project directory containing " + f.getPath())
f
}
protected def resourceFile(filename: String) = {
new File(resourceDir, filename)
}
}