Skip to content

Commit 5d4fc25

Browse files
committed
Final Scala scripts and documentation.
1 parent 74cda2e commit 5d4fc25

8 files changed

Lines changed: 133 additions & 35 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,13 @@ language subproject contains the Data and Test folders necessary.
499499
On linux, execute the `evaluate_haskell.sh` script within its current directory and it will create
500500
a `haskell-report.txt` file within `target/ep-firstVersion`
501501

502+
## Compiling Scala and running test cases with FunSpec
503+
504+
The Haskell code uses [FunSpec](https://www.scalatest.org/getting_started_with_fun_spec) for testing.
505+
506+
On Windows, execute the `evaluate_scala.bat` script within its current directory and it will create
507+
a `scala-report.txt` file within `target/ep-firstVersion`
508+
502509
# References
503510

504511
1. Wadler, Philip, [Email to to Java Genericity Mailing List](http://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt)

build.sbt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import play.twirl.sbt.SbtTwirl
66
lazy val commonSettings = Seq(
77
version := "1.0.0-SNAPSHOT",
88
organization := "org.combinators",
9-
9+
1010
scalaVersion := "2.12.17",
1111

1212
resolvers ++= Seq(
@@ -45,21 +45,21 @@ lazy val commonSettings = Seq(
4545
"junit" % "junit" % "4.12",
4646
"javax.inject" % "javax.inject" % "1",
4747
guice
48-
)
48+
)
4949
)
5050

5151
/** The core components to model expression problem code generators and domains.
52-
* Things in here are (DI, LI, AI).
53-
*/
52+
* Things in here are (DI, LI, AI).
53+
*/
5454
lazy val core = (Project(id = "core", base = file("core")))
5555
.settings(commonSettings: _*)
5656
.settings(
5757
moduleName := "expression-problem-core"
5858
)
5959

6060
/** Template for a subproject for a specific domain named `domainName`.
61-
* These projects should be (DD, LI, AI).
62-
*/
61+
* These projects should be (DD, LI, AI).
62+
*/
6363
def standardDomainProject(domainName: String): Project =
6464
(Project(id = s"domain-$domainName", base = file(s"domain/$domainName")))
6565
.settings(commonSettings: _*)
@@ -74,14 +74,14 @@ lazy val domainMath = standardDomainProject("math")
7474
lazy val domainShape = standardDomainProject("shape")
7575

7676
/** Template for a subproject for a specific language and its EP approaches.
77-
* Contains code in the set {DD, DI} x LD x {AD, AI}.
78-
* Includes startable play server to host generated solutions.
79-
*/
77+
* Contains code in the set {DD, DI} x LD x {AD, AI}.
78+
* Includes startable play server to host generated solutions.
79+
*/
8080
def standardLanguageProject(languageName: String): Project =
8181
(Project(id = s"language-$languageName", base = file(s"language/$languageName")))
8282
.settings(commonSettings: _*)
83-
// .enablePlugins(PlayScala)
84-
// .disablePlugins(PlayLayoutPlugin)
83+
// .enablePlugins(PlayScala)
84+
// .disablePlugins(PlayLayoutPlugin)
8585
.settings(
8686
moduleName := s"expression-problem-language-$languageName",
8787
//libraryDependencies += guice

evaluate_scala.bat

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
@ECHO OFF
2+
3+
@REM Assume that 'sbt' is already installed someplace
4+
5+
if exist target (
6+
rem file exists
7+
) else (
8+
@echo "No target directory"
9+
goto:EOF
10+
)
11+
12+
cd target
13+
14+
if exist ep-firstVersion (
15+
rem file exists
16+
) else (
17+
@echo "ep-firstVersion has not yet been generated"
18+
cd ..
19+
goto:EOF
20+
)
21+
22+
cd ep-firstVersion
23+
24+
if exist scala (
25+
rem file exists
26+
) else (
27+
@echo "No Scala EP approaches have been generated"
28+
cd ..\..
29+
goto:EOF
30+
)
31+
32+
@REM All output will appear in the scala-report.txt
33+
@echo REPORT > scala-report.txt
34+
35+
cd scala
36+
37+
setlocal enabledelayedexpansion
38+
for /D %%d in (.\*) do (
39+
@echo %%d >> ..\scala-report.txt
40+
@echo %%d
41+
cd %%d
42+
for /D %%m in (.\*) do (
43+
@echo %%m >> ..\..\scala-report.txt
44+
@echo %%m
45+
cd %%m
46+
cd
47+
echo "compiling %%d %%m"
48+
echo libraryDependencies += "org.scalatest" %%%% "scalatest" %% "3.2.18" %% "test" > build.sbt
49+
echo exit > exit
50+
51+
if exist project (
52+
rem file exists
53+
) else (
54+
mkdir project
55+
)
56+
if exist src (
57+
rem file exists
58+
) else (
59+
mkdir src
60+
mkdir src\main
61+
mkdir src\main\scala
62+
mkdir src\test
63+
mkdir src\test\scala
64+
65+
@REM move files (though of course this can only be done once)
66+
echo "moving files..."
67+
move *.scala src\main\scala >nul
68+
move src\main\scala\TestSuite*.scala src\test\scala >nul
69+
)
70+
71+
echo "compiling and testing..."
72+
call sbt test >> ..\..\..\scala-report.txt 2>&1 <exit
73+
cd
74+
del exit
75+
cd ..
76+
)
77+
cd ..
78+
)
79+
80+
echo "-------------" >> ..\scala-report.txt
81+
echo "FINALLY DONE" >> ..\scala-report.txt
82+
echo "-------------" >> ..\scala-report.txt
83+
84+
@rem go back home
85+
cd ..\..\..
86+
87+
dir target\ep-firstVersion\scala-report.txt

language/scala/src/main/scala/org/combinators/ep/language/scala/FunSpecTestGenerator.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ trait FunSpecTestGenerator extends TestGenerator with ScalaGenerator with Perfor
2929
testGenerator.zipWithIndex.map{ case (t, num) => {
3030
ScalaTestWithPath(Scala(s"""
3131
|$packageDeclaration
32-
|import org.scalatest.FunSpec
3332
|
34-
|class TestSuite$num extends FunSpec {
33+
|import org.scalatest.funspec.AnyFunSpec
34+
|
35+
|class TestSuite$num extends AnyFunSpec {
3536
| describe("test cases") {
3637
| it ("run test") {
3738
| ${t.mkString("\n")}

language/scala/src/main/scala/org/combinators/ep/language/scala/GenerateAll.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ object GenerateAll extends App {
99
approaches.foreach(approach =>
1010
systems.foreach(system =>
1111
approach match {
12-
case "straight" => StraightTest.evaluate (system).generatedCode (approach, system)
13-
case "oo" => OOTest.evaluate (system).generatedCode (approach, system)
14-
case "functional" => FunctionalTest.evaluate (system).generatedCode (approach, system)
12+
case "straight" => StraightTest.evaluate (system).generatedCode (approach, system, Some("scala_oo"))
13+
case "oo" => OOTest.evaluate (system).generatedCode (approach, system, Some("odersky"))
14+
case "functional" => FunctionalTest.evaluate (system).generatedCode (approach, system, Some("scala_func"))
1515

1616
case _ => ???
1717
})

language/scala/src/main/scala/org/combinators/ep/language/scala/GenerateApproach.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.nio.file.{Files, Paths, StandardOpenOption}
88
import org.apache.commons.io.FileUtils
99
import org.combinators.ep.generator.{LanguageIndependentGenerator, LanguageIndependentTestGenerator}
1010
import org.combinators.ep.language.scala.functional.{FunSpecFunctionalTestGenerator, FunctionalGenerator}
11-
import org.combinators.ep.language.scala.oo.OderskyGenerator
11+
import org.combinators.ep.language.scala.oo.{FunSpecOOTestGenerator, OderskyGenerator}
1212
import org.combinators.ep.language.scala.straight.OOGenerator
1313

1414
import System.nanoTime
@@ -18,9 +18,9 @@ abstract class BaseTest(val id:String) {
1818
val gen: WithDomain[MathDomain] with LanguageIndependentGenerator with LanguageIndependentTestGenerator
1919

2020
// time the synthesis of the generated code plus test suites
21-
def generatedCode(approachName:String, systemName: String): Long = {
21+
def generatedCode(approachName:String, systemName: String, pkg: Option[String]): Long = {
2222
val now = nanoTime
23-
val all_code = gen.generatedCode() ++ gen.generateSuite(None)
23+
val all_code = gen.generatedCode() ++ gen.generateSuite(pkg)
2424
val scala_code = all_code.asInstanceOf[Seq[ScalaWithPath]]
2525

2626
val outputDir = Paths.get("target", "ep-firstVersion", "scala", approachName, systemName)
@@ -47,19 +47,19 @@ object OOTest extends App {
4747

4848
selected match {
4949
case "e0" => new BaseTest("e0") {
50-
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecTestGenerator with e0
50+
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecOOTestGenerator with e0
5151
}
5252
case "e1" => new BaseTest("e1") {
53-
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecTestGenerator with e0 with e1
53+
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecOOTestGenerator with e0 with e1
5454
}
5555
case "e2" => new BaseTest("e2") {
56-
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecTestGenerator with e0 with e1 with e2
56+
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecOOTestGenerator with e0 with e1 with e2
5757
}
5858
case "e3" => new BaseTest("e3") {
59-
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecTestGenerator with e0 with e1 with e2 with e3
59+
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecOOTestGenerator with e0 with e1 with e2 with e3
6060
}
6161
case "e4" => new BaseTest("e4") {
62-
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecTestGenerator with e0 with e1 with e2 with e3 with e4
62+
override val gen = new WithDomain(MathDomain) with OderskyGenerator with FunSpecOOTestGenerator with e0 with e1 with e2 with e3 with e4
6363
}
6464

6565
case _ => ???
@@ -130,13 +130,13 @@ object GenerateApproach extends App {
130130
println ("Generating code...")
131131

132132
// Choose your own adventure. Cannot go higher than e4 for now...
133-
val approach = "oo"
134-
val system = "e4"
133+
val approach = "straight"
134+
val system = "e0"
135135

136136
approach match {
137-
case "straight" => StraightTest.evaluate (system).generatedCode (approach, system)
138-
case "oo" => OOTest.evaluate (system).generatedCode (approach, system)
139-
case "functional" => FunctionalTest.evaluate (system).generatedCode (approach, system)
137+
case "straight" => StraightTest.evaluate (system).generatedCode (approach, system, Some("scala_oo"))
138+
case "oo" => OOTest.evaluate (system).generatedCode (approach, system, Some("odersky"))
139+
case "functional" => FunctionalTest.evaluate (system).generatedCode (approach, system, Some("scala_func"))
140140

141141
case _ => ???
142142
}

language/scala/src/main/scala/org/combinators/ep/language/scala/functional/FunSpecFunctionalTestGenerator.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ trait FunSpecFunctionalTestGenerator extends FunSpecTestGenerator {
3535
testGenerator.zipWithIndex.map{ case (t, num) =>
3636
ScalaTestWithPath(Scala(s"""
3737
|$packageDeclaration
38-
|import org.scalatest.FunSpec
38+
|import org.scalatest.funspec.AnyFunSpec
3939
|
40-
|class TestSuite$num extends FunSpec $withClause {
40+
|class TestSuite$num extends AnyFunSpec $withClause {
4141
|
4242
| type visitor = Visitor
4343
| ${helpers.mkString("\n")}

language/scala/src/main/scala/org/combinators/ep/language/scala/oo/FunSpecOOTestGenerator.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import java.nio.file.Paths
55
import org.combinators.ep.language.scala.{FunSpecTestGenerator, Scala, ScalaTestWithPath, ScalaWithPath}
66
import org.combinators.ep.domain.{BaseDomain, ModelDomain}
77

8+
// Note: never got these test cases to work...
9+
810
trait FunSpecOOTestGenerator extends FunSpecTestGenerator {
911
val domain: BaseDomain with ModelDomain
1012

@@ -22,16 +24,17 @@ trait FunSpecOOTestGenerator extends FunSpecTestGenerator {
2224
""
2325
}
2426

25-
// t is a Seq[Stat] so we have to expand with mkString
27+
// t is a Seq[Stat] so we have to expand with mkString. Would inject ${t.mkString("\n")} below
2628
testGenerator.zipWithIndex.map{ case (t, num) =>
2729
ScalaTestWithPath(Scala(s"""
2830
|$packageDeclaration
29-
|import org.scalatest.FunSpec
31+
|import org.scalatest.funspec.AnyFunSpec
3032
|
31-
|class TestSuite$num extends FunSpec with ${model.name.capitalize} {
33+
|class TestSuite$num extends AnyFunSpec with ${model.name.capitalize} {
3234
| describe("test cases") {
3335
| it ("run test") {
34-
| ${t.mkString("\n")}
36+
| alert("Not generating test cases for Odersky")
37+
| assert(false == true)
3538
| }
3639
| }
3740
|}""".stripMargin).source(), Paths.get(s"TestSuite$num.scala"))

0 commit comments

Comments
 (0)