Skip to content

Commit

Permalink
Simplify integration test layout (com-lihaoyi#3457)
Browse files Browse the repository at this point in the history
* `test/src/` just becomes `src/`, cutting out one unnecessary degree of
nesting
* `repo/` is now `resources/`, letting us use the now-standard
`MILL_TEST_RESOURCE_FOLDER` environment variable rather than the bespoke
`MILL_INTEGRATION_REPO_ROOT`
* `example.foo[bar]` no longer extends `JavaModule`, and instead only
defines the minimal set of properties necessary to configure the child
`local`/`fork`/`server` modules correctly, and unlike the
`integration.*` modules they do not need to compile anything themselves.
* The child `ModeModule`s in both `example` and `integration` also no
longer inherit `MillJavaModule`, since they do not compile anything
themselves. Instead they inherit `mill.scalalib.TestModule` with the
minimal set of properties wired up

This should greatly simplify things overall, as the various integration
and example test modules no longer have a bunch of unwanted
`JavaModule`/`ScalaModule` tasks that need to be overriden.
  • Loading branch information
lihaoyi committed Sep 4, 2024
1 parent dd57a10 commit 028abe4
Show file tree
Hide file tree
Showing 183 changed files with 102 additions and 106 deletions.
4 changes: 2 additions & 2 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul

/** Default tests module. */
lazy val test: MillScalaTests = new MillScalaTests {}
trait MillScalaTests extends ScalaTests with MillBaseTestsModule {
trait MillScalaTests extends ScalaTests with MillJavaModule with MillBaseTestsModule {
def forkArgs = super.forkArgs() ++ outer.testArgs()
def moduleDeps = outer.testModuleDeps
def ivyDeps = super.ivyDeps() ++ outer.testIvyDeps()
def forkEnv = super.forkEnv() ++ outer.forkEnv()
}
}

trait MillBaseTestsModule extends MillJavaModule with TestModule {
trait MillBaseTestsModule extends TestModule {
def forkArgs = T {
Seq(
s"-DMILL_SCALA_2_13_VERSION=${Deps.scalaVersion}",
Expand Down
1 change: 0 additions & 1 deletion example/depth/large/11-helper-files/src/Main.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

object Main {
def main(args: Array[String]): Unit = {
println("Main Env build.util.myScalaVersion: " + sys.env("MY_SCALA_VERSION"))
Expand Down
1 change: 0 additions & 1 deletion example/depth/large/12-helper-files-sc/src/Main.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

object Main {
def main(args: Array[String]): Unit = {
println("Main Env build.util.myScalaVersion: " + sys.env("MY_SCALA_VERSION"))
Expand Down
14 changes: 8 additions & 6 deletions example/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ object `package` extends RootModule with Module {
this.millModuleSegments.parts.dropRight(1).last
).valuesToModules.get(List(crossValue))

def testRepoRoot = upstreamOpt match {
case None => T{ super.testRepoRoot() }
def resources = upstreamOpt match {
case None => T{ Seq(super.testRepoRoot()) }
case Some(upstream) => T{
os.copy.over(super.testRepoRoot().path, T.dest)
val upstreamRoot = upstream.testRepoRoot().path
val suffix = Seq("build.mill", "build.mill").find(s => os.exists(upstreamRoot / s)).head
for(lines <- buildScLines()) {
os.write.over(T.dest / suffix, lines.mkString("\n"))
}
PathRef(T.dest)
Seq(PathRef(T.dest))
}
}
def buildScLines = upstreamOpt match {
Expand Down Expand Up @@ -118,14 +118,16 @@ object `package` extends RootModule with Module {
}
}

trait ExampleCrossModule extends build.integration.IntegrationTestCrossModule {
trait ExampleCrossModule extends build.integration.IntegrationTestModule {
// disable scalafix because these example modules don't have sources causing it to misbehave
def fix(args: String*): Command[Unit] = T.command {}
def testRepoRoot: T[PathRef] = T.source(millSourcePath)

def compile = build.testkit.compile()
def resources = Seq(testRepoRoot())
def runClasspath = build.main.test.runClasspath()
def localRunClasspath = build.testkit.localRunClasspath()

def forkEnv = super.forkEnv() ++ Map(
def forkEnv = Map(
"MILL_EXAMPLE_PARSED" -> upickle.default.write(parsed()),
"LANG" -> "C"
)
Expand Down
2 changes: 1 addition & 1 deletion example/scalalib/basic/2-custom-build-logic/src/Foo.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package foo

object Foo{
object Foo {

def getLineCount() = {
scala.io.Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ object Foo {
val fi = new InputReader(new java.io.FileInputStream(filePath))
try {
while (
fi.nextLine() match{
fi.nextLine() match {
case null => false
case line =>
println(line)
true
}
)()
) ()
} finally {
fi.close()
}
Expand Down
60 changes: 29 additions & 31 deletions example/scalalib/web/1-todo-webapp/src/WebApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package webapp
import scalatags.Text.all._
import scalatags.Text.tags2

object WebApp extends cask.MainRoutes{
object WebApp extends cask.MainRoutes {
case class Todo(checked: Boolean, text: String)

object Todo {
Expand Down Expand Up @@ -48,29 +48,33 @@ object WebApp extends cask.MainRoutes{
renderBody(state)
}

def renderBody(state: String)/*: scalatags.Text.TypedTag[String] */= {
val filteredTodos = state match{
def renderBody(state: String) /*: scalatags.Text.TypedTag[String] */ = {
val filteredTodos = state match {
case "all" => todos.zipWithIndex
case "active" => todos.zipWithIndex.filter(!_._1.checked)
case "completed" => todos.zipWithIndex.filter(_._1.checked)
}
div(
header(cls := "header",
header(
cls := "header",
h1("todos"),
input(cls := "new-todo", placeholder := "What needs to be done?", autofocus := "")
),
tags2.section(cls := "main",
tags2.section(
cls := "main",
input(
id := "toggle-all",
cls := "toggle-all",
`type` := "checkbox",
if (todos.filter(_.checked).size != 0) checked else ()
),
label(`for` := "toggle-all","Mark all as complete"),
ul(cls := "todo-list",
for((todo, index) <- filteredTodos) yield li(
label(`for` := "toggle-all", "Mark all as complete"),
ul(
cls := "todo-list",
for ((todo, index) <- filteredTodos) yield li(
if (todo.checked) cls := "completed" else (),
div(cls := "view",
div(
cls := "view",
input(
cls := "toggle",
`type` := "checkbox",
Expand All @@ -84,31 +88,28 @@ object WebApp extends cask.MainRoutes{
)
)
),
footer(cls := "footer",
span(cls := "todo-count",
strong(todos.filter(!_.checked).size),
" items left"
),
ul(cls := "filters",
li(cls := "todo-all",
a(if (state == "all") cls := "selected" else (), "All")
),
li(cls := "todo-active",
a(if (state == "active") cls := "selected" else (), "Active")
),
li(cls := "todo-completed",
footer(
cls := "footer",
span(cls := "todo-count", strong(todos.filter(!_.checked).size), " items left"),
ul(
cls := "filters",
li(cls := "todo-all", a(if (state == "all") cls := "selected" else (), "All")),
li(cls := "todo-active", a(if (state == "active") cls := "selected" else (), "Active")),
li(
cls := "todo-completed",
a(if (state == "completed") cls := "selected" else (), "Completed")
)
),
button(cls := "clear-completed","Clear completed")
button(cls := "clear-completed", "Clear completed")
)
)
}

@cask.get("/")
def index() = {
doctype("html")(
html(lang := "en",
html(
lang := "en",
head(
meta(charset := "utf-8"),
meta(name := "viewport", content := "width=device-width, initial-scale=1"),
Expand All @@ -117,14 +118,11 @@ object WebApp extends cask.MainRoutes{
),
body(
tags2.section(cls := "todoapp", renderBody("all")),
footer(cls := "info",
footer(
cls := "info",
p("Double-click to edit a todo"),
p("Created by ",
a(href := "http://todomvc.com","Li Haoyi")
),
p("Part of ",
a(href := "http://todomvc.com","TodoMVC")
)
p("Created by ", a(href := "http://todomvc.com", "Li Haoyi")),
p("Part of ", a(href := "http://todomvc.com", "TodoMVC"))
),
script(src := "/static/main.js")
)
Expand Down
62 changes: 30 additions & 32 deletions example/scalalib/web/2-webapp-cache-busting/src/WebApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package webapp
import scalatags.Text.all._
import scalatags.Text.tags2

object WebApp extends cask.MainRoutes{
object WebApp extends cask.MainRoutes {
override def port = 8081
case class Todo(checked: Boolean, text: String)

Expand All @@ -13,7 +13,7 @@ object WebApp extends cask.MainRoutes{
val hashedResourceMapping = upickle.default.read[Map[String, String]](
os.read(os.resource / "hashed-resource-mapping.json")
)
def hashedResource(s: String) = s match{
def hashedResource(s: String) = s match {
case s"/static/$rest" =>
val s"webapp/$hashed" = hashedResourceMapping(s"webapp/$rest")
s"/static/$hashed"
Expand Down Expand Up @@ -58,29 +58,33 @@ object WebApp extends cask.MainRoutes{
renderBody(state)
}

def renderBody(state: String)/*: scalatags.Text.TypedTag[String] */= {
val filteredTodos = state match{
def renderBody(state: String) /*: scalatags.Text.TypedTag[String] */ = {
val filteredTodos = state match {
case "all" => todos.zipWithIndex
case "active" => todos.zipWithIndex.filter(!_._1.checked)
case "completed" => todos.zipWithIndex.filter(_._1.checked)
}
div(
header(cls := "header",
header(
cls := "header",
h1("todos"),
input(cls := "new-todo", placeholder := "What needs to be done?", autofocus := "")
),
tags2.section(cls := "main",
tags2.section(
cls := "main",
input(
id := "toggle-all",
cls := "toggle-all",
`type` := "checkbox",
if (todos.filter(_.checked).size != 0) checked else ()
),
label(`for` := "toggle-all","Mark all as complete"),
ul(cls := "todo-list",
for((todo, index) <- filteredTodos) yield li(
label(`for` := "toggle-all", "Mark all as complete"),
ul(
cls := "todo-list",
for ((todo, index) <- filteredTodos) yield li(
if (todo.checked) cls := "completed" else (),
div(cls := "view",
div(
cls := "view",
input(
cls := "toggle",
`type` := "checkbox",
Expand All @@ -94,31 +98,28 @@ object WebApp extends cask.MainRoutes{
)
)
),
footer(cls := "footer",
span(cls := "todo-count",
strong(todos.filter(!_.checked).size),
" items left"
),
ul(cls := "filters",
li(cls := "todo-all",
a(if (state == "all") cls := "selected" else (), "All")
),
li(cls := "todo-active",
a(if (state == "active") cls := "selected" else (), "Active")
),
li(cls := "todo-completed",
footer(
cls := "footer",
span(cls := "todo-count", strong(todos.filter(!_.checked).size), " items left"),
ul(
cls := "filters",
li(cls := "todo-all", a(if (state == "all") cls := "selected" else (), "All")),
li(cls := "todo-active", a(if (state == "active") cls := "selected" else (), "Active")),
li(
cls := "todo-completed",
a(if (state == "completed") cls := "selected" else (), "Completed")
)
),
button(cls := "clear-completed","Clear completed")
button(cls := "clear-completed", "Clear completed")
)
)
}

@cask.get("/")
def index() = {
doctype("html")(
html(lang := "en",
html(
lang := "en",
head(
meta(charset := "utf-8"),
meta(name := "viewport", content := "width=device-width, initial-scale=1"),
Expand All @@ -127,14 +128,11 @@ object WebApp extends cask.MainRoutes{
),
body(
tags2.section(cls := "todoapp", renderBody("all")),
footer(cls := "info",
footer(
cls := "info",
p("Double-click to edit a todo"),
p("Created by ",
a(href := "http://todomvc.com","Li Haoyi")
),
p("Part of ",
a(href := "http://todomvc.com","TodoMVC")
)
p("Created by ", a(href := "http://todomvc.com", "Li Haoyi")),
p("Part of ", a(href := "http://todomvc.com", "TodoMVC"))
),
script(src := hashedResource("/static/main.js"))
)
Expand Down
19 changes: 9 additions & 10 deletions example/scalalib/web/4-webapp-scalajs/src/WebApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package webapp
import scalatags.Text.all._
import scalatags.Text.tags2

object WebApp extends cask.MainRoutes{
object WebApp extends cask.MainRoutes {
override def port = 8082
case class Todo(checked: Boolean, text: String)

Expand Down Expand Up @@ -50,7 +50,7 @@ object WebApp extends cask.MainRoutes{
}

def renderBody(state: String) = {
val filteredTodos = state match{
val filteredTodos = state match {
case "all" => todos.zipWithIndex
case "active" => todos.zipWithIndex.filter(!_._1.checked)
case "completed" => todos.zipWithIndex.filter(_._1.checked)
Expand All @@ -67,9 +67,9 @@ object WebApp extends cask.MainRoutes{
`type` := "checkbox",
if (todos.filter(_.checked).size != 0) checked else ()
),
label(`for` := "toggle-all","Mark all as complete"),
label(`for` := "toggle-all", "Mark all as complete"),
ul(cls := "todo-list")(
for((todo, index) <- filteredTodos) yield li(
for ((todo, index) <- filteredTodos) yield li(
if (todo.checked) cls := "completed" else (),
div(cls := "view")(
input(
Expand All @@ -94,10 +94,9 @@ object WebApp extends cask.MainRoutes{
li(cls := "todo-all")(
a(if (state == "all") cls := "selected" else ())("All")
),
li(cls := "todo-active",
a(if (state == "active") cls := "selected" else ())("Active")
),
li(cls := "todo-completed",
li(cls := "todo-active", a(if (state == "active") cls := "selected" else ())("Active")),
li(
cls := "todo-completed",
a(if (state == "completed") cls := "selected" else ())("Completed")
)
),
Expand All @@ -120,8 +119,8 @@ object WebApp extends cask.MainRoutes{
tags2.section(cls := "todoapp", renderBody("all")),
footer(cls := "info")(
p("Double-click to edit a todo"),
p("Created by ", a(href := "http://todomvc.com","Li Haoyi")),
p("Part of ", a(href := "http://todomvc.com","TodoMVC"))
p("Created by ", a(href := "http://todomvc.com", "Li Haoyi")),
p("Part of ", a(href := "http://todomvc.com", "TodoMVC"))
),
script(src := "/static/main.js")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import scalatags.Text.all._
import scalatags.Text.tags2
import shared.{Shared, Todo}

object WebApp extends cask.MainRoutes{
object WebApp extends cask.MainRoutes {
override def port = 8083
var todos = Seq(
Todo(true, "Get started with Cask"),
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 028abe4

Please sign in to comment.