From f6a2a3ed312e82327b5e178cc2570ec0989cbe8c Mon Sep 17 00:00:00 2001 From: cheeseng Date: Fri, 9 May 2014 23:24:55 +0800 Subject: [PATCH 01/14] Added execute permission to runem.sh. --- runem.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 runem.sh diff --git a/runem.sh b/runem.sh old mode 100644 new mode 100755 From 48b4d78f776332a39ea76a38e967f1c48b33249e Mon Sep 17 00:00:00 2001 From: cheeseng Date: Fri, 9 May 2014 23:53:46 +0800 Subject: [PATCH 02/14] Changed to use shapeless 2.0.0 instead of 2.0.0-SNAPSHOT. --- shapelessTables.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shapelessTables.scala b/shapelessTables.scala index bd761d1..f81eb02 100644 --- a/shapelessTables.scala +++ b/shapelessTables.scala @@ -208,9 +208,9 @@ val scalatestJar = new File("scalatest_" + scalaVersion + "-" + scalaTestVersion if (!scalatestJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestVersion + "/scalatest_" + scalaVersion + "-" + scalaTestVersion + ".jar", scalatestJar) -val shapelessJar = new File("shapeless_2.10.2-2.0.0-SNAPSHOT.jar") +val shapelessJar = new File("shapeless_2.10.2-2.0.0.jar") if (!shapelessJar.exists) - downloadFile("http://oss.sonatype.org/content/repositories/snapshots/com/chuusai/shapeless_2.10.2/2.0.0-SNAPSHOT/shapeless_2.10.2-2.0.0-SNAPSHOT.jar", shapelessJar) + downloadFile("http://oss.sonatype.org/content/repositories/releases/com/chuusai/shapeless_2.10.2/2.0.0/shapeless_2.10.2-2.0.0.jar", shapelessJar) val baseDir = new File("shapelessTables") if (baseDir.exists) @@ -348,4 +348,4 @@ finally { fileCountFile.flush() fileSizeFile.write("\n") fileSizeFile.flush() -} \ No newline at end of file +} From 84c99f987a034f55644f4b512c1cae6fccb3a03e Mon Sep 17 00:00:00 2001 From: cheeseng Date: Sat, 10 May 2014 00:52:50 +0800 Subject: [PATCH 03/14] Upgraded to latest library versions. --- allClassTestsInOneFile.scala | 6 +++--- allMethodTestsInOneFile.scala | 8 ++++---- allTestsInOneFile.scala | 6 +++--- assertTestsInOneFile.scala | 6 +++--- scalautilsScalaz.scala | 6 +++--- tenTestsPerFile.scala | 6 +++--- testsIn100Files.scala | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/allClassTestsInOneFile.scala b/allClassTestsInOneFile.scala index 840f764..ef3fd05 100644 --- a/allClassTestsInOneFile.scala +++ b/allClassTestsInOneFile.scala @@ -14,9 +14,9 @@ def scalaVersion = { } */ def scalaVersion = "2.10" -val scalaTestVersion = "2.0" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val scalaTestVersion = "2.1.6" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) diff --git a/allMethodTestsInOneFile.scala b/allMethodTestsInOneFile.scala index 29e1e24..eb080c9 100644 --- a/allMethodTestsInOneFile.scala +++ b/allMethodTestsInOneFile.scala @@ -13,12 +13,12 @@ import scala.math.pow }*/ def scalaVersion = "2.10" -val scalaTestVersion = "2.0" +val scalaTestVersion = "2.1.6" val junitVersion = "4.11" // JUnit depends on hamcrestVersion val hamcrestVersion = "1.3" -val testngVersion = "6.8" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val testngVersion = "6.8.8" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) diff --git a/allTestsInOneFile.scala b/allTestsInOneFile.scala index bbb4d0a..dce5993 100644 --- a/allTestsInOneFile.scala +++ b/allTestsInOneFile.scala @@ -14,9 +14,9 @@ def scalaVersion = { } */ def scalaVersion = "2.10" -val scalaTestVersion = "2.0" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val scalaTestVersion = "2.1.6" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) diff --git a/assertTestsInOneFile.scala b/assertTestsInOneFile.scala index 9478c8f..242ecd7 100644 --- a/assertTestsInOneFile.scala +++ b/assertTestsInOneFile.scala @@ -14,9 +14,9 @@ def scalaVersion = { } */ def scalaVersion = "2.10" -val scalaTestVersion = "2.0" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val scalaTestVersion = "2.1.6" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) diff --git a/scalautilsScalaz.scala b/scalautilsScalaz.scala index a0eefa1..c37c6c6 100644 --- a/scalautilsScalaz.scala +++ b/scalautilsScalaz.scala @@ -4,8 +4,8 @@ import java.nio.channels.Channels import scala.annotation.tailrec def scalaVersion = "2.10" -val scalautilsVersion = "2.0" -val scalazVersion = "7.0.4" +val scalautilsVersion = "2.1.6" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) @@ -229,4 +229,4 @@ durationFile.close() fileCountFile.flush() fileCountFile.close() fileSizeFile.flush() -fileSizeFile.close() \ No newline at end of file +fileSizeFile.close() diff --git a/tenTestsPerFile.scala b/tenTestsPerFile.scala index 495179d..6a160b4 100644 --- a/tenTestsPerFile.scala +++ b/tenTestsPerFile.scala @@ -14,9 +14,9 @@ def scalaVersion = { } */ def scalaVersion = "2.10" -val scalaTestVersion = "2.0" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val scalaTestVersion = "2.1.6" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) diff --git a/testsIn100Files.scala b/testsIn100Files.scala index af9b4e1..a430fbd 100644 --- a/testsIn100Files.scala +++ b/testsIn100Files.scala @@ -14,9 +14,9 @@ def scalaVersion = { } */ def scalaVersion = "2.10" -val scalaTestVersion = "2.0" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val scalaTestVersion = "2.1.6" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) From e55401479d3806e42fcee67175b13895bb3a9a7b Mon Sep 17 00:00:00 2001 From: cheeseng Date: Sat, 10 May 2014 23:43:26 +0800 Subject: [PATCH 04/14] Make scripts to support scala 2.10 and 2.11, and make runem.sh to run the scripts using both scala 2.10 and 2.11. --- allClassTestsInOneFile.scala | 22 +++-- allMethodTestsInOneFile.scala | 23 +++-- allTestsInOneFile.scala | 22 +++-- assertMacro.scala | 2 +- assertTestsInOneFile.scala | 22 +++-- dataTables.scala | 38 +++++--- google-chart.scala | 170 ++++++++++++++++++++++++---------- runem.sh | 29 ++++-- scalautilsScalaz.scala | 17 +++- shapelessTables.scala | 29 ++++-- tenTestsPerFile.scala | 22 +++-- testsIn100Files.scala | 22 +++-- 12 files changed, 273 insertions(+), 145 deletions(-) diff --git a/allClassTestsInOneFile.scala b/allClassTestsInOneFile.scala index ef3fd05..6a09b2a 100644 --- a/allClassTestsInOneFile.scala +++ b/allClassTestsInOneFile.scala @@ -4,16 +4,18 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/* -def scalaVersion = { +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt } -*/ -def scalaVersion = "2.10" val scalaTestVersion = "2.1.6" val specs2Version = "2.3.11" val scalazVersion = "7.0.6" @@ -149,7 +151,7 @@ class ExampleSpec extends SpecificationClass { def is =""" + "\n" + def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -241,7 +243,7 @@ if (scalaVersion != "unknown") { if (!specs2ScalazJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-core_" + scalaVersion + "/" + scalazVersion + "/scalaz-core_" + scalaVersion + "-" + scalazVersion + ".jar", specs2ScalazJar) - val baseDir = new File("allClassTestsInOneFile") + val baseDir = new File("target/" + scalaVersion + "/allClassTestsInOneFile") if (baseDir.exists) deleteDir(baseDir) diff --git a/allMethodTestsInOneFile.scala b/allMethodTestsInOneFile.scala index eb080c9..e9c1e4c 100644 --- a/allMethodTestsInOneFile.scala +++ b/allMethodTestsInOneFile.scala @@ -4,15 +4,18 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/*def scalaVersion = { - val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion -}*/ +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} -def scalaVersion = "2.10" +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} val scalaTestVersion = "2.1.6" val junitVersion = "4.11" // JUnit depends on hamcrestVersion val hamcrestVersion = "1.3" @@ -89,7 +92,7 @@ def specs2MutableTestDefFun(x: Int): String = "\"increment " + x + "\" in" def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -174,7 +177,7 @@ if (scalaVersion != "unknown") { if (!testngJar.exists) downloadFile("http://repo1.maven.org/maven2/org/testng/testng/" + testngVersion + "/testng-" + testngVersion + ".jar", testngJar) - val baseDir = new File("allMethodTestsInOneFile") + val baseDir = new File("target/" + scalaVersion + "/allMethodTestsInOneFile") if (baseDir.exists) deleteDir(baseDir) diff --git a/allTestsInOneFile.scala b/allTestsInOneFile.scala index dce5993..c928807 100644 --- a/allTestsInOneFile.scala +++ b/allTestsInOneFile.scala @@ -4,16 +4,18 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/* -def scalaVersion = { +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt } -*/ -def scalaVersion = "2.10" val scalaTestVersion = "2.1.6" val specs2Version = "2.3.11" val scalazVersion = "7.0.6" @@ -150,7 +152,7 @@ class ExampleSpec extends Specification { def is =""" + "\n" + def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -221,7 +223,7 @@ if (scalaVersion != "unknown") { if (!specs2ScalazJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-core_" + scalaVersion + "/" + scalazVersion + "/scalaz-core_" + scalaVersion + "-" + scalazVersion + ".jar", specs2ScalazJar) - val baseDir = new File("allTestsInOneFile") + val baseDir = new File("target/" + scalaVersion + "/allTestsInOneFile") if (baseDir.exists) deleteDir(baseDir) diff --git a/assertMacro.scala b/assertMacro.scala index 4d372c0..775601a 100644 --- a/assertMacro.scala +++ b/assertMacro.scala @@ -245,4 +245,4 @@ durationFile.close() fileCountFile.flush() fileCountFile.close() fileSizeFile.flush() -fileSizeFile.close() \ No newline at end of file +fileSizeFile.close() diff --git a/assertTestsInOneFile.scala b/assertTestsInOneFile.scala index 242ecd7..c315daa 100644 --- a/assertTestsInOneFile.scala +++ b/assertTestsInOneFile.scala @@ -4,16 +4,18 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/* -def scalaVersion = { +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt } -*/ -def scalaVersion = "2.10" val scalaTestVersion = "2.1.6" val specs2Version = "2.3.11" val scalazVersion = "7.0.6" @@ -76,7 +78,7 @@ def specTestDefFun(x: Int): String = "def `increment " + x + "`" def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -139,7 +141,7 @@ if (scalaVersion != "unknown") { if (!scalatestJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestVersion + "/scalatest_" + scalaVersion + "-" + scalaTestVersion + ".jar", scalatestJar) - val baseDir = new File("assertTestsInOneFile") + val baseDir = new File("target/" + scalaVersion + "/assertTestsInOneFile") if (baseDir.exists) deleteDir(baseDir) diff --git a/dataTables.scala b/dataTables.scala index d8a6baf..aa3f1c9 100644 --- a/dataTables.scala +++ b/dataTables.scala @@ -4,19 +4,27 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/* -def scalaVersion = { +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt } -*/ -def scalaVersion = "2.10" -val scalaTestVersion = "2.0" -val specs2Version = "2.3.4" -val scalazVersion = "7.0.4" +val scalaTestVersion = "2.1.6" +val specs2Version = "2.3.11" +val scalazVersion = "7.0.6" +val shapelessVersion = "2.0.0" +val shapelessScalaVersion = + if (scalaVersion == "2.11") + scalaVersion + else + scala.util.Properties.scalaPropOrElse("version.number", "unknown") def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) @@ -190,7 +198,7 @@ def generateSpecs2Mutable(testCount: Int, targetDir: File): File = { def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -279,11 +287,11 @@ if (scalaVersion != "unknown") { if (!specs2ScalazJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-core_" + scalaVersion + "/" + scalazVersion + "/scalaz-core_" + scalaVersion + "-" + scalazVersion + ".jar", specs2ScalazJar) - val shapelessJar = new File("shapeless_2.10.2-2.0.0-SNAPSHOT.jar") + val shapelessJar = new File("shapeless_" + scalaVersion + "-" + shapelessVersion + ".jar") if (!shapelessJar.exists) - downloadFile("http://oss.sonatype.org/content/repositories/snapshots/com/chuusai/shapeless_2.10.2/2.0.0-SNAPSHOT/shapeless_2.10.2-2.0.0-SNAPSHOT.jar", shapelessJar) + downloadFile("http://oss.sonatype.org/content/repositories/releases/com/chuusai/shapeless_" + shapelessScalaVersion + "/" + shapelessVersion + "/shapeless_" + shapelessScalaVersion + "-" + shapelessVersion + ".jar", shapelessJar) - val baseDir = new File("dataTables") + val baseDir = new File("target/" + scalaVersion + "/dataTables") if (baseDir.exists) deleteDir(baseDir) diff --git a/google-chart.scala b/google-chart.scala index a1adb14..e87c233 100644 --- a/google-chart.scala +++ b/google-chart.scala @@ -135,72 +135,142 @@ def generateChartFile(srcDir: File, targetFile: File, whichChart: WhichChart = B println("Generated " + targetFile.getAbsolutePath) } -val allTestsInOneFileDir = new File("allTestsInOneFile") -val allTestsInOneFileStatDir = new File(allTestsInOneFileDir, "stat") -if (allTestsInOneFileStatDir.exists) - generateChartFile(allTestsInOneFileStatDir, new File(allTestsInOneFileDir, "allTestsInOneFile-graph.html")) +val allTestsInOneFile210Dir = new File("target/2.10/allTestsInOneFile") +val allTestsInOneFile210StatDir = new File(allTestsInOneFile210Dir, "stat") +if (allTestsInOneFile210StatDir.exists) + generateChartFile(allTestsInOneFile210StatDir, new File(allTestsInOneFile210Dir, "allTestsInOneFile-graph.html")) else - println("allTestsInOneFile/stat directory does not exist, allTestsInOneFile/allTestsInOneFile-graph.html will not be generated.") + println("target/2.10/allTestsInOneFile/stat directory does not exist, target/2.10/allTestsInOneFile/allTestsInOneFile-graph.html will not be generated.") + +val allTestsInOneFile211Dir = new File("target/2.11/allTestsInOneFile") +val allTestsInOneFile211StatDir = new File(allTestsInOneFile211Dir, "stat") +if (allTestsInOneFile211StatDir.exists) + generateChartFile(allTestsInOneFile211StatDir, new File(allTestsInOneFile211Dir, "allTestsInOneFile-graph.html")) +else + println("target/2.11/allTestsInOneFile/stat directory does not exist, target/2.11/allTestsInOneFile/allTestsInOneFile-graph.html will not be generated.") -val tenTestsPerFileDir = new File("tenTestsPerFile") -val tenTestsPerFileStatDir = new File(tenTestsPerFileDir, "stat") -if (tenTestsPerFileStatDir.exists) - generateChartFile(tenTestsPerFileStatDir, new File(tenTestsPerFileDir, "tenTestsPerFile-graph.html")) +val tenTestsPerFile210Dir = new File("target/2.10/tenTestsPerFile") +val tenTestsPerFile210StatDir = new File(tenTestsPerFile210Dir, "stat") +if (tenTestsPerFile210StatDir.exists) + generateChartFile(tenTestsPerFile210StatDir, new File(tenTestsPerFile210Dir, "tenTestsPerFile-graph.html")) else - println("tenTestsPerFile/stat directory does not exist, tenTestsPerFile/tenTestsPerFile-graph.html will not be generated.") + println("target/2.10/tenTestsPerFile/stat directory does not exist, target/2.10/tenTestsPerFile/tenTestsPerFile-graph.html will not be generated.") + +val tenTestsPerFile211Dir = new File("target/2.11/tenTestsPerFile") +val tenTestsPerFile211StatDir = new File(tenTestsPerFile211Dir, "stat") +if (tenTestsPerFile211StatDir.exists) + generateChartFile(tenTestsPerFile211StatDir, new File(tenTestsPerFile211Dir, "tenTestsPerFile-graph.html")) +else + println("target/2.11/tenTestsPerFile/stat directory does not exist, target/2.11/tenTestsPerFile/tenTestsPerFile-graph.html will not be generated.") -val testsIn100FilesDir = new File("testsIn100Files") -val testsIn100FilesStatDir = new File(testsIn100FilesDir, "stat") -if (testsIn100FilesStatDir.exists) - generateChartFile(testsIn100FilesStatDir, new File(testsIn100FilesDir, "testsIn100Files-graph.html"), FirstChart) +val testsIn100Files210Dir = new File("target/2.10/testsIn100Files") +val testsIn100Files210StatDir = new File(testsIn100Files210Dir, "stat") +if (testsIn100Files210StatDir.exists) + generateChartFile(testsIn100Files210StatDir, new File(testsIn100Files210Dir, "testsIn100Files-graph.html"), FirstChart) +else + println("target/2.10/testsIn100Files/stat directory does not exist, target/2.10/testsIn100Files/tenTestsPerFile-graph.html will not be generated.") + +val testsIn100Files211Dir = new File("target/2.11/testsIn100Files") +val testsIn100Files211StatDir = new File(testsIn100Files211Dir, "stat") +if (testsIn100Files211StatDir.exists) + generateChartFile(testsIn100Files211StatDir, new File(testsIn100Files211Dir, "testsIn100Files-graph.html"), FirstChart) +else + println("target/2.11/testsIn100Files/stat directory does not exist, target/2.11/testsIn100Files/tenTestsPerFile-graph.html will not be generated.") + +val dataTables210Dir = new File("target/2.10/dataTables") +val dataTables210StatDir = new File(dataTables210Dir, "stat") +if (dataTables210StatDir.exists) + generateChartFile(dataTables210StatDir, new File(dataTables210Dir, "dataTables-graph.html")) else - println("testsIn100Files/stat directory does not exist, testsIn100Files/tenTestsPerFile-graph.html will not be generated.") + println("target/2.10/dataTables/stat directory does not exist, target/2.10/dataTables/dataTables-graph.html will not be generated.") -val dataTablesDir = new File("dataTables") -val dataTablesStatDir = new File(dataTablesDir, "stat") -if (dataTablesStatDir.exists) - generateChartFile(dataTablesStatDir, new File(dataTablesDir, "dataTables-graph.html")) +val dataTables211Dir = new File("target/2.11/dataTables") +val dataTables211StatDir = new File(dataTables211Dir, "stat") +if (dataTables211StatDir.exists) + generateChartFile(dataTables211StatDir, new File(dataTables211Dir, "dataTables-graph.html")) else - println("dataTables/stat directory does not exist, dataTables/dataTables-graph.html will not be generated.") + println("target/2.11/dataTables/stat directory does not exist, target/2.11/dataTables/dataTables-graph.html will not be generated.") -val allMethodTestsInOneFileDir = new File("allMethodTestsInOneFile") -val allMethodTestsInOneFileStatDir = new File(allMethodTestsInOneFileDir, "stat") -if (allMethodTestsInOneFileStatDir.exists) - generateChartFile(allMethodTestsInOneFileStatDir, new File(allMethodTestsInOneFileDir, "allMethodTestsInOneFile-graph.html"), SecondChart) +val allMethodTestsInOneFile210Dir = new File("target/2.10/allMethodTestsInOneFile") +val allMethodTestsInOneFile210StatDir = new File(allMethodTestsInOneFile210Dir, "stat") +if (allMethodTestsInOneFile210StatDir.exists) + generateChartFile(allMethodTestsInOneFile210StatDir, new File(allMethodTestsInOneFile210Dir, "allMethodTestsInOneFile-graph.html"), SecondChart) else - println("allMethodTestsInOneFile/stat directory does not exist, allMethodTestsInOneFile/allMethodTestsInOneFile-graph.html will not be generated.") + println("target/2.10/allMethodTestsInOneFile/stat directory does not exist, target/2.10/allMethodTestsInOneFile/allMethodTestsInOneFile-graph.html will not be generated.") -val assertTestsInOneFileDir = new File("assertTestsInOneFile") -val assertTestsInOneFileStatDir = new File(assertTestsInOneFileDir, "stat") -if (assertTestsInOneFileStatDir.exists) - generateChartFile(assertTestsInOneFileStatDir, new File(assertTestsInOneFileDir, "assertTestsInOneFile-graph.html")) +val allMethodTestsInOneFile211Dir = new File("target/2.11/allMethodTestsInOneFile") +val allMethodTestsInOneFile211StatDir = new File(allMethodTestsInOneFile211Dir, "stat") +if (allMethodTestsInOneFile211StatDir.exists) + generateChartFile(allMethodTestsInOneFile211StatDir, new File(allMethodTestsInOneFile211Dir, "allMethodTestsInOneFile-graph.html"), SecondChart) +else + println("target/2.11/allMethodTestsInOneFile/stat directory does not exist, target/2.11/allMethodTestsInOneFile/allMethodTestsInOneFile-graph.html will not be generated.") + +val assertTestsInOneFile210Dir = new File("target/2.10/assertTestsInOneFile") +val assertTestsInOneFile210StatDir = new File(assertTestsInOneFile210Dir, "stat") +if (assertTestsInOneFile210StatDir.exists) + generateChartFile(assertTestsInOneFile210StatDir, new File(assertTestsInOneFile210Dir, "assertTestsInOneFile-graph.html")) else - println("assertTestsInOneFile/stat directory does not exist, assertTestsInOneFile/assertTestsInOneFile-graph.html will not be generated.") + println("target/2.10/assertTestsInOneFile/stat directory does not exist, target/2.10/assertTestsInOneFile/assertTestsInOneFile-graph.html will not be generated.") + +val assertTestsInOneFile211Dir = new File("target/2.11/assertTestsInOneFile") +val assertTestsInOneFile211StatDir = new File(assertTestsInOneFile211Dir, "stat") +if (assertTestsInOneFile211StatDir.exists) + generateChartFile(assertTestsInOneFile211StatDir, new File(assertTestsInOneFile211Dir, "assertTestsInOneFile-graph.html")) +else + println("target/2.11/assertTestsInOneFile/stat directory does not exist, target/2.11/assertTestsInOneFile/assertTestsInOneFile-graph.html will not be generated.") -val allClassTestsInOneFileDir = new File("allClassTestsInOneFile") -val allClassTestsInOneFileStatDir = new File(allClassTestsInOneFileDir, "stat") -if (allClassTestsInOneFileStatDir.exists) - generateChartFile(allClassTestsInOneFileStatDir, new File(allClassTestsInOneFileDir, "allClassTestsInOneFile-graph.html")) +val allClassTestsInOneFile210Dir = new File("target/2.10/allClassTestsInOneFile") +val allClassTestsInOneFile210StatDir = new File(allClassTestsInOneFile210Dir, "stat") +if (allClassTestsInOneFile210StatDir.exists) + generateChartFile(allClassTestsInOneFile210StatDir, new File(allClassTestsInOneFile210Dir, "allClassTestsInOneFile-graph.html")) +else + println("target/2.10/allClassTestsInOneFile/stat directory does not exist, target/2.10/allClassTestsInOneFile/allClassTestsInOneFile-graph.html will not be generated.") + +val allClassTestsInOneFile211Dir = new File("target/2.11/allClassTestsInOneFile") +val allClassTestsInOneFile211StatDir = new File(allClassTestsInOneFile211Dir, "stat") +if (allClassTestsInOneFile211StatDir.exists) + generateChartFile(allClassTestsInOneFile211StatDir, new File(allClassTestsInOneFile211Dir, "allClassTestsInOneFile-graph.html")) +else + println("target/2.11/allClassTestsInOneFile/stat directory does not exist, target/2.11/allClassTestsInOneFile/allClassTestsInOneFile-graph.html will not be generated.") + +val assertMacro210Dir = new File("target/2.10/assertMacro") +val assertMacro210StatDir = new File(assertMacro210Dir, "stat") +if (assertMacro210StatDir.exists) + generateChartFile(assertMacro210StatDir, new File(assertMacro210Dir, "assertMacro-graph.html")) +else + println("target/2.10/assertMacro/stat directory does not exist, target/2.10/assertMacro/assertMacro-graph.html will not be generated.") + +val assertMacro211Dir = new File("target/2.11/assertMacro") +val assertMacro211StatDir = new File(assertMacro211Dir, "stat") +if (assertMacro211StatDir.exists) + generateChartFile(assertMacro211StatDir, new File(assertMacro211Dir, "assertMacro-graph.html")) +else + println("target/2.11/assertMacro/stat directory does not exist, target/2.11/assertMacro/assertMacro-graph.html will not be generated.") + +val scalautilsScalaz210Dir = new File("target/2.10/scalautilsScalaz") +val scalautilsScalaz210StatDir = new File(scalautilsScalaz210Dir, "stat") +if (scalautilsScalaz210StatDir.exists) + generateChartFile(scalautilsScalaz210StatDir, new File(scalautilsScalaz210Dir, "scalautilsScalaz-graph.html")) else - println("allClassTestsInOneFile/stat directory does not exist, allClassTestsInOneFile/allClassTestsInOneFile-graph.html will not be generated.") + println("target/2.10/scalautilsScalaz/stat directory does not exist, target/2.10/scalautilsScalaz/scalautilsScalaz-graph.html will not be generated.") -val assertMacroDir = new File("assertMacro") -val assertMacroStatDir = new File(assertMacroDir, "stat") -if (assertMacroStatDir.exists) - generateChartFile(assertMacroStatDir, new File(assertMacroDir, "assertMacro-graph.html")) +val scalautilsScalaz211Dir = new File("target/2.11/scalautilsScalaz") +val scalautilsScalaz211StatDir = new File(scalautilsScalaz211Dir, "stat") +if (scalautilsScalaz211StatDir.exists) + generateChartFile(scalautilsScalaz211StatDir, new File(scalautilsScalaz211Dir, "scalautilsScalaz-graph.html")) else - println("assertMacro/stat directory does not exist, assertMacro/assertMacro-graph.html will not be generated.") + println("target/2.11/scalautilsScalaz/stat directory does not exist, target/2.11/scalautilsScalaz/scalautilsScalaz-graph.html will not be generated.") -val scalautilsScalazDir = new File("scalautilsScalaz") -val scalautilsScalazStatDir = new File(scalautilsScalazDir, "stat") -if (scalautilsScalazStatDir.exists) - generateChartFile(scalautilsScalazStatDir, new File(scalautilsScalazDir, "scalautilsScalaz-graph.html")) +val shapelessTables210Dir = new File("target/2.10/shapelessTables") +val shapelessTables210StatDir = new File(shapelessTables210Dir, "stat") +if (shapelessTables210StatDir.exists) + generateChartFile(shapelessTables210StatDir, new File(shapelessTables210Dir, "shapelessTables-graph.html")) else - println("scalautilsScalaz/stat directory does not exist, scalautilsScalaz/scalautilsScalaz-graph.html will not be generated.") + println("target/2.10/shapelessTables/stat directory does not exist, target/2.10/shapelessTables/shapelessTables-graph.html will not be generated.") -val shapelessTablesDir = new File("shapelessTables") -val shapelessTablesStatDir = new File(shapelessTablesDir, "stat") -if (shapelessTablesStatDir.exists) - generateChartFile(shapelessTablesStatDir, new File(shapelessTablesDir, "shapelessTables-graph.html")) +val shapelessTables211Dir = new File("target/2.11/shapelessTables") +val shapelessTables211StatDir = new File(shapelessTables211Dir, "stat") +if (shapelessTables211StatDir.exists) + generateChartFile(shapelessTables211StatDir, new File(shapelessTables211Dir, "shapelessTables-graph.html")) else - println("shapelessTables/stat directory does not exist, shapelessTables/shapelessTables-graph.html will not be generated.") + println("target/2.11/shapelessTables/stat directory does not exist, target/2.11/shapelessTables/shapelessTables-graph.html will not be generated.") diff --git a/runem.sh b/runem.sh index e15c1cd..e21fab7 100755 --- a/runem.sh +++ b/runem.sh @@ -1,15 +1,24 @@ set -x JAVA_OPTS="-server -Xmx1024M -Xms128M" export JAVA_OPTS -scala tenTestsPerFile.scala +$SCALA_210/bin/scala tenTestsPerFile.scala +$SCALA_211/bin/scala tenTestsPerFile.scala JAVA_OPTS="-server -Xmx2048M -Xms256M" export JAVA_OPTS -scala allTestsInOneFile.scala -scala testsIn100Files.scala -scala dataTables.scala -scala allMethodTestsInOneFile.scala -scala assertTestsInOneFile.scala -scala allClassTestsInOneFile.scala -scala scalautilsScalaz.scala -scala shapelessTables.scala -scala google-chart.scala +$SCALA_210/bin/scala allTestsInOneFile.scala +$SCALA_211/bin/scala allTestsInOneFile.scala +$SCALA_210/bin/scala testsIn100Files.scala +$SCALA_211/bin/scala testsIn100Files.scala +$SCALA_210/bin/scala dataTables.scala +$SCALA_211/bin/scala dataTables.scala +$SCALA_210/bin/scala allMethodTestsInOneFile.scala +$SCALA_211/bin/scala allMethodTestsInOneFile.scala +$SCALA_210/bin/scala assertTestsInOneFile.scala +$SCALA_211/bin/scala assertTestsInOneFile.scala +$SCALA_210/bin/scala allClassTestsInOneFile.scala +$SCALA_211/bin/scala allClassTestsInOneFile.scala +$SCALA_210/bin/scala scalautilsScalaz.scala +$SCALA_211/bin/scala scalautilsScalaz.scala +$SCALA_210/bin/scala shapelessTables.scala +$SCALA_211/bin/scala shapelessTables.scala +$SCALA_210/bin/scala google-chart.scala diff --git a/scalautilsScalaz.scala b/scalautilsScalaz.scala index c37c6c6..c2930b8 100644 --- a/scalautilsScalaz.scala +++ b/scalautilsScalaz.scala @@ -3,7 +3,18 @@ import java.io._ import java.nio.channels.Channels import scala.annotation.tailrec -def scalaVersion = "2.10" +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} val scalautilsVersion = "2.1.6" val scalazVersion = "7.0.6" @@ -47,7 +58,7 @@ def equalFun(x: Int): String = x + " + 1 === " + (x+1) def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -110,7 +121,7 @@ val scalazJar = new File("scalaz-core_" + scalaVersion + "-" + scalazVersion + " if (!scalazJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-core_" + scalaVersion + "/" + scalazVersion + "/scalaz-core_" + scalaVersion + "-" + scalazVersion + ".jar", scalazJar) -val baseDir = new File("scalautilsScalaz") +val baseDir = new File("target/" + scalaVersion + "/scalautilsScalaz") if (baseDir.exists) deleteDir(baseDir) diff --git a/shapelessTables.scala b/shapelessTables.scala index f81eb02..ac26158 100644 --- a/shapelessTables.scala +++ b/shapelessTables.scala @@ -3,8 +3,25 @@ import java.io._ import java.nio.channels.Channels import scala.annotation.tailrec -def scalaVersion = "2.10" -val scalaTestVersion = "2.0" +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} +val scalaTestVersion = "2.1.6" +val shapelessVersion = "2.0.0" +val shapelessScalaVersion = + if (scalaVersion == "2.11") + scalaVersion + else + scala.util.Properties.scalaPropOrElse("version.number", "unknown") def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) @@ -128,7 +145,7 @@ def generateShapelessSourceFile(testCount: Int, targetDir: File): File = { def compile(srcFile: String, classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir, srcFile) val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -208,11 +225,11 @@ val scalatestJar = new File("scalatest_" + scalaVersion + "-" + scalaTestVersion if (!scalatestJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestVersion + "/scalatest_" + scalaVersion + "-" + scalaTestVersion + ".jar", scalatestJar) -val shapelessJar = new File("shapeless_2.10.2-2.0.0.jar") +val shapelessJar = new File("shapeless_" + scalaVersion + "-" + shapelessVersion + ".jar") if (!shapelessJar.exists) - downloadFile("http://oss.sonatype.org/content/repositories/releases/com/chuusai/shapeless_2.10.2/2.0.0/shapeless_2.10.2-2.0.0.jar", shapelessJar) + downloadFile("http://oss.sonatype.org/content/repositories/releases/com/chuusai/shapeless_" + shapelessScalaVersion + "/" + shapelessVersion + "/shapeless_" + shapelessScalaVersion + "-" + shapelessVersion + ".jar", shapelessJar) -val baseDir = new File("shapelessTables") +val baseDir = new File("target/" + scalaVersion + "/shapelessTables") if (baseDir.exists) deleteDir(baseDir) diff --git a/tenTestsPerFile.scala b/tenTestsPerFile.scala index 6a160b4..d1be85b 100644 --- a/tenTestsPerFile.scala +++ b/tenTestsPerFile.scala @@ -4,16 +4,18 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/* -def scalaVersion = { +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt } -*/ -def scalaVersion = "2.10" val scalaTestVersion = "2.1.6" val specs2Version = "2.3.11" val scalazVersion = "7.0.6" @@ -212,7 +214,7 @@ def generateMultipleSpecs2Immutable(testCount: Int, maxTestCount: Int, targetDir def compile(srcFiles: List[String], classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir) ::: srcFiles + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir) ::: srcFiles val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -284,7 +286,7 @@ if (scalaVersion != "unknown") { if (!specs2ScalazJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-core_" + scalaVersion + "/" + scalazVersion + "/scalaz-core_" + scalaVersion + "-" + scalazVersion + ".jar", specs2ScalazJar) - val baseDir = new File("tenTestsPerFile") + val baseDir = new File("target/" + scalaVersion + "/tenTestsPerFile") if (baseDir.exists) deleteDir(baseDir) diff --git a/testsIn100Files.scala b/testsIn100Files.scala index a430fbd..42d5521 100644 --- a/testsIn100Files.scala +++ b/testsIn100Files.scala @@ -4,16 +4,18 @@ import java.nio.channels.Channels import scala.annotation.tailrec import scala.math.pow -/* -def scalaVersion = { +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") - if (rawVersion.endsWith(".final")) - rawVersion.substring(0, rawVersion.length - 6) - else - rawVersion + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt } -*/ -def scalaVersion = "2.10" val scalaTestVersion = "2.1.6" val specs2Version = "2.3.11" val scalazVersion = "7.0.6" @@ -181,7 +183,7 @@ def generateMultipleSpecs2Immutable(testCount: Int, targetDir: File): List[Strin def compile(srcFiles: List[String], classpath: String, targetDir: String) = { import scala.collection.JavaConversions._ - val command = List("scalac", "-classpath", classpath, "-d", targetDir) ::: srcFiles + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir) ::: srcFiles val builder = new ProcessBuilder(command) builder.redirectErrorStream(true) val start = System.currentTimeMillis @@ -253,7 +255,7 @@ if (scalaVersion != "unknown") { if (!specs2ScalazJar.exists) downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalaz/scalaz-core_" + scalaVersion + "/" + scalazVersion + "/scalaz-core_" + scalaVersion + "-" + scalazVersion + ".jar", specs2ScalazJar) - val baseDir = new File("testsIn100Files") + val baseDir = new File("target/" + scalaVersion + "/testsIn100Files") if (baseDir.exists) deleteDir(baseDir) From d917ec242dc5ccfb66553eddd75e1468223b8b23 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Wed, 11 Mar 2015 10:29:59 +0800 Subject: [PATCH 05/14] Added scalatest3.scala to benchmark compile time in scalatest 3.0. --- google-chart.scala | 7 + scalatest3.scala | 381 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 388 insertions(+) create mode 100644 scalatest3.scala diff --git a/google-chart.scala b/google-chart.scala index e87c233..0c68f88 100644 --- a/google-chart.scala +++ b/google-chart.scala @@ -274,3 +274,10 @@ if (shapelessTables211StatDir.exists) generateChartFile(shapelessTables211StatDir, new File(shapelessTables211Dir, "shapelessTables-graph.html")) else println("target/2.11/shapelessTables/stat directory does not exist, target/2.11/shapelessTables/shapelessTables-graph.html will not be generated.") + +val scalatest3211Dir = new File("target/2.11/scalatest3") +val scalatest3211StatDir = new File(scalatest3211Dir, "stat") +if (scalatest3211StatDir.exists) + generateChartFile(scalatest3211StatDir, new File(scalatest3211Dir, "scalatest3-graph.html")) +else + println("target/2.11/scalatest3/stat directory does not exist, target/2.11/scalatest3/scalatest3-graph.html will not be generated.") diff --git a/scalatest3.scala b/scalatest3.scala new file mode 100644 index 0000000..93bb971 --- /dev/null +++ b/scalatest3.scala @@ -0,0 +1,381 @@ +import java.net._ +import java.io._ +import java.nio.channels.Channels +import scala.annotation.tailrec +import scala.math.pow + +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} +val scalaTest2Version = "2.3.0-SNAP2" +val scalaTest3Version = "3.0.0-SNAP4" + +def downloadFile(urlString: String, targetFile: File) { + println("Downloading " + urlString) + val url = new URL(urlString) + val connection = url.openConnection + val in = connection.getInputStream + val out = new FileOutputStream(targetFile) + out getChannel() transferFrom(Channels.newChannel(in), 0, Long.MaxValue) + in.close() + out.flush() + out.close() +} + +val classFooter = """ + } +}""" + +def generateSourceFile(testCount: Int, targetDir: File, fileNumber: Int, packageName: String, importStatements: Array[String], + extendsName: String, withNames: Array[String], scopeBracket: Boolean, scopeDef: String, + testDefFun: (Int) => String, testBodyFun: (Int) => String): File = { + targetDir.mkdirs() + val targetFile = new File(targetDir, "ExampleSpec" + fileNumber + ".scala") + val targetOut = new BufferedWriter(new FileWriter(targetFile)) + try { + targetOut.write("package " + packageName + "\n\n") + importStatements.foreach { s => + targetOut.write("import " + s + "\n") + } + targetOut.write("\n") + targetOut.write("class ExampleSpec" + fileNumber + " extends " + extendsName + " " + withNames.map(n => " with " + n).mkString(" ") + " {\n") + targetOut.write(" " + scopeDef + (if (scopeBracket) "{" else "") + " \n") + for (x <- 1 to testCount) { + targetOut.write(" " + testDefFun(x) + " {\n") + targetOut.write(" " + testBodyFun(x) + "\n") + targetOut.write(" }\n") + } + targetOut.write(" " + (if (scopeBracket) "}" else "") + "\n") + targetOut.write("}\n") + } + finally { + targetOut.flush() + targetOut.close() + } + targetFile +} + +def generateMultipleSourceFiles(testCount: Int, maxTestCount:Int, targetDir: File, packageName: String, importStatements: Array[String], + extendsName: String, withNames: Array[String], scopeBracket: Boolean, scopeDef: String, + testDefFun: (Int) => String, testBodyFun: (Int) => String): List[String] = { + targetDir.mkdirs() + val totalFiles = testCount / maxTestCount + val remainder = testCount % maxTestCount + + val sourceFiles = + if (totalFiles == 0) + List(generateSourceFile(testCount, targetDir, 0, packageName, importStatements, + extendsName, withNames, scopeBracket, scopeDef, testDefFun, testBodyFun).getAbsolutePath) + else + for (fileNumber <- 1 to totalFiles) yield + generateSourceFile(maxTestCount, targetDir, fileNumber, packageName, importStatements, + extendsName, withNames, scopeBracket, scopeDef, testDefFun, testBodyFun).getAbsolutePath + + // For remainder + if (remainder > 0) + List(generateSourceFile(remainder, targetDir, totalFiles + 1, packageName, importStatements, + extendsName, withNames, scopeBracket, scopeDef, testDefFun, testBodyFun).getAbsolutePath) ++ sourceFiles + else + sourceFiles.toList +} + +// Using assert(==) +def assert2TestBodyFun(x: Int): String = "assert(" + x + " + 1 == " + (x+1) + ")" +// Using assert(===) +def assert3TestBodyFun(x: Int): String = "assert(" + x + " + 1 === " + (x+1) + ")" +// Using should matchers +def shouldTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + ")" + +// Spec +def specTestDefFun(x: Int): String = "def `increment " + x + "`" +// WordSpec +def wordSpecTestDefFun(x: Int): String = "\"increment " + x + "\" in" +//FunSuite +def funSuiteTestDefFun(x: Int): String = "test(\"increment " + x + "\")" +//FunSpec +def funSpecTestDefFun(x: Int): String = "it(\"increment " + x + "\")" +//FreeSpec +def freeSpecTestDefFun(x: Int): String = "\"increment " + x + "\" in" +//FlatSpec +def flatSpecTestDefFun(x: Int): String = "it should \"increment " + x + "\" in" + +def compile(srcFiles: List[String], classpath: String, targetDir: String) = { + import scala.collection.JavaConversions._ + + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir) ::: srcFiles + val builder = new ProcessBuilder(command) + builder.redirectErrorStream(true) + val start = System.currentTimeMillis + val process = builder.start() + + val stdout = new BufferedReader(new InputStreamReader(process.getInputStream)) + + var line = "Compiling " + srcFiles.mkString(", ") + "..." + + while (line != null) { + println (line) + line = stdout.readLine + } + + val end = System.currentTimeMillis + end - start +} + +def getFileAndByteCount(srcDir: File) = { + @tailrec + def getFileAndByteCountAcc(dirList: Array[File], fileCount: Long, byteCount: Long): Tuple2[Long, Long] = { + val (files, subDirs) = dirList.partition(_.isFile) + val classFiles = files.filter(f => f.getName.endsWith(".class")) + val newFileCount = fileCount + classFiles.size + val newByteCount = byteCount + classFiles.map { f => f.length.toLong }.foldLeft(0l) { (a, b) => a + b } + if (subDirs.isEmpty) + (newFileCount, newByteCount) + else + getFileAndByteCountAcc(subDirs.flatMap(d => d.listFiles), newFileCount, newByteCount) + } + getFileAndByteCountAcc(srcDir.listFiles, 0l, 0l) +} + +def deleteDir(targetDir: File) { + val children = targetDir.listFiles + if (children != null) { + targetDir.listFiles.foreach { child => + if (child.isFile) + child.delete() + else + deleteDir(child) + } + targetDir.delete() + } + else + println("Unable to list files in " + targetDir.getAbsolutePath) +} + +def getOutputDir(baseOutputDir: File, testCount: Int): File = { + val outputDirName = "output-" + testCount + val outputDir = new File(baseOutputDir, outputDirName) + outputDir.mkdirs() + outputDir +} + +case class Style(name: String, className: String, scopeBracket: Boolean, scopeDef: String, testDefFun: (Int) => String) +case class TestType(name: String, shortName: String, importNames: Array[String], mixinNames: Array[String], testBodyFun: (Int) => String) + +if (scalaVersion != "unknown") { + val scalatest2Jar = new File("scalatest_" + scalaVersion + "-" + scalaTest2Version + ".jar") + if (!scalatest2Jar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTest2Version + "/scalatest_" + scalaVersion + "-" + scalaTest2Version + ".jar", scalatest2Jar) + + val scalatest3Jar = new File("scalatest_" + scalaVersion + "-" + scalaTest3Version + ".jar") + if (!scalatest3Jar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTest3Version + "/scalatest_" + scalaVersion + "-" + scalaTest3Version + ".jar", scalatest3Jar) + + val baseDir = new File("target/" + scalaVersion + "/scalatest3") + if (baseDir.exists) + deleteDir(baseDir) + + val statDir = new File(baseDir, "stat") + statDir.mkdirs() + + val durationFile = new FileWriter(new File(statDir, "duration.csv")) + val fileCountFile = new FileWriter(new File(statDir, "filecount.csv")) + val fileSizeFile = new FileWriter(new File(statDir, "filesize.csv")) + + val scalaTest2Classpath = scalatest2Jar.getName + val scalaTest3Classpath = scalatest3Jar.getName + + val baseOutputDir = new File(baseDir, "output") + baseOutputDir.mkdirs() + + val baseGeneratedDir = new File(baseDir, "generated") + baseGeneratedDir.mkdirs() + + val scalatest2Styles = + Array( + Style("scalatest2.WordSpec", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + ) + + val scalatest2TestTypes = + Array( + TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun) + //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) + + /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun), + TestType("withTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TripleEquals"), Array("TripleEquals"), shouldTestBodyFun), + TestType("withTypeCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals"), Array("TypeCheckedTripleEquals"), shouldTestBodyFun), + TestType("withConversionCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.ConversionCheckedTripleEquals"), Array("ConversionCheckedTripleEquals"), shouldTestBodyFun)*/ + ) + + val scalatest3Styles = + Array( + Style("scalatest3.WordSpec", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + ) + + val scalatest3TestTypes = + Array( + TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun) + //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) + + /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun), + TestType("withUncheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.UncheckedEquality"), Array("UncheckedEquality"), shouldTestBodyFun), + TestType("withCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality"), Array("CheckedEquality"), shouldTestBodyFun), + TestType("withStrictCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality"), Array("StrictCheckedEquality"), shouldTestBodyFun), + TestType("withEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.EnabledEquality"), Array("EnabledEquality"), shouldTestBodyFun), + TestType("withStrictEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictEnabledEquality"), Array("StrictEnabledEquality"), shouldTestBodyFun)*/ + ) + + val testCounts = + Array( + 0, + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 1000 + ) + + val headers = "TestCount," + testCounts.mkString(",") + "\n" + durationFile.write(headers) + fileCountFile.write(headers) + fileSizeFile.write(headers) + + scalatest2Styles.foreach { style => + scalatest2TestTypes.foreach { testType => + try { + durationFile.write(style.name) // Don't write with MustMatchers to get all 4 names to fit on graph + durationFile.flush() + fileCountFile.write(style.name) + fileCountFile.flush() + fileSizeFile.write(style.name) + fileSizeFile.flush() + testCounts.foreach { testCount => + println("Working on " + style.className +" " + testType.name + " test count " + testCount + "...") + val outputDir = getOutputDir(baseOutputDir, testCount) + val generatedDir = new File(baseGeneratedDir, "generated-" + testCount) + + val generatedSrc = generateMultipleSourceFiles( + testCount, + 10, // maximum number of tests in a file + new File(generatedDir, "ScalaTest2" + style.className), // target dir + style.className + testType.shortName + "2", // package name + testType.importNames, // imports + style.className, // extends + testType.mixinNames, // mixin + style.scopeBracket, // scope requires bracket or not + style.scopeDef, // scope definition + style.testDefFun, + testType.testBodyFun) + + + val duration = compile(generatedSrc, scalaTest2Classpath, outputDir.getAbsolutePath) + durationFile.write("," + duration) + durationFile.flush() + + val (fileCount, fileSize) = getFileAndByteCount(new File(outputDir, style.className + testType.shortName + "2")) + fileCountFile.write("," + fileCount) + fileCountFile.flush() + fileSizeFile.write("," + fileSize) + fileSizeFile.flush() + } + } + catch { + case e: Throwable => + e.printStackTrace() + } + finally { + durationFile.write("\n") + durationFile.flush() + fileCountFile.write("\n") + fileCountFile.flush() + fileSizeFile.write("\n") + fileSizeFile.flush() + } + } + } + + scalatest3Styles.foreach { style => + scalatest3TestTypes.foreach { testType => + try { + durationFile.write(style.name) // Don't write with MustMatchers to get all 4 names to fit on graph + durationFile.flush() + fileCountFile.write(style.name) + fileCountFile.flush() + fileSizeFile.write(style.name) + fileSizeFile.flush() + testCounts.foreach { testCount => + println("Working on " + style.className +" " + testType.name + " test count " + testCount + "...") + val outputDir = getOutputDir(baseOutputDir, testCount) + val generatedDir = new File(baseGeneratedDir, "generated-" + testCount) + + val generatedSrc = generateMultipleSourceFiles( + testCount, + 10, // maximum number of tests in a file + new File(generatedDir, "ScalaTest3" + style.className), // target dir + style.className + testType.shortName + "3", // package name + testType.importNames, // imports + style.className, // extends + testType.mixinNames, // mixin + style.scopeBracket, // scope requires bracket or not + style.scopeDef, // scope definition + style.testDefFun, + testType.testBodyFun) + + + val duration = compile(generatedSrc, scalaTest3Classpath, outputDir.getAbsolutePath) + durationFile.write("," + duration) + durationFile.flush() + + val (fileCount, fileSize) = getFileAndByteCount(new File(outputDir, style.className + testType.shortName + "3")) + fileCountFile.write("," + fileCount) + fileCountFile.flush() + fileSizeFile.write("," + fileSize) + fileSizeFile.flush() + } + } + catch { + case e: Throwable => + e.printStackTrace() + } + finally { + durationFile.write("\n") + durationFile.flush() + fileCountFile.write("\n") + fileCountFile.flush() + fileSizeFile.write("\n") + fileSizeFile.flush() + } + } + } + + durationFile.flush() + durationFile.close() + fileCountFile.flush() + fileCountFile.close() + fileSizeFile.flush() + fileSizeFile.close() +} +else + println("ERROR: Unable to detect Scala version.") From ce9cf65fe8394eaa45531f13cfe447158e1b763c Mon Sep 17 00:00:00 2001 From: cheeseng Date: Wed, 11 Mar 2015 10:53:29 +0800 Subject: [PATCH 06/14] Renamed style name to scalatest2Equal and scalatest3Equal. --- scalatest3.scala | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index 93bb971..c797488 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -93,7 +93,7 @@ def assert2TestBodyFun(x: Int): String = "assert(" + x + " + 1 == " + (x+1) + ") // Using assert(===) def assert3TestBodyFun(x: Int): String = "assert(" + x + " + 1 === " + (x+1) + ")" // Using should matchers -def shouldTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + ")" +def shouldEqualTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + ")" // Spec def specTestDefFun(x: Int): String = "def `increment " + x + "`" @@ -201,36 +201,36 @@ if (scalaVersion != "unknown") { val scalatest2Styles = Array( - Style("scalatest2.WordSpec", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + Style("scalatest2Equal", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) ) val scalatest2TestTypes = Array( - TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun) + TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) - /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun), - TestType("withTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TripleEquals"), Array("TripleEquals"), shouldTestBodyFun), - TestType("withTypeCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals"), Array("TypeCheckedTripleEquals"), shouldTestBodyFun), - TestType("withConversionCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.ConversionCheckedTripleEquals"), Array("ConversionCheckedTripleEquals"), shouldTestBodyFun)*/ + /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("withTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TripleEquals"), Array("TripleEquals"), shouldEqualTestBodyFun), + TestType("withTypeCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals"), Array("TypeCheckedTripleEquals"), shouldEqualTestBodyFun), + TestType("withConversionCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.ConversionCheckedTripleEquals"), Array("ConversionCheckedTripleEquals"), shouldEqualTestBodyFun)*/ ) val scalatest3Styles = Array( - Style("scalatest3.WordSpec", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + Style("scalatest3Equal", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) ) val scalatest3TestTypes = Array( - TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun) + TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) - /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldTestBodyFun), - TestType("withUncheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.UncheckedEquality"), Array("UncheckedEquality"), shouldTestBodyFun), - TestType("withCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality"), Array("CheckedEquality"), shouldTestBodyFun), - TestType("withStrictCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality"), Array("StrictCheckedEquality"), shouldTestBodyFun), - TestType("withEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.EnabledEquality"), Array("EnabledEquality"), shouldTestBodyFun), - TestType("withStrictEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictEnabledEquality"), Array("StrictEnabledEquality"), shouldTestBodyFun)*/ + /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("withUncheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.UncheckedEquality"), Array("UncheckedEquality"), shouldEqualTestBodyFun), + TestType("withCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality"), Array("CheckedEquality"), shouldEqualTestBodyFun), + TestType("withStrictCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality"), Array("StrictCheckedEquality"), shouldEqualTestBodyFun), + TestType("withEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.EnabledEquality"), Array("EnabledEquality"), shouldEqualTestBodyFun), + TestType("withStrictEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictEnabledEquality"), Array("StrictEnabledEquality"), shouldEqualTestBodyFun)*/ ) val testCounts = From a29114b0a2a2ea1574bce61f8946558418605ca4 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Wed, 11 Mar 2015 11:30:33 +0800 Subject: [PATCH 07/14] Added 'be' to scalatest3.scala. --- scalatest3.scala | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index c797488..647de13 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -92,8 +92,10 @@ def generateMultipleSourceFiles(testCount: Int, maxTestCount:Int, targetDir: Fil def assert2TestBodyFun(x: Int): String = "assert(" + x + " + 1 == " + (x+1) + ")" // Using assert(===) def assert3TestBodyFun(x: Int): String = "assert(" + x + " + 1 === " + (x+1) + ")" -// Using should matchers +// Using should equal matchers def shouldEqualTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + ")" +// Using should be matchers +def shouldBeTestBodyFun(x: Int): String = x + " + 1 should be (" + (x+1) + ")" // Spec def specTestDefFun(x: Int): String = "def `increment " + x + "`" @@ -201,12 +203,13 @@ if (scalaVersion != "unknown") { val scalatest2Styles = Array( - Style("scalatest2Equal", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + Style("scalatest2", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) ) val scalatest2TestTypes = Array( - TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun) //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), @@ -217,12 +220,13 @@ if (scalaVersion != "unknown") { val scalatest3Styles = Array( - Style("scalatest3Equal", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + Style("scalatest3", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) ) val scalatest3TestTypes = Array( - TestType("with Matchers", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), @@ -265,11 +269,11 @@ if (scalaVersion != "unknown") { scalatest2Styles.foreach { style => scalatest2TestTypes.foreach { testType => try { - durationFile.write(style.name) // Don't write with MustMatchers to get all 4 names to fit on graph + durationFile.write(style.name + "-" + testType.shortName) // Don't write with MustMatchers to get all 4 names to fit on graph durationFile.flush() - fileCountFile.write(style.name) + fileCountFile.write(style.name + "-" + testType.shortName) fileCountFile.flush() - fileSizeFile.write(style.name) + fileSizeFile.write(style.name + "-" + testType.shortName) fileSizeFile.flush() testCounts.foreach { testCount => println("Working on " + style.className +" " + testType.name + " test count " + testCount + "...") @@ -319,11 +323,11 @@ if (scalaVersion != "unknown") { scalatest3Styles.foreach { style => scalatest3TestTypes.foreach { testType => try { - durationFile.write(style.name) // Don't write with MustMatchers to get all 4 names to fit on graph + durationFile.write(style.name + "-" + testType.shortName) // Don't write with MustMatchers to get all 4 names to fit on graph durationFile.flush() - fileCountFile.write(style.name) + fileCountFile.write(style.name + "-" + testType.shortName) fileCountFile.flush() - fileSizeFile.write(style.name) + fileSizeFile.write(style.name + "-" + testType.shortName) fileSizeFile.flush() testCounts.foreach { testCount => println("Working on " + style.className +" " + testType.name + " test count " + testCount + "...") From 0e7953c6bc3014aa342588b0e52aee598fdf6806 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Wed, 11 Mar 2015 11:56:41 +0800 Subject: [PATCH 08/14] Added test style for 'should contain'. --- scalatest3.scala | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index 647de13..6f3002f 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -96,6 +96,8 @@ def assert3TestBodyFun(x: Int): String = "assert(" + x + " + 1 === " + (x+1) + " def shouldEqualTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + ")" // Using should be matchers def shouldBeTestBodyFun(x: Int): String = x + " + 1 should be (" + (x+1) + ")" +// Using should be matchers +def shouldContainTestBodyFun(x: Int): String = "List(" + x + " + 1) should contain (" + (x+1) + ")" // Spec def specTestDefFun(x: Int): String = "def `increment " + x + "`" @@ -209,13 +211,8 @@ if (scalaVersion != "unknown") { val scalatest2TestTypes = Array( TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), - TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun) - //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) - - /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), - TestType("withTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TripleEquals"), Array("TripleEquals"), shouldEqualTestBodyFun), - TestType("withTypeCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals"), Array("TypeCheckedTripleEquals"), shouldEqualTestBodyFun), - TestType("withConversionCheckedTripleEquals", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.ConversionCheckedTripleEquals"), Array("ConversionCheckedTripleEquals"), shouldEqualTestBodyFun)*/ + TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun) ) val scalatest3Styles = @@ -226,15 +223,8 @@ if (scalaVersion != "unknown") { val scalatest3TestTypes = Array( TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), - TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) - //TestType("assert ===", "Assert3", Array("org.scalatest._"), Array.empty, assert3TestBodyFun) - - /*TestType("Default", "Matchers", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), - TestType("withUncheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.UncheckedEquality"), Array("UncheckedEquality"), shouldEqualTestBodyFun), - TestType("withCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality"), Array("CheckedEquality"), shouldEqualTestBodyFun), - TestType("withStrictCheckedEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality"), Array("StrictCheckedEquality"), shouldEqualTestBodyFun), - TestType("withEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.EnabledEquality"), Array("EnabledEquality"), shouldEqualTestBodyFun), - TestType("withStrictEnabledEquality", "Matchers", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictEnabledEquality"), Array("StrictEnabledEquality"), shouldEqualTestBodyFun)*/ + TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun) ) val testCounts = From af76ddc695c3abd53abb988b980c83b667a45985 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Wed, 11 Mar 2015 13:42:22 +0800 Subject: [PATCH 09/14] Changed to use scalatest-all as artifact name for scalatest jar, and bump up SNAP release number. --- scalatest3.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index 6f3002f..99c7019 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -16,8 +16,8 @@ val scalaVersion = { val versionParts = rawVersion.split("\\.") versionParts(0).toInt + "." + versionParts(1).toInt } -val scalaTest2Version = "2.3.0-SNAP2" -val scalaTest3Version = "3.0.0-SNAP4" +val scalaTest2Version = "2.3.0-SNAP3" +val scalaTest3Version = "3.0.0-SNAP5" def downloadFile(urlString: String, targetFile: File) { println("Downloading " + urlString) @@ -175,13 +175,13 @@ case class Style(name: String, className: String, scopeBracket: Boolean, scopeDe case class TestType(name: String, shortName: String, importNames: Array[String], mixinNames: Array[String], testBodyFun: (Int) => String) if (scalaVersion != "unknown") { - val scalatest2Jar = new File("scalatest_" + scalaVersion + "-" + scalaTest2Version + ".jar") + val scalatest2Jar = new File("scalatest-all_" + scalaVersion + "-" + scalaTest2Version + ".jar") if (!scalatest2Jar.exists) - downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTest2Version + "/scalatest_" + scalaVersion + "-" + scalaTest2Version + ".jar", scalatest2Jar) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest-all_" + scalaVersion + "/" + scalaTest2Version + "/scalatest-all_" + scalaVersion + "-" + scalaTest2Version + ".jar", scalatest2Jar) - val scalatest3Jar = new File("scalatest_" + scalaVersion + "-" + scalaTest3Version + ".jar") + val scalatest3Jar = new File("scalatest-all_" + scalaVersion + "-" + scalaTest3Version + ".jar") if (!scalatest3Jar.exists) - downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTest3Version + "/scalatest_" + scalaVersion + "-" + scalaTest3Version + ".jar", scalatest3Jar) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest-all_" + scalaVersion + "/" + scalaTest3Version + "/scalatest-all_" + scalaVersion + "-" + scalaTest3Version + ".jar", scalatest3Jar) val baseDir = new File("target/" + scalaVersion + "/scalatest3") if (baseDir.exists) From 3660284ef0ed3536760c720ad90d85c24627f8e0 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Wed, 11 Mar 2015 22:08:49 +0800 Subject: [PATCH 10/14] Added more test types to scalatest3.scala. --- scalatest3.scala | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index 99c7019..d8f5479 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -98,6 +98,12 @@ def shouldEqualTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + def shouldBeTestBodyFun(x: Int): String = x + " + 1 should be (" + (x+1) + ")" // Using should be matchers def shouldContainTestBodyFun(x: Int): String = "List(" + x + " + 1) should contain (" + (x+1) + ")" +// Using should equal matchers with logical and +def shouldLogicalAndEqualTestBodyFun(x: Int): String = x + " + 1 should (not equal " + x + " and not equal " + (x-1) + ")" +// Using should be matchers with logical and +def shouldLogicalAndBeTestBodyFun(x: Int): String = x + " + 1 should (not be " + x + " and not be " + (x-1) + ")" +// Using should contain matchers with logical and +def shouldLogicalAndContainTestBodyFun(x: Int): String = "List(" + x + " + 1) should (not contain " + x + " and not contain " + (x-1) + ")" // Spec def specTestDefFun(x: Int): String = "def `increment " + x + "`" @@ -211,8 +217,17 @@ if (scalaVersion != "unknown") { val scalatest2TestTypes = Array( TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndEqualTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun) + TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldBeTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndBeTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndBeTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndContainTestBodyFun) ) val scalatest3Styles = @@ -223,8 +238,17 @@ if (scalaVersion != "unknown") { val scalatest3TestTypes = Array( TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndEqualTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun) + TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldBeTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndBeTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndBeTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndContainTestBodyFun) ) val testCounts = From 7c74dc0c9bc4bb22bbd360b31ede6926caff248c Mon Sep 17 00:00:00 2001 From: cheeseng Date: Thu, 12 Mar 2015 15:55:44 +0800 Subject: [PATCH 11/14] Added StrictCheckedEquality flavor to scalatest3.scala. --- scalatest3.scala | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index d8f5479..b2fafb9 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -214,9 +214,9 @@ if (scalaVersion != "unknown") { Style("scalatest2", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) ) - val scalatest2TestTypes = + val scalatest2TestTypes: Array[TestType] = Array( - TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + /*TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndEqualTestBodyFun), @@ -227,7 +227,7 @@ if (scalaVersion != "unknown") { TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldContainTestBodyFun), TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndContainTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndContainTestBodyFun) + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndContainTestBodyFun) */ ) val scalatest3Styles = @@ -235,20 +235,23 @@ if (scalaVersion != "unknown") { Style("scalatest3", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) ) - val scalatest3TestTypes = + val scalatest3TestTypes: Array[TestType] = Array( - TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + /*TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndEqualTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldBeTestBodyFun), + TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldBeTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndBeTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndBeTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), */ TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldContainTestBodyFun), + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldContainTestBodyFun)/*, TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndContainTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndContainTestBodyFun) + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndContainTestBodyFun)*/ ) val testCounts = From e851ac545aa303a52a9033953e66b160c0a75bf0 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Thu, 12 Mar 2015 22:18:24 +0800 Subject: [PATCH 12/14] Uncomment test types in scalatest3.scala. --- scalatest3.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scalatest3.scala b/scalatest3.scala index b2fafb9..47fada8 100644 --- a/scalatest3.scala +++ b/scalatest3.scala @@ -216,7 +216,7 @@ if (scalaVersion != "unknown") { val scalatest2TestTypes: Array[TestType] = Array( - /*TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndEqualTestBodyFun), @@ -227,7 +227,7 @@ if (scalaVersion != "unknown") { TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldContainTestBodyFun), TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndContainTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndContainTestBodyFun) */ + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.TypeCheckedTripleEquals._"), Array.empty, shouldLogicalAndContainTestBodyFun) ) val scalatest3Styles = @@ -237,7 +237,7 @@ if (scalaVersion != "unknown") { val scalatest3TestTypes: Array[TestType] = Array( - /*TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldEqualTestBodyFun), TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndEqualTestBodyFun), @@ -247,11 +247,11 @@ if (scalaVersion != "unknown") { TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldBeTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndBeTestBodyFun), TestType("be", "be", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndBeTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), */ + TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldContainTestBodyFun), TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldContainTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldContainTestBodyFun)/*, + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.StrictCheckedEquality._"), Array.empty, shouldContainTestBodyFun), TestType("contain", "contain", Array("org.scalatest._", "Matchers._"), Array.empty, shouldLogicalAndContainTestBodyFun), - TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndContainTestBodyFun)*/ + TestType("contain", "contain", Array("org.scalatest._", "Matchers._", "org.scalactic.CheckedEquality._"), Array.empty, shouldLogicalAndContainTestBodyFun) ) val testCounts = From 76ea12db46d431a1836792ca4d0336231ad7fe97 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Thu, 12 Mar 2015 22:52:01 +0800 Subject: [PATCH 13/14] Added supersafe.scala. --- google-chart.scala | 7 + supersafe.scala | 399 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 406 insertions(+) create mode 100644 supersafe.scala diff --git a/google-chart.scala b/google-chart.scala index 0c68f88..dc60c74 100644 --- a/google-chart.scala +++ b/google-chart.scala @@ -281,3 +281,10 @@ if (scalatest3211StatDir.exists) generateChartFile(scalatest3211StatDir, new File(scalatest3211Dir, "scalatest3-graph.html")) else println("target/2.11/scalatest3/stat directory does not exist, target/2.11/scalatest3/scalatest3-graph.html will not be generated.") + +val supersafe211Dir = new File("target/2.11/supersafe") +val supersafe211StatDir = new File(supersafe211Dir, "stat") +if (supersafe211StatDir.exists) + generateChartFile(supersafe211StatDir, new File(supersafe211Dir, "supersafe-graph.html")) +else + println("target/2.11/supersafe/stat directory does not exist, target/2.11/supersafe/supersafe-graph.html will not be generated.") diff --git a/supersafe.scala b/supersafe.scala new file mode 100644 index 0000000..eeaac93 --- /dev/null +++ b/supersafe.scala @@ -0,0 +1,399 @@ +import java.net._ +import java.io._ +import java.nio.channels.Channels +import scala.annotation.tailrec +import scala.math.pow + +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} +val scalaTest2Version = "2.3.0-SNAP3" +val scalaTest3Version = "3.0.0-SNAP5" + +def downloadFile(urlString: String, targetFile: File) { + println("Downloading " + urlString) + val url = new URL(urlString) + val connection = url.openConnection + val in = connection.getInputStream + val out = new FileOutputStream(targetFile) + out getChannel() transferFrom(Channels.newChannel(in), 0, Long.MaxValue) + in.close() + out.flush() + out.close() +} + +val classFooter = """ + } +}""" + +def generateSourceFile(testCount: Int, targetDir: File, fileNumber: Int, packageName: String, importStatements: Array[String], + extendsName: String, withNames: Array[String], scopeBracket: Boolean, scopeDef: String, + testDefFun: (Int) => String, testBodyFun: (Int) => String): File = { + targetDir.mkdirs() + val targetFile = new File(targetDir, "ExampleSpec" + fileNumber + ".scala") + val targetOut = new BufferedWriter(new FileWriter(targetFile)) + try { + targetOut.write("package " + packageName + "\n\n") + importStatements.foreach { s => + targetOut.write("import " + s + "\n") + } + targetOut.write("\n") + targetOut.write("class ExampleSpec" + fileNumber + " extends " + extendsName + " " + withNames.map(n => " with " + n).mkString(" ") + " {\n") + targetOut.write(" " + scopeDef + (if (scopeBracket) "{" else "") + " \n") + for (x <- 1 to testCount) { + targetOut.write(" " + testDefFun(x) + " {\n") + targetOut.write(" " + testBodyFun(x) + "\n") + targetOut.write(" }\n") + } + targetOut.write(" " + (if (scopeBracket) "}" else "") + "\n") + targetOut.write("}\n") + } + finally { + targetOut.flush() + targetOut.close() + } + targetFile +} + +def generateMultipleSourceFiles(testCount: Int, maxTestCount:Int, targetDir: File, packageName: String, importStatements: Array[String], + extendsName: String, withNames: Array[String], scopeBracket: Boolean, scopeDef: String, + testDefFun: (Int) => String, testBodyFun: (Int) => String): List[String] = { + targetDir.mkdirs() + val totalFiles = testCount / maxTestCount + val remainder = testCount % maxTestCount + + val sourceFiles = + if (totalFiles == 0) + List(generateSourceFile(testCount, targetDir, 0, packageName, importStatements, + extendsName, withNames, scopeBracket, scopeDef, testDefFun, testBodyFun).getAbsolutePath) + else + for (fileNumber <- 1 to totalFiles) yield + generateSourceFile(maxTestCount, targetDir, fileNumber, packageName, importStatements, + extendsName, withNames, scopeBracket, scopeDef, testDefFun, testBodyFun).getAbsolutePath + + // For remainder + if (remainder > 0) + List(generateSourceFile(remainder, targetDir, totalFiles + 1, packageName, importStatements, + extendsName, withNames, scopeBracket, scopeDef, testDefFun, testBodyFun).getAbsolutePath) ++ sourceFiles + else + sourceFiles.toList +} + +// Using assert(==) +def assert2TestBodyFun(x: Int): String = "assert(" + x + " + 1 == " + (x+1) + ")" +// Using assert(===) +def assert3TestBodyFun(x: Int): String = "assert(" + x + " + 1 === " + (x+1) + ")" +// Using should equal matchers +def shouldEqualTestBodyFun(x: Int): String = x + " + 1 should equal (" + (x+1) + ")" +// Using should be matchers +def shouldBeTestBodyFun(x: Int): String = x + " + 1 should be (" + (x+1) + ")" +// Using should be matchers +def shouldContainTestBodyFun(x: Int): String = "List(" + x + " + 1) should contain (" + (x+1) + ")" +// Using should equal matchers with logical and +def shouldLogicalAndEqualTestBodyFun(x: Int): String = x + " + 1 should (not equal " + x + " and not equal " + (x-1) + ")" +// Using should be matchers with logical and +def shouldLogicalAndBeTestBodyFun(x: Int): String = x + " + 1 should (not be " + x + " and not be " + (x-1) + ")" +// Using should contain matchers with logical and +def shouldLogicalAndContainTestBodyFun(x: Int): String = "List(" + x + " + 1) should (not contain " + x + " and not contain " + (x-1) + ")" + +// Spec +def specTestDefFun(x: Int): String = "def `increment " + x + "`" +// WordSpec +def wordSpecTestDefFun(x: Int): String = "\"increment " + x + "\" in" +//FunSuite +def funSuiteTestDefFun(x: Int): String = "test(\"increment " + x + "\")" +//FunSpec +def funSpecTestDefFun(x: Int): String = "it(\"increment " + x + "\")" +//FreeSpec +def freeSpecTestDefFun(x: Int): String = "\"increment " + x + "\" in" +//FlatSpec +def flatSpecTestDefFun(x: Int): String = "it should \"increment " + x + "\" in" + +def compile(srcFiles: List[String], classpath: String, targetDir: String) = { + import scala.collection.JavaConversions._ + + val command = List(scalaHome + "/bin/scalac", "-classpath", classpath, "-d", targetDir) ::: srcFiles + val builder = new ProcessBuilder(command) + builder.redirectErrorStream(true) + val start = System.currentTimeMillis + val process = builder.start() + + val stdout = new BufferedReader(new InputStreamReader(process.getInputStream)) + + var line = "Compiling " + srcFiles.mkString(", ") + "..." + + while (line != null) { + println (line) + line = stdout.readLine + } + + val end = System.currentTimeMillis + end - start +} + +def compileWithSuperSafe(srcFiles: List[String], classpath: String, targetDir: String) = { + import scala.collection.JavaConversions._ + + val command = List(scalaHome + "/bin/scalac", "-Xplugin:supersafe_2.11-1.1.0-SNAPSHOT.jar", "-classpath", classpath, "-d", targetDir) ::: srcFiles + val builder = new ProcessBuilder(command) + builder.redirectErrorStream(true) + val start = System.currentTimeMillis + val process = builder.start() + + val stdout = new BufferedReader(new InputStreamReader(process.getInputStream)) + + var line = "Compiling " + srcFiles.mkString(", ") + "..." + + while (line != null) { + println (line) + line = stdout.readLine + } + + val end = System.currentTimeMillis + end - start +} + +def getFileAndByteCount(srcDir: File) = { + @tailrec + def getFileAndByteCountAcc(dirList: Array[File], fileCount: Long, byteCount: Long): Tuple2[Long, Long] = { + val (files, subDirs) = dirList.partition(_.isFile) + val classFiles = files.filter(f => f.getName.endsWith(".class")) + val newFileCount = fileCount + classFiles.size + val newByteCount = byteCount + classFiles.map { f => f.length.toLong }.foldLeft(0l) { (a, b) => a + b } + if (subDirs.isEmpty) + (newFileCount, newByteCount) + else + getFileAndByteCountAcc(subDirs.flatMap(d => d.listFiles), newFileCount, newByteCount) + } + getFileAndByteCountAcc(srcDir.listFiles, 0l, 0l) +} + +def deleteDir(targetDir: File) { + val children = targetDir.listFiles + if (children != null) { + targetDir.listFiles.foreach { child => + if (child.isFile) + child.delete() + else + deleteDir(child) + } + targetDir.delete() + } + else + println("Unable to list files in " + targetDir.getAbsolutePath) +} + +def getOutputDir(baseOutputDir: File, testCount: Int): File = { + val outputDirName = "output-" + testCount + val outputDir = new File(baseOutputDir, outputDirName) + outputDir.mkdirs() + outputDir +} + +case class Style(name: String, className: String, scopeBracket: Boolean, scopeDef: String, testDefFun: (Int) => String) +case class TestType(name: String, shortName: String, importNames: Array[String], mixinNames: Array[String], testBodyFun: (Int) => String) + +if (scalaVersion != "unknown") { + val scalatest2Jar = new File("scalatest-all_" + scalaVersion + "-" + scalaTest2Version + ".jar") + if (!scalatest2Jar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest-all_" + scalaVersion + "/" + scalaTest2Version + "/scalatest-all_" + scalaVersion + "-" + scalaTest2Version + ".jar", scalatest2Jar) + + val scalatest3Jar = new File("scalatest-all_" + scalaVersion + "-" + scalaTest3Version + ".jar") + if (!scalatest3Jar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest-all_" + scalaVersion + "/" + scalaTest3Version + "/scalatest-all_" + scalaVersion + "-" + scalaTest3Version + ".jar", scalatest3Jar) + + val baseDir = new File("target/" + scalaVersion + "/supersafe") + if (baseDir.exists) + deleteDir(baseDir) + + val statDir = new File(baseDir, "stat") + statDir.mkdirs() + + val durationFile = new FileWriter(new File(statDir, "duration.csv")) + val fileCountFile = new FileWriter(new File(statDir, "filecount.csv")) + val fileSizeFile = new FileWriter(new File(statDir, "filesize.csv")) + + val scalaTest2Classpath = scalatest2Jar.getName + val scalaTest3Classpath = scalatest3Jar.getName + + val baseOutputDir = new File(baseDir, "output") + baseOutputDir.mkdirs() + + val baseGeneratedDir = new File(baseDir, "generated") + baseGeneratedDir.mkdirs() + + val scalatest2Styles = + Array( + Style("scalatest2", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + ) + + val scalatest2TestTypes: Array[TestType] = + Array( + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) + ) + + val supersafeStyles = + Array( + Style("supersafe", "WordSpec", true, "\"Scala\" can ", wordSpecTestDefFun) + ) + + val supersafeTestTypes: Array[TestType] = + Array( + TestType("equal", "equals", Array("org.scalatest._", "Matchers._"), Array.empty, shouldEqualTestBodyFun) + ) + + val testCounts = + Array( + 0, + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 1000 + ) + + val headers = "TestCount," + testCounts.mkString(",") + "\n" + durationFile.write(headers) + fileCountFile.write(headers) + fileSizeFile.write(headers) + + scalatest2Styles.foreach { style => + scalatest2TestTypes.foreach { testType => + try { + durationFile.write(style.name + "-" + testType.shortName) // Don't write with MustMatchers to get all 4 names to fit on graph + durationFile.flush() + fileCountFile.write(style.name + "-" + testType.shortName) + fileCountFile.flush() + fileSizeFile.write(style.name + "-" + testType.shortName) + fileSizeFile.flush() + testCounts.foreach { testCount => + println("Working on " + style.className +" " + testType.name + " test count " + testCount + "...") + val outputDir = getOutputDir(baseOutputDir, testCount) + val generatedDir = new File(baseGeneratedDir, "generated-" + testCount) + + val generatedSrc = generateMultipleSourceFiles( + testCount, + 10, // maximum number of tests in a file + new File(generatedDir, "ScalaTest2" + style.className), // target dir + style.className + testType.shortName + "2", // package name + testType.importNames, // imports + style.className, // extends + testType.mixinNames, // mixin + style.scopeBracket, // scope requires bracket or not + style.scopeDef, // scope definition + style.testDefFun, + testType.testBodyFun) + + + val duration = compile(generatedSrc, scalaTest2Classpath, outputDir.getAbsolutePath) + durationFile.write("," + duration) + durationFile.flush() + + val (fileCount, fileSize) = getFileAndByteCount(new File(outputDir, style.className + testType.shortName + "2")) + fileCountFile.write("," + fileCount) + fileCountFile.flush() + fileSizeFile.write("," + fileSize) + fileSizeFile.flush() + } + } + catch { + case e: Throwable => + e.printStackTrace() + } + finally { + durationFile.write("\n") + durationFile.flush() + fileCountFile.write("\n") + fileCountFile.flush() + fileSizeFile.write("\n") + fileSizeFile.flush() + } + } + } + + supersafeStyles.foreach { style => + supersafeTestTypes.foreach { testType => + try { + durationFile.write(style.name + "-" + testType.shortName) // Don't write with MustMatchers to get all 4 names to fit on graph + durationFile.flush() + fileCountFile.write(style.name + "-" + testType.shortName) + fileCountFile.flush() + fileSizeFile.write(style.name + "-" + testType.shortName) + fileSizeFile.flush() + testCounts.foreach { testCount => + println("Working on " + style.className +" " + testType.name + " test count " + testCount + "...") + val outputDir = getOutputDir(baseOutputDir, testCount) + val generatedDir = new File(baseGeneratedDir, "generated-" + testCount) + + val generatedSrc = generateMultipleSourceFiles( + testCount, + 10, // maximum number of tests in a file + new File(generatedDir, "SuperSafe" + style.className), // target dir + style.className + testType.shortName + "3", // package name + testType.importNames, // imports + style.className, // extends + testType.mixinNames, // mixin + style.scopeBracket, // scope requires bracket or not + style.scopeDef, // scope definition + style.testDefFun, + testType.testBodyFun) + + + val duration = compileWithSuperSafe(generatedSrc, scalaTest2Classpath, outputDir.getAbsolutePath) + durationFile.write("," + duration) + durationFile.flush() + + val (fileCount, fileSize) = getFileAndByteCount(new File(outputDir, style.className + testType.shortName + "3")) + fileCountFile.write("," + fileCount) + fileCountFile.flush() + fileSizeFile.write("," + fileSize) + fileSizeFile.flush() + } + } + catch { + case e: Throwable => + e.printStackTrace() + } + finally { + durationFile.write("\n") + durationFile.flush() + fileCountFile.write("\n") + fileCountFile.flush() + fileSizeFile.write("\n") + fileSizeFile.flush() + } + } + } + + durationFile.flush() + durationFile.close() + fileCountFile.flush() + fileCountFile.close() + fileSizeFile.flush() + fileSizeFile.close() +} +else + println("ERROR: Unable to detect Scala version.") From 978979ed5a735b54bd124a945aae2c7aff85f9f6 Mon Sep 17 00:00:00 2001 From: cheeseng Date: Mon, 25 Apr 2016 22:46:07 +0800 Subject: [PATCH 14/14] Added assertBeforeAfter.scala and matcherBeforeAfter.scala. --- assertBeforeAfter.scala | 260 +++++++++++++++++++++++++++++++++++++++ google-chart.scala | 28 +++++ matcherBeforeAfter.scala | 260 +++++++++++++++++++++++++++++++++++++++ runem.sh | 4 + 4 files changed, 552 insertions(+) create mode 100644 assertBeforeAfter.scala create mode 100644 matcherBeforeAfter.scala diff --git a/assertBeforeAfter.scala b/assertBeforeAfter.scala new file mode 100644 index 0000000..12853cc --- /dev/null +++ b/assertBeforeAfter.scala @@ -0,0 +1,260 @@ +import java.net._ +import java.io._ +import java.nio.channels.Channels +import scala.annotation.tailrec +import scala.math.pow + +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} + +val scalaTestWithoutMacroVersion = "3.0.0-before" +val scalaTestWithMacroVersion = "3.0.0-after" + +def downloadFile(urlString: String, targetFile: File) { + println("Downloading " + urlString) + val url = new URL(urlString) + val connection = url.openConnection + val in = connection.getInputStream + val out = new FileOutputStream(targetFile) + out getChannel() transferFrom(Channels.newChannel(in), 0, Long.MaxValue) + in.close() + out.flush() + out.close() +} + +val classFooter = """ + } +}""" + +def generateSourceFile(testCount: Int, targetDir: File, packageName: String, importStatements: Array[String], + extendsName: String, withNames: Array[String], scopeBracket: Boolean, scopeDef: String, + testDefFun: (Int) => String, testBodyFun: (Int) => String): File = { + targetDir.mkdirs() + val targetFile = new File(targetDir, "ExampleSpec.scala") + val targetOut = new BufferedWriter(new FileWriter(targetFile)) + try { + targetOut.write("package " + packageName + "\n\n") + importStatements.foreach { s => + targetOut.write("import " + s + "\n") + } + targetOut.write("\n") + targetOut.write("class ExampleSpec extends " + extendsName + " " + withNames.map(n => " with " + n).mkString(" ") + " {\n") + targetOut.write(" " + scopeDef + (if (scopeBracket) "{" else "") + " \n") + for (x <- 1 to testCount) { + targetOut.write(" " + testDefFun(x) + " {\n") + targetOut.write(" " + testBodyFun(x) + "\n") + targetOut.write(" }\n") + } + targetOut.write(" " + (if (scopeBracket) "}" else "") + "\n") + targetOut.write("}\n") + } + finally { + targetOut.flush() + targetOut.close() + } + targetFile +} + +// Using assert(==) +def assertEqual2TestBodyFun(x: Int): String = "assert(" + x + " + 1 == " + (x+1) + ")" +// Using assert(===) +def assertEqual3TestBodyFun(x: Int): String = "assert(" + x + " + 1 === " + (x+1) + ")" + +// Spec +def specTestDefFun(x: Int): String = "def `increment " + x + "`" + +def compile(srcFile: String, classpath: String, targetDir: String) = { + import scala.collection.JavaConversions._ + + val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val builder = new ProcessBuilder(command) + builder.redirectErrorStream(true) + val start = System.currentTimeMillis + val process = builder.start() + + val stdout = new BufferedReader(new InputStreamReader(process.getInputStream)) + + var line = "Compiling " + srcFile + "..." + while (line != null) { + println (line) + line = stdout.readLine + } + + val end = System.currentTimeMillis + end - start +} + +def getFileAndByteCount(srcDir: File) = { + @tailrec + def getFileAndByteCountAcc(dirList: Array[File], fileCount: Long, byteCount: Long): Tuple2[Long, Long] = { + val (files, subDirs) = dirList.partition(_.isFile) + val classFiles = files.filter(f => f.getName.endsWith(".class")) + val newFileCount = fileCount + classFiles.size + val newByteCount = byteCount + classFiles.map { f => f.length.toLong }.foldLeft(0l) { (a, b) => a + b } + if (subDirs.isEmpty) + (newFileCount, newByteCount) + else + getFileAndByteCountAcc(subDirs.flatMap(d => d.listFiles), newFileCount, newByteCount) + } + getFileAndByteCountAcc(srcDir.listFiles, 0l, 0l) +} + +def deleteDir(targetDir: File) { + val children = targetDir.listFiles + if (children != null) { + targetDir.listFiles.foreach { child => + if (child.isFile) + child.delete() + else + deleteDir(child) + } + targetDir.delete() + } + else + println("Unable to list files in " + targetDir.getAbsolutePath) +} + +def getOutputDir(baseOutputDir: File, testCount: Int): File = { + val outputDirName = "output-" + testCount + val outputDir = new File(baseOutputDir, outputDirName) + outputDir.mkdirs() + outputDir +} + +val scalatestOldJar = new File("scalatest-app_" + scalaVersion + "-" + scalaTestWithoutMacroVersion + ".jar") +if (!scalatestOldJar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestWithoutMacroVersion + "/scalatest-app_" + scalaVersion + "-" + scalaTestWithoutMacroVersion + ".jar", scalatestOldJar) + +val scalatestMacroJar = new File("scalatest-app_" + scalaVersion + "-" + scalaTestWithMacroVersion + ".jar") +if (!scalatestMacroJar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestWithMacroVersion + "/scalatest-app_" + scalaVersion + "-" + scalaTestWithMacroVersion + ".jar", scalatestMacroJar) + +val baseDir = new File("target/" + scalaVersion + "/assertBeforeAfter") +if (baseDir.exists) + deleteDir(baseDir) + +val statDir = new File(baseDir, "stat") + statDir.mkdirs() + +val durationFile = new FileWriter(new File(statDir, "duration.csv")) +val fileCountFile = new FileWriter(new File(statDir, "filecount.csv")) +val fileSizeFile = new FileWriter(new File(statDir, "filesize.csv")) + +val baseOutputDir = new File(baseDir, "output") +baseOutputDir.mkdirs() + +val baseGeneratedDir = new File(baseDir, "generated") +baseGeneratedDir.mkdirs() + +case class Style(name: String, className: String, scopeBracket: Boolean, scopeDef: String, testDefFun: (Int) => String) +case class TestType(name: String, shortName: String, importNames: Array[String], mixinNames: Array[String], testBodyFun: (Int) => String, scalatestJar: File) + +val styles = + Array( + Style("scalatest.Spec", "Spec", true, "object `Scala can ` ", specTestDefFun) + ) + +val testTypes = + Array( + TestType("Before asert(==)", "BeforeEqual2", Array("org.scalatest._"), Array.empty, assertEqual2TestBodyFun, scalatestOldJar), + TestType("After assert(==)", "AfterEqual2", Array("org.scalatest._"), Array.empty, assertEqual2TestBodyFun, scalatestMacroJar), + TestType("Before asert(===)", "BeforeEqual3", Array("org.scalatest._"), Array.empty, assertEqual3TestBodyFun, scalatestOldJar), + TestType("After assert(===)", "AfterEqual3", Array("org.scalatest._"), Array.empty, assertEqual3TestBodyFun, scalatestMacroJar) + ) + +val testCounts = + Array( + 0, + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 1000 + ) + +val headers = "TestCount," + testCounts.mkString(",") + "\n" +durationFile.write(headers) +fileCountFile.write(headers) +fileSizeFile.write(headers) + +styles.foreach { style => + testTypes.foreach { testType => + durationFile.write(testType.shortName) + durationFile.flush() + fileCountFile.write(testType.shortName) + fileCountFile.flush() + fileSizeFile.write(testType.shortName) + fileSizeFile.flush() + try { + testCounts.foreach { testCount => + println("Working on " + testType.name + " test count " + testCount + "...") + val outputDir = getOutputDir(baseOutputDir, testCount) + val generatedDir = new File(baseGeneratedDir, "generated-" + testCount) + + val generatedSrc = generateSourceFile( + testCount, + new File(generatedDir, style.className + testType.shortName), // target dir + style.className + testType.shortName, // package name + testType.importNames, // imports + style.className, // extends + testType.mixinNames, // mixin + style.scopeBracket, // scope requires bracket or not + style.scopeDef, // scope definition + style.testDefFun, + testType.testBodyFun) + val duration = compile(generatedSrc.getAbsolutePath, testType.scalatestJar.getName, outputDir.getAbsolutePath) + durationFile.write("," + duration) + durationFile.flush() + + val (fileCount, fileSize) = getFileAndByteCount(new File(outputDir, style.className + testType.shortName)) + fileCountFile.write("," + fileCount) + fileCountFile.flush() + fileSizeFile.write("," + fileSize) + fileSizeFile.flush() + } + } + catch { + case e: Throwable => + e.printStackTrace() + } + finally { + durationFile.write("\n") + durationFile.flush() + fileCountFile.write("\n") + fileCountFile.flush() + fileSizeFile.write("\n") + fileSizeFile.flush() + } + } +} + +durationFile.flush() +durationFile.close() +fileCountFile.flush() +fileCountFile.close() +fileSizeFile.flush() +fileSizeFile.close() diff --git a/google-chart.scala b/google-chart.scala index dc60c74..6925ba0 100644 --- a/google-chart.scala +++ b/google-chart.scala @@ -288,3 +288,31 @@ if (supersafe211StatDir.exists) generateChartFile(supersafe211StatDir, new File(supersafe211Dir, "supersafe-graph.html")) else println("target/2.11/supersafe/stat directory does not exist, target/2.11/supersafe/supersafe-graph.html will not be generated.") + +val assertBeforeAfter210Dir = new File("target/2.10/assertBeforeAfter") +val assertBeforeAfter210StatDir = new File(assertBeforeAfter210Dir, "stat") +if (assertBeforeAfter210StatDir.exists) + generateChartFile(assertBeforeAfter210StatDir, new File(assertBeforeAfter210Dir, "assertBeforeAfter-graph.html")) +else + println("target/2.10/assertBeforeAfter/stat directory does not exist, target/2.10/assertBeforeAfter/assertBeforeAfter-graph.html will not be generated.") + +val assertBeforeAfter211Dir = new File("target/2.11/assertBeforeAfter") +val assertBeforeAfter211StatDir = new File(assertBeforeAfter211Dir, "stat") +if (assertBeforeAfter211StatDir.exists) + generateChartFile(assertBeforeAfter211StatDir, new File(assertBeforeAfter211Dir, "assertBeforeAfter-graph.html")) +else + println("target/2.11/assertBeforeAfter/stat directory does not exist, target/2.11/assertBeforeAfter/assertBeforeAfter-graph.html will not be generated.") + +val matcherBeforeAfter210Dir = new File("target/2.10/matcherBeforeAfter") +val matcherBeforeAfter210StatDir = new File(matcherBeforeAfter210Dir, "stat") +if (matcherBeforeAfter210StatDir.exists) + generateChartFile(matcherBeforeAfter210StatDir, new File(matcherBeforeAfter210Dir, "matcherBeforeAfter-graph.html")) +else + println("target/2.10/matcherBeforeAfter/stat directory does not exist, target/2.10/matcherBeforeAfter/matcherBeforeAfter-graph.html will not be generated.") + +val matcherBeforeAfter211Dir = new File("target/2.11/matcherBeforeAfter") +val matcherBeforeAfter211StatDir = new File(matcherBeforeAfter211Dir, "stat") +if (matcherBeforeAfter211StatDir.exists) + generateChartFile(matcherBeforeAfter211StatDir, new File(matcherBeforeAfter211Dir, "matcherBeforeAfter-graph.html")) +else + println("target/2.11/matcherBeforeAfter/stat directory does not exist, target/2.11/matcherBeforeAfter/matcherBeforeAfter-graph.html will not be generated.") diff --git a/matcherBeforeAfter.scala b/matcherBeforeAfter.scala new file mode 100644 index 0000000..fb7a2ef --- /dev/null +++ b/matcherBeforeAfter.scala @@ -0,0 +1,260 @@ +import java.net._ +import java.io._ +import java.nio.channels.Channels +import scala.annotation.tailrec +import scala.math.pow + +val scalaHome = { + val home = scala.util.Properties.scalaHome + println("Scala Home: " + home) + home +} + +val scalaVersion = { + val rawVersion = scala.util.Properties.scalaPropOrElse("version.number", "unknown") + println("Detected Scala version: " + rawVersion) + val versionParts = rawVersion.split("\\.") + versionParts(0).toInt + "." + versionParts(1).toInt +} + +val scalaTestWithoutMacroVersion = "3.0.0-before" +val scalaTestWithMacroVersion = "3.0.0-after" + +def downloadFile(urlString: String, targetFile: File) { + println("Downloading " + urlString) + val url = new URL(urlString) + val connection = url.openConnection + val in = connection.getInputStream + val out = new FileOutputStream(targetFile) + out getChannel() transferFrom(Channels.newChannel(in), 0, Long.MaxValue) + in.close() + out.flush() + out.close() +} + +val classFooter = """ + } +}""" + +def generateSourceFile(testCount: Int, targetDir: File, packageName: String, importStatements: Array[String], + extendsName: String, withNames: Array[String], scopeBracket: Boolean, scopeDef: String, + testDefFun: (Int) => String, testBodyFun: (Int) => String): File = { + targetDir.mkdirs() + val targetFile = new File(targetDir, "ExampleSpec.scala") + val targetOut = new BufferedWriter(new FileWriter(targetFile)) + try { + targetOut.write("package " + packageName + "\n\n") + importStatements.foreach { s => + targetOut.write("import " + s + "\n") + } + targetOut.write("\n") + targetOut.write("class ExampleSpec extends " + extendsName + " " + withNames.map(n => " with " + n).mkString(" ") + " {\n") + targetOut.write(" " + scopeDef + (if (scopeBracket) "{" else "") + " \n") + for (x <- 1 to testCount) { + targetOut.write(" " + testDefFun(x) + " {\n") + targetOut.write(" " + testBodyFun(x) + "\n") + targetOut.write(" }\n") + } + targetOut.write(" " + (if (scopeBracket) "}" else "") + "\n") + targetOut.write("}\n") + } + finally { + targetOut.flush() + targetOut.close() + } + targetFile +} + +// Using assert(==) +def shouldBeTestBodyFun(x: Int): String = x + " + 1 should be (" + (x+1) + ")" +// Using assert(===) +def shouldBeShorthandTestBodyFun(x: Int): String = x + " + 1 shouldBe " + (x+1) + +// Spec +def specTestDefFun(x: Int): String = "def `increment " + x + "`" + +def compile(srcFile: String, classpath: String, targetDir: String) = { + import scala.collection.JavaConversions._ + + val command = List("scalac", "-classpath", classpath, "-d", targetDir, srcFile) + val builder = new ProcessBuilder(command) + builder.redirectErrorStream(true) + val start = System.currentTimeMillis + val process = builder.start() + + val stdout = new BufferedReader(new InputStreamReader(process.getInputStream)) + + var line = "Compiling " + srcFile + "..." + while (line != null) { + println (line) + line = stdout.readLine + } + + val end = System.currentTimeMillis + end - start +} + +def getFileAndByteCount(srcDir: File) = { + @tailrec + def getFileAndByteCountAcc(dirList: Array[File], fileCount: Long, byteCount: Long): Tuple2[Long, Long] = { + val (files, subDirs) = dirList.partition(_.isFile) + val classFiles = files.filter(f => f.getName.endsWith(".class")) + val newFileCount = fileCount + classFiles.size + val newByteCount = byteCount + classFiles.map { f => f.length.toLong }.foldLeft(0l) { (a, b) => a + b } + if (subDirs.isEmpty) + (newFileCount, newByteCount) + else + getFileAndByteCountAcc(subDirs.flatMap(d => d.listFiles), newFileCount, newByteCount) + } + getFileAndByteCountAcc(srcDir.listFiles, 0l, 0l) +} + +def deleteDir(targetDir: File) { + val children = targetDir.listFiles + if (children != null) { + targetDir.listFiles.foreach { child => + if (child.isFile) + child.delete() + else + deleteDir(child) + } + targetDir.delete() + } + else + println("Unable to list files in " + targetDir.getAbsolutePath) +} + +def getOutputDir(baseOutputDir: File, testCount: Int): File = { + val outputDirName = "output-" + testCount + val outputDir = new File(baseOutputDir, outputDirName) + outputDir.mkdirs() + outputDir +} + +val scalatestOldJar = new File("scalatest-app_" + scalaVersion + "-" + scalaTestWithoutMacroVersion + ".jar") +if (!scalatestOldJar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestWithoutMacroVersion + "/scalatest-app_" + scalaVersion + "-" + scalaTestWithoutMacroVersion + ".jar", scalatestOldJar) + +val scalatestMacroJar = new File("scalatest-app_" + scalaVersion + "-" + scalaTestWithMacroVersion + ".jar") +if (!scalatestMacroJar.exists) + downloadFile("https://oss.sonatype.org/content/repositories/releases/org/scalatest/scalatest_" + scalaVersion + "/" + scalaTestWithMacroVersion + "/scalatest-app_" + scalaVersion + "-" + scalaTestWithMacroVersion + ".jar", scalatestMacroJar) + +val baseDir = new File("target/" + scalaVersion + "/matcherBeforeAfter") +if (baseDir.exists) + deleteDir(baseDir) + +val statDir = new File(baseDir, "stat") + statDir.mkdirs() + +val durationFile = new FileWriter(new File(statDir, "duration.csv")) +val fileCountFile = new FileWriter(new File(statDir, "filecount.csv")) +val fileSizeFile = new FileWriter(new File(statDir, "filesize.csv")) + +val baseOutputDir = new File(baseDir, "output") +baseOutputDir.mkdirs() + +val baseGeneratedDir = new File(baseDir, "generated") +baseGeneratedDir.mkdirs() + +case class Style(name: String, className: String, scopeBracket: Boolean, scopeDef: String, testDefFun: (Int) => String) +case class TestType(name: String, shortName: String, importNames: Array[String], mixinNames: Array[String], testBodyFun: (Int) => String, scalatestJar: File) + +val styles = + Array( + Style("scalatest.Spec", "Spec", true, "object `Scala can ` ", specTestDefFun) + ) + +val testTypes = + Array( + TestType("Before should be", "BeforeShouldBe", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun, scalatestOldJar), + TestType("After should be", "AfterShouldBe", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeTestBodyFun, scalatestMacroJar), + TestType("Before shouldBe", "BeforeShouldBeShorthand", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeShorthandTestBodyFun, scalatestOldJar), + TestType("After shouldBe", "AfterShouldBeShorthand", Array("org.scalatest._", "Matchers._"), Array.empty, shouldBeShorthandTestBodyFun, scalatestMacroJar) + ) + +val testCounts = + Array( + 0, + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 1000 + ) + +val headers = "TestCount," + testCounts.mkString(",") + "\n" +durationFile.write(headers) +fileCountFile.write(headers) +fileSizeFile.write(headers) + +styles.foreach { style => + testTypes.foreach { testType => + durationFile.write(testType.shortName) + durationFile.flush() + fileCountFile.write(testType.shortName) + fileCountFile.flush() + fileSizeFile.write(testType.shortName) + fileSizeFile.flush() + try { + testCounts.foreach { testCount => + println("Working on " + testType.name + " test count " + testCount + "...") + val outputDir = getOutputDir(baseOutputDir, testCount) + val generatedDir = new File(baseGeneratedDir, "generated-" + testCount) + + val generatedSrc = generateSourceFile( + testCount, + new File(generatedDir, style.className + testType.shortName), // target dir + style.className + testType.shortName, // package name + testType.importNames, // imports + style.className, // extends + testType.mixinNames, // mixin + style.scopeBracket, // scope requires bracket or not + style.scopeDef, // scope definition + style.testDefFun, + testType.testBodyFun) + val duration = compile(generatedSrc.getAbsolutePath, testType.scalatestJar.getName, outputDir.getAbsolutePath) + durationFile.write("," + duration) + durationFile.flush() + + val (fileCount, fileSize) = getFileAndByteCount(new File(outputDir, style.className + testType.shortName)) + fileCountFile.write("," + fileCount) + fileCountFile.flush() + fileSizeFile.write("," + fileSize) + fileSizeFile.flush() + } + } + catch { + case e: Throwable => + e.printStackTrace() + } + finally { + durationFile.write("\n") + durationFile.flush() + fileCountFile.write("\n") + fileCountFile.flush() + fileSizeFile.write("\n") + fileSizeFile.flush() + } + } +} + +durationFile.flush() +durationFile.close() +fileCountFile.flush() +fileCountFile.close() +fileSizeFile.flush() +fileSizeFile.close() diff --git a/runem.sh b/runem.sh index e21fab7..51ec46b 100755 --- a/runem.sh +++ b/runem.sh @@ -21,4 +21,8 @@ $SCALA_210/bin/scala scalautilsScalaz.scala $SCALA_211/bin/scala scalautilsScalaz.scala $SCALA_210/bin/scala shapelessTables.scala $SCALA_211/bin/scala shapelessTables.scala +$SCALA_210/bin/scala assertBeforeAfter.scala +$SCALA_211/bin/scala assertBeforeAfter.scala +$SCALA_210/bin/scala matcherBeforeAfter.scala +$SCALA_211/bin/scala matcherBeforeAfter.scala $SCALA_210/bin/scala google-chart.scala