Skip to content

Commit

Permalink
add tests.sc to split tests from common.sc
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Jan 20, 2024
1 parent 1634320 commit 60da186
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 80 deletions.
34 changes: 29 additions & 5 deletions build.sc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import mill._
import mill.scalalib._
import mill.scalalib.TestModule._
import mill.scalalib.publish._
import mill.scalalib.scalafmt._
import coursier.maven.MavenRepository
import mill.define.Cross
import mill.scalalib.api.ZincWorkerUtil.matchingVersions
import $file.common
import $file.tests

object v {
val pluginScalaCrossVersions = Seq(
Expand Down Expand Up @@ -65,7 +65,7 @@ trait Svsim
object firrtlut extends Cross[FirrtlUnitTest](v.scalaCrossVersions)

trait FirrtlUnitTest
extends common.FirrtlUnitTestModule
extends tests.FirrtlUnitTestModule
with CrossModuleBase
with ScalafmtModule {
override def millSourcePath = firrtl(crossScalaVersion).millSourcePath
Expand Down Expand Up @@ -185,7 +185,7 @@ trait Chisel
object chiselut extends Cross[ChiselUnitTest](v.scalaCrossVersions)

trait ChiselUnitTest
extends common.ChiselUnitTestModule
extends tests.ChiselUnitTestModule
with CrossModuleBase
with ScalafmtModule {
override def millSourcePath = chisel(crossScalaVersion).millSourcePath
Expand Down Expand Up @@ -256,7 +256,7 @@ trait CIRCTPanamaBinder
object bindertest extends Cross[CIRCTPanamaBinderModuleTest](v.scalaCrossVersions)

trait CIRCTPanamaBinderModuleTest
extends common.CIRCTPanamaBinderModuleTestModule
extends tests.CIRCTPanamaBinderModuleTestModule
with CrossModuleBase
with ScalafmtModule {
override def millSourcePath = circtpanamabinder(crossScalaVersion).millSourcePath
Expand All @@ -271,3 +271,27 @@ trait CIRCTPanamaBinderModuleTest
Seq(PathRef(millSourcePath / "src" / "test"))
}
}

object litutility extends Cross[LitUtility](v.scalaCrossVersions)

trait LitUtility
extends tests.LitUtilityModule
with CrossModuleBase
with ScalafmtModule {
def millSourcePath = super.millSourcePath / "litutility"
def circtPanamaBinderModule = circtpanamabinder(crossScalaVersion)
}

object lit extends Cross[Lit](v.scalaCrossVersions)

trait Lit
extends tests.LitModule
with Cross.Module[String] {
def scalaVersion: T[String] = crossValue
def runClasspath: T[Seq[os.Path]] = T(litutility(crossValue).runClasspath().map(_.path))
def pluginJars: T[Seq[os.Path]] = T(Seq(litutility(crossValue).circtPanamaBinderModule.pluginModule.jar().path))
def javaLibraryPath: T[Seq[os.Path]] = T(litutility(crossValue).circtPanamaBinderModule.libraryPaths().map(_.path))
def javaHome: T[os.Path] = T(os.Path(sys.props("java.home")))
def chiselLitDir: T[os.Path] = T(millSourcePath)
def litConfigIn: T[PathRef] = T.source(millSourcePath / "tests" / "lit.site.cfg.py.in")
}
75 changes: 0 additions & 75 deletions common.sc
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,6 @@ trait SvsimModule
extends ScalaModule {
}

trait SvsimUnitTestModule
extends TestModule
with ScalaModule
with TestModule.ScalaTest {
def svsimModule: SvsimModule

def scalatestIvy: Dep

def scalacheckIvy: Dep

override def moduleDeps = Seq(svsimModule)

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait FirrtlUnitTestModule
extends TestModule
with ScalaModule
with TestModule.ScalaTest {
def firrtlModule: FirrtlModule

def scalatestIvy: Dep

def scalacheckIvy: Dep

override def moduleDeps = Seq(firrtlModule)

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait CoreModule
extends ScalaModule
with HasMacroAnnotations {
Expand Down Expand Up @@ -158,24 +118,6 @@ trait HasChisel
override def moduleDeps = super.moduleDeps ++ Some(chiselModule)
}

trait ChiselUnitTestModule
extends TestModule
with ScalaModule
with HasChisel
with HasMacroAnnotations
with TestModule.ScalaTest {
def scalatestIvy: Dep

def scalacheckIvy: Dep

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait HasJextractGeneratedSources
extends JavaModule {
def includePaths: T[Seq[PathRef]]
Expand Down Expand Up @@ -280,20 +222,3 @@ trait HasCIRCTPanamaBinderModule
)
}

trait CIRCTPanamaBinderModuleTestModule
extends TestModule
with ScalaModule
with HasCIRCTPanamaBinderModule
with HasMacroAnnotations
with TestModule.ScalaTest {
def scalatestIvy: Dep

def scalacheckIvy: Dep

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}
114 changes: 114 additions & 0 deletions tests.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import mill._
import mill.api.Result
import mill.scalalib._
import mill.scalalib.api.CompilationResult
import mill.util.Jvm

import java.util
import scala.jdk.StreamConverters.StreamHasToScala

trait SvsimUnitTestModule
extends TestModule
with ScalaModule
with TestModule.ScalaTest {
def svsimModule: common.SvsimModule

def scalatestIvy: Dep

def scalacheckIvy: Dep

override def moduleDeps = Seq(svsimModule)

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait FirrtlUnitTestModule
extends TestModule
with ScalaModule
with TestModule.ScalaTest {
def firrtlModule: common.FirrtlModule

def scalatestIvy: Dep

def scalacheckIvy: Dep

override def moduleDeps = Seq(firrtlModule)

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait ChiselUnitTestModule
extends TestModule
with ScalaModule
with common.HasChisel
with common.HasMacroAnnotations
with TestModule.ScalaTest {
def scalatestIvy: Dep

def scalacheckIvy: Dep

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait CIRCTPanamaBinderModuleTestModule
extends TestModule
with ScalaModule
with common.HasCIRCTPanamaBinderModule
with common.HasMacroAnnotations
with TestModule.ScalaTest {
def scalatestIvy: Dep

def scalacheckIvy: Dep

override def defaultCommandName() = "test"

override def ivyDeps = super.ivyDeps() ++ Agg(
scalatestIvy,
scalacheckIvy
)
}

trait LitUtilityModule
extends ScalaModule
with common.HasCIRCTPanamaBinderModule
with common.HasMacroAnnotations

trait LitModule
extends Module {
def scalaVersion: T[String]
def runClasspath: T[Seq[os.Path]]
def pluginJars: T[Seq[os.Path]]
def javaLibraryPath: T[Seq[os.Path]]
def javaHome: T[os.Path]
def chiselLitDir: T[os.Path]
def litConfigIn: T[PathRef]
def litConfig: T[PathRef] = T {
os.write(
T.dest / "lit.site.cfg.py",
os.read(litConfigIn().path)
.replaceAll("@SCALA_VERSION@", scalaVersion())
.replaceAll("@RUN_CLASSPATH@", runClasspath().mkString(","))
.replaceAll("@SCALA_PLUGIN_JARS@", pluginJars().mkString(","))
.replaceAll("@JAVA_HOME@", javaHome().toString)
.replaceAll("@JAVA_LIBRARY_PATH@", javaLibraryPath().mkString(","))
.replaceAll("@CHISEL_LIT_DIR@", chiselLitDir().toString)
)
PathRef(T.dest)
}
def run(args: String*) = T.command(os.proc("lit", litConfig().path).call(T.dest, stdout = os.ProcessOutput.Readlines(line => T.ctx().log.info("[lit] " + line))))
}

0 comments on commit 60da186

Please sign in to comment.