From eb32d8d4a1e2bd50e5416fcfefd72dfe6da1a7bb Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Mon, 13 Aug 2018 00:42:18 +0800 Subject: Add scalatags example --- example/compress/build.sc | 2 +- example/compress2/build.sc | 2 +- example/compress3/build.sc | 2 +- example/cookies/build.sc | 2 +- example/decorated/build.sc | 2 +- example/decorated2/build.sc | 2 +- example/formJsonPost/build.sc | 2 +- example/httpMethods/build.sc | 2 +- example/minimalApplication/build.sc | 2 +- example/minimalApplication2/build.sc | 2 +- example/redirectAbort/build.sc | 2 +- example/scalatags/app/src/Scalatags.scala | 15 ++++++++++++ example/scalatags/app/test/src/ExampleTests.scala | 29 +++++++++++++++++++++++ example/scalatags/build.sc | 19 +++++++++++++++ example/staticFiles/build.sc | 2 +- example/todo/app/test/src/ExampleTests.scala | 22 +++++++++++++++++ example/todo/app/test/src/TodoTest.scala | 22 ----------------- example/todo/build.sc | 2 +- example/todoApi/build.sc | 2 +- example/todoDb/build.sc | 2 +- example/variableRoutes/build.sc | 2 +- 21 files changed, 101 insertions(+), 38 deletions(-) create mode 100644 example/scalatags/app/src/Scalatags.scala create mode 100644 example/scalatags/app/test/src/ExampleTests.scala create mode 100644 example/scalatags/build.sc create mode 100644 example/todo/app/test/src/ExampleTests.scala delete mode 100644 example/todo/app/test/src/TodoTest.scala (limited to 'example') diff --git a/example/compress/build.sc b/example/compress/build.sc index 6b3ab3f..2794393 100644 --- a/example/compress/build.sc +++ b/example/compress/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/compress2/build.sc b/example/compress2/build.sc index 6b3ab3f..2794393 100644 --- a/example/compress2/build.sc +++ b/example/compress2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/compress3/build.sc b/example/compress3/build.sc index 6b3ab3f..2794393 100644 --- a/example/compress3/build.sc +++ b/example/compress3/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/cookies/build.sc b/example/cookies/build.sc index 6b3ab3f..2794393 100644 --- a/example/cookies/build.sc +++ b/example/cookies/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/decorated/build.sc b/example/decorated/build.sc index 6b3ab3f..2794393 100644 --- a/example/decorated/build.sc +++ b/example/decorated/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/decorated2/build.sc b/example/decorated2/build.sc index 6b3ab3f..2794393 100644 --- a/example/decorated2/build.sc +++ b/example/decorated2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/formJsonPost/build.sc b/example/formJsonPost/build.sc index 6b3ab3f..2794393 100644 --- a/example/formJsonPost/build.sc +++ b/example/formJsonPost/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/httpMethods/build.sc b/example/httpMethods/build.sc index 6b3ab3f..2794393 100644 --- a/example/httpMethods/build.sc +++ b/example/httpMethods/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/minimalApplication/build.sc b/example/minimalApplication/build.sc index 6b3ab3f..2794393 100644 --- a/example/minimalApplication/build.sc +++ b/example/minimalApplication/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/minimalApplication2/build.sc b/example/minimalApplication2/build.sc index 6b3ab3f..2794393 100644 --- a/example/minimalApplication2/build.sc +++ b/example/minimalApplication2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/redirectAbort/build.sc b/example/redirectAbort/build.sc index 6b3ab3f..2794393 100644 --- a/example/redirectAbort/build.sc +++ b/example/redirectAbort/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/scalatags/app/src/Scalatags.scala b/example/scalatags/app/src/Scalatags.scala new file mode 100644 index 0000000..600f022 --- /dev/null +++ b/example/scalatags/app/src/Scalatags.scala @@ -0,0 +1,15 @@ +package app +import scalatags.Text.all._ +object Scalatags extends cask.MainRoutes{ + @cask.get("/") + def hello() = { + "" + html( + body( + h1("Hello World"), + p("I am cow") + ) + ) + } + + initialize() +} diff --git a/example/scalatags/app/test/src/ExampleTests.scala b/example/scalatags/app/test/src/ExampleTests.scala new file mode 100644 index 0000000..8eccecf --- /dev/null +++ b/example/scalatags/app/test/src/ExampleTests.scala @@ -0,0 +1,29 @@ +package app +import io.undertow.Undertow + +import utest._ + +object ExampleTests extends TestSuite{ + def test[T](example: cask.main.BaseMain)(f: String => T): T = { + val server = Undertow.builder + .addHttpListener(8080, "localhost") + .setHandler(example.defaultHandler) + .build + server.start() + val res = + try f("http://localhost:8080") + finally server.stop() + res + } + + val tests = Tests { + 'Scalatags - test(Scalatags) { host => + val body = requests.get(host).text() + + assert( + body.contains("

Hello World

"), + body.contains("

I am cow

"), + ) + } + } +} diff --git a/example/scalatags/build.sc b/example/scalatags/build.sc new file mode 100644 index 0000000..ff39504 --- /dev/null +++ b/example/scalatags/build.sc @@ -0,0 +1,19 @@ +import mill._, scalalib._ + + +trait AppModule extends ScalaModule{ + def scalaVersion = "2.12.6" + def ivyDeps = Agg( + ivy"com.lihaoyi::cask:0.0.1", + ivy"com.lihaoyi::scalatags:0.6.7", + ) + + object test extends Tests{ + def testFrameworks = Seq("utest.runner.Framework") + + def ivyDeps = Agg( + ivy"com.lihaoyi::utest::0.6.3", + ivy"com.lihaoyi::requests::0.1.2", + ) + } +} \ No newline at end of file diff --git a/example/staticFiles/build.sc b/example/staticFiles/build.sc index 6b3ab3f..2794393 100644 --- a/example/staticFiles/build.sc +++ b/example/staticFiles/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/todo/app/test/src/ExampleTests.scala b/example/todo/app/test/src/ExampleTests.scala new file mode 100644 index 0000000..e8ca7eb --- /dev/null +++ b/example/todo/app/test/src/ExampleTests.scala @@ -0,0 +1,22 @@ +package app +import utest._ +object ExampleTests extends TestSuite{ + def test[T](example: cask.main.BaseMain)(f: String => T): T = { + val server = io.undertow.Undertow.builder + .addHttpListener(8080, "localhost") + .setHandler(example.defaultHandler) + .build + server.start() + val res = + try f("http://localhost:8080") + finally server.stop() + res + } + val tests = Tests{ + 'TodoServer - test(TodoServer){ host => + val page = requests.get(host).text() + assert(page.contains("What needs to be done?")) + } + } + +} \ No newline at end of file diff --git a/example/todo/app/test/src/TodoTest.scala b/example/todo/app/test/src/TodoTest.scala deleted file mode 100644 index 8f38612..0000000 --- a/example/todo/app/test/src/TodoTest.scala +++ /dev/null @@ -1,22 +0,0 @@ -package app -import utest._ -object TodoTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { - val server = io.undertow.Undertow.builder - .addHttpListener(8080, "localhost") - .setHandler(example.defaultHandler) - .build - server.start() - val res = - try f("http://localhost:8080") - finally server.stop() - res - } - val tests = Tests{ - 'TodoServer - test(TodoServer){ host => - val page = requests.get(host).text() - assert(page.contains("What needs to be done?")) - } - } - -} \ No newline at end of file diff --git a/example/todo/build.sc b/example/todo/build.sc index b570b3b..77a4dee 100644 --- a/example/todo/build.sc +++ b/example/todo/build.sc @@ -11,7 +11,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/todoApi/build.sc b/example/todoApi/build.sc index 6b3ab3f..2794393 100644 --- a/example/todoApi/build.sc +++ b/example/todoApi/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/todoDb/build.sc b/example/todoDb/build.sc index b570b3b..77a4dee 100644 --- a/example/todoDb/build.sc +++ b/example/todoDb/build.sc @@ -11,7 +11,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/variableRoutes/build.sc b/example/variableRoutes/build.sc index 6b3ab3f..2794393 100644 --- a/example/variableRoutes/build.sc +++ b/example/variableRoutes/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", -- cgit v1.2.3