aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-06-21 14:33:29 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-06-21 20:07:03 +0200
commit0a8020bbe3cbe145b86945ac13ee7d376ef110f5 (patch)
treee69a7f97ce1397d40185a5bb6a8b86ca8bad9c00 /test
parent81034c52f8f1b227c55d8ae998963ad534073501 (diff)
downloaddotty-0a8020bbe3cbe145b86945ac13ee7d376ef110f5.tar.gz
dotty-0a8020bbe3cbe145b86945ac13ee7d376ef110f5.tar.bz2
dotty-0a8020bbe3cbe145b86945ac13ee7d376ef110f5.zip
Add tests fixing #1322
Diffstat (limited to 'test')
-rw-r--r--test/scripts/TestDotc.scala89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/scripts/TestDotc.scala b/test/scripts/TestDotc.scala
new file mode 100644
index 000000000..f662a2695
--- /dev/null
+++ b/test/scripts/TestDotc.scala
@@ -0,0 +1,89 @@
+package test
+
+import org.junit.Assert._
+import org.junit.{Before, After, Test}
+
+import scala.io.Source
+import scala.sys.process.{Process, ProcessLogger}
+import java.io.{File => JFile, FileNotFoundException}
+
+class TestDotc {
+ private val lineSep = util.Properties.lineSeparator
+ private def doUnlessWindows(op: => Unit) =
+ if (!System.getProperty("os.name").toLowerCase.contains("windows"))
+ op
+ else
+ Console.err.println("[warn] Could not perform test, windows batch-scripts not available")
+
+ private def executeScript(script: String): (Int, String) = {
+ val sb = new StringBuilder
+ val ret = Process(script) ! ProcessLogger(sb append _)
+ (ret, sb.toString)
+ }
+
+ private def deletePackages: Unit = {
+ def delete(path: String) = {
+ val file = new JFile(path)
+ if (file.exists) file.delete()
+ }
+
+ try {
+ for (jar <- Source.fromFile(".packages").getLines())
+ delete(jar)
+
+ delete(".packages")
+ delete("src/dotty/tools/dotc/Dummy.scala")
+ } catch {
+ case _: FileNotFoundException => ()
+ }
+ }
+
+ @Before def buildUp = deletePackages
+ @After def tearDown = deletePackages
+
+ /** bin/dotc script should be able to build hello world and successfully
+ * execute it using dotr
+ */
+ @Test def buildAndRunHelloWorld = doUnlessWindows {
+ val (retDotc, dotcOutput) = executeScript("bin/dotc tests/pos/HelloWorld.scala")
+
+ // Check correct output of building and running dotc
+ assert(
+ retDotc == 0,
+ s"bin/dotc script did not run properly. Output:$lineSep$dotcOutput"
+ )
+
+ val (retDotr, dotrOutput) = executeScript("bin/dotr HelloWorld")
+ assert(
+ retDotr == 0 && dotrOutput == "hello world",
+ s"Running hello world exited with status: $retDotr and output: $dotrOutput"
+ )
+ }
+
+ /** bin/dotc script should be able to detect changes in dotty sources and
+ * rebuild dotty if needed
+ */
+ @Test def rebuildIfNecessary = doUnlessWindows {
+ val (retFirstBuild, _) = executeScript("bin/dotc tests/pos/HelloWorld.scala")
+ assert(retFirstBuild == 0, "building dotc failed")
+
+ // Create a new file
+ new JFile("src/dotty/tools/dotc/Dummy.scala").createNewFile()
+
+ val (retSecondBuild, output) = executeScript("bin/dotc tests/pos/HelloWorld.scala")
+ assert(
+ retSecondBuild == 0 && output.contains("rebuilding"),
+ s"Rebuilding the tool should result in jar files being rebuilt. Status: $retSecondBuild, output:$lineSep$output")
+ }
+
+ /** if no changes to dotty, dotc script should be fast */
+ @Test def beFastOnNoChanges = doUnlessWindows {
+ val (retFirstBuild, _) = executeScript("bin/dotc tests/pos/HelloWorld.scala")
+ assert(retFirstBuild == 0, "building dotc failed")
+
+ val (ret, output) = executeScript("bin/dotc tests/pos/HelloWorld.scala")
+ assert(
+ ret == 0 && !output.contains("rebuilding"),
+ s"Project recompiled when it didn't need to be. Status $ret, output:$lineSep$output")
+ }
+}