diff options
Diffstat (limited to 'test/test.scala')
-rw-r--r-- | test/test.scala | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/test/test.scala b/test/test.scala index 9ab5b4e..3befa4a 100644 --- a/test/test.scala +++ b/test/test.scala @@ -1,3 +1,4 @@ +import cbt._ import cbt.paths._ import scala.collection.immutable.Seq @@ -5,7 +6,7 @@ object Main{ // micro framework var successes = 0 var failures = 0 - def assert(condition: Boolean, msg: String = null) = { + def assert(condition: Boolean, msg: String = "")(implicit logger: Logger) = { scala.util.Try{ Predef.assert(condition, msg) }.map{ _ => @@ -19,12 +20,14 @@ object Main{ }.get } - def runCbt(path: String, args: Seq[String]) = { + def runCbt(path: String, args: Seq[String])(implicit logger: Logger): Result = { import java.io._ - val allArgs = ((cbtHome + "/cbt") +: args) + val allArgs = ((cbtHome + "/cbt") +: args :+ "-Dlog=all") + logger.test(allArgs.toString) val pb = new ProcessBuilder( allArgs :_* ) pb.directory(new File(cbtHome + "/test/" + path)) - val p = pb.start + val p = pb.inheritIO.start + p.waitFor val berr = new BufferedReader(new InputStreamReader(p.getErrorStream)); val bout = new BufferedReader(new InputStreamReader(p.getInputStream)); p.waitFor @@ -34,32 +37,32 @@ object Main{ Result(out, err, p.exitValue == 0) } case class Result(out: String, err: String, exit0: Boolean) - def assertSuccess(res: Result) = { + def assertSuccess(res: Result)(implicit logger: Logger) = { assert(res.exit0,res.toString) } // tests - def usage(path: String) = { + def usage(path: String)(implicit logger: Logger) = { val usageString = "Methods provided by CBT" val res = runCbt(path, Seq()) - assert(res.out == "", res.out) + logger.test(res.toString) + assertSuccess(res) + assert(res.out == "", "#"+res.out+"#") assert(res.err contains usageString, res.err) } - def compile(path: String) = { + def compile(path: String)(implicit logger: Logger) = { val res = runCbt(path, Seq("compile")) assertSuccess(res) // assert(res.err == "", res.err) // FIXME: enable this } def main(args: Array[String]): Unit = { - import cbt._ - - println("Running tests ") + implicit val logger: Logger = new Init(args).logger + System.err.println("Running tests "+args.toList) usage("nothing") compile("nothing") { - val logger = new Logger(Set[String]()) val noContext = Context(cbtHome + "/test/" + "nothing",Seq(),logger) val b = new Build(noContext){ override def dependencies = Seq( @@ -71,8 +74,8 @@ object Main{ assert(cp.strings.distinct == cp.strings, "duplicates in classpath: "+cp) } - println(" DONE!") - println(successes+" succeeded, "+ failures+" failed" ) + System.err.println(" DONE!") + System.err.println(successes+" succeeded, "+ failures+" failed" ) if(failures > 0) System.exit(1) else System.exit(0) } } |