diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-06 23:35:57 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-06 23:35:57 -0500 |
commit | f0dc760df8757caea1d83b15142a3d0704488636 (patch) | |
tree | a3c9d8351de510d98610910862f91d8826b33ce1 /test/test.scala | |
parent | 4dae0e69f4b2947942d5ff7d4edee482073ee26b (diff) | |
download | cbt-f0dc760df8757caea1d83b15142a3d0704488636.tar.gz cbt-f0dc760df8757caea1d83b15142a3d0704488636.tar.bz2 cbt-f0dc760df8757caea1d83b15142a3d0704488636.zip |
trap and pass exit codes throug the app, pass logger on to tests, remove the lib. qualification from Stage1 for better readability
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) } } |