|
| 1 | +import ch.epfl.scala.githubapi.DependencyRelationship |
| 2 | +import ch.epfl.scala.githubapi.DependencyScope |
| 3 | +import ch.epfl.scala.githubapi.Manifest |
| 4 | +import ch.epfl.scala.SubmitInput |
| 5 | +import sjsonnew.shaded.scalajson.ast.unsafe.JString |
| 6 | + |
| 7 | +val checkTest = taskKey[Unit]("Check munit_3 is in the manifest ") |
| 8 | +val ignoreTestConfig = taskKey[StateTransform]("Ignore the test config in the submit input") |
| 9 | +val checkIgnoreTest = taskKey[Unit]("Check scaladoc_3 is absent in the manifest") |
| 10 | + |
| 11 | +inThisBuild( |
| 12 | + Seq( |
| 13 | + organization := "ch.epfl.scala", |
| 14 | + version := "1.2.0-SNAPSHOT", |
| 15 | + scalaVersion := "3.2.1" |
| 16 | + ) |
| 17 | +) |
| 18 | + |
| 19 | +Global / ignoreTestConfig := { |
| 20 | + val input = SubmitInput(None, Vector.empty, ignoredConfigs = Vector("test")) |
| 21 | + StateTransform(state => state.put(githubSubmitInputKey, input)) |
| 22 | +} |
| 23 | + |
| 24 | +lazy val p1 = project |
| 25 | + .in(file("p1")) |
| 26 | + .settings( |
| 27 | + libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test, |
| 28 | + checkTest := { |
| 29 | + val manifest = githubDependencyManifest.value.get |
| 30 | + checkDependency(manifest, "org.scalameta:munit_3:0.7.29")( |
| 31 | + expectedRelationship = DependencyRelationship.direct, |
| 32 | + expectedScope = DependencyScope.development, |
| 33 | + expectedConfig = "test" |
| 34 | + ) |
| 35 | + }, |
| 36 | + checkIgnoreTest := { |
| 37 | + val manifest = githubDependencyManifest.value.get |
| 38 | + val suspicious = manifest.resolved.keys.filter(dep => dep.contains("munit_3")) |
| 39 | + assert(suspicious.isEmpty, s"The manifest should not contain munit_3, found ${suspicious.mkString(", ")}") |
| 40 | + } |
| 41 | + ) |
| 42 | + |
| 43 | +def checkDependency(manifest: Manifest, name: String)( |
| 44 | + expectedRelationship: DependencyRelationship = DependencyRelationship.direct, |
| 45 | + expectedScope: DependencyScope = DependencyScope.runtime, |
| 46 | + expectedConfig: String = "compile", |
| 47 | + expectedDeps: Seq[String] = Seq.empty |
| 48 | +): Unit = { |
| 49 | + val node = manifest.resolved(name) |
| 50 | + assert(node.package_url.startsWith("pkg:maven/"), s"Wrong package_url for node $name: ${node.package_url}") |
| 51 | + assert(node.relationship.contains(expectedRelationship), s"Wrong relationship for node $name: ${node.relationship}") |
| 52 | + assert(node.scope.contains(expectedScope), s"Wrong scope for node $name: ${node.scope}") |
| 53 | + val configurations = node.metadata.get("config").collect { case JString(c) => c } |
| 54 | + assert(configurations.contains(expectedConfig), s"Wrong config in metadata for node $name: $configurations") |
| 55 | + expectedDeps.foreach(d => assert(node.dependencies.contains(d), s"missing dependency $d in node $name")) |
| 56 | +} |
0 commit comments