From 72d0ac972839698cfec5bd266a878a8a0278bd97 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 15 Aug 2016 16:14:32 +0200 Subject: [PATCH] Move tests with external requirements to it tests --- .ci/travis.sh | 2 +- appveyor.yml | 4 +- build.sbt | 6 +- .../test/HttpAuthenticationTests.scala | 70 +++++++++ .../scala/coursier/test/IvyLocalTests.scala | 0 .../scala/coursier/test/CacheFetchTests.scala | 144 ++++++------------ 6 files changed, 121 insertions(+), 105 deletions(-) create mode 100644 tests/jvm/src/it/scala/coursier/test/HttpAuthenticationTests.scala rename tests/jvm/src/{test => it}/scala/coursier/test/IvyLocalTests.scala (100%) diff --git a/.ci/travis.sh b/.ci/travis.sh index de3cc7fcb..ad114ebfe 100755 --- a/.ci/travis.sh +++ b/.ci/travis.sh @@ -41,7 +41,7 @@ function isMasterOrDevelop() { # TODO Add coverage once https://github.com/scoverage/sbt-scoverage/issues/111 is fixed -SBT_COMMANDS="compile test" +SBT_COMMANDS="compile test it:test" if echo "$TRAVIS_SCALA_VERSION" | grep -q "^2\.10"; then SBT_COMMANDS="$SBT_COMMANDS publishLocal" # to make the scripted tests happy diff --git a/appveyor.yml b/appveyor.yml index d3609cd8e..dea810fd2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,8 +20,8 @@ build_script: - sbt ++2.10.6 coreJVM/publishLocal cache/publishLocal # to make the scripted tests happy test_script: - ps: Start-Job { & java -jar -noverify C:\projects\coursier\coursier launch -r http://dl.bintray.com/scalaz/releases io.get-coursier:http-server-java7_2.11:1.0.0-SNAPSHOT -- -d /C:/projects/coursier/tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm -v } - - sbt ++2.11.8 testsJVM/test # Would node be around for testsJS/test? - - sbt ++2.10.6 testsJVM/test plugin/scripted + - sbt ++2.11.8 testsJVM/test testsJVM/it:test # Would node be around for testsJS/test? + - sbt ++2.10.6 testsJVM/test testsJVM/it:test plugin/scripted cache: - C:\sbt\ - C:\Users\appveyor\.ivy2 diff --git a/build.sbt b/build.sbt index 7c3e04dea..9e3b2d527 100644 --- a/build.sbt +++ b/build.sbt @@ -6,6 +6,8 @@ import MimaKeys.{ previousArtifacts, binaryIssueFilters } val binaryCompatibilityVersion = "1.0.0-M7" +lazy val IntegrationTest = config("it") extend Test + lazy val releaseSettings = Seq( publishMavenStyle := true, licenses := Seq("Apache 2.0" -> url("http://opensource.org/licenses/Apache-2.0")), @@ -249,11 +251,13 @@ lazy val tests = crossProject .dependsOn(core) .settings(commonSettings: _*) .settings(noPublishSettings: _*) + .configs(IntegrationTest) + .settings(Defaults.itSettings: _*) .settings( name := "coursier-tests", libraryDependencies ++= Seq( "org.scala-lang.modules" %% "scala-async" % "0.9.5" % "provided", - "com.lihaoyi" %%% "utest" % "0.4.3" % "test" + "com.lihaoyi" %%% "utest" % "0.4.3" % "test,it" ), unmanagedResourceDirectories in Test += (baseDirectory in LocalRootProject).value / "tests" / "shared" / "src" / "test" / "resources", testFrameworks += new TestFramework("utest.runner.Framework") diff --git a/tests/jvm/src/it/scala/coursier/test/HttpAuthenticationTests.scala b/tests/jvm/src/it/scala/coursier/test/HttpAuthenticationTests.scala new file mode 100644 index 000000000..6874924e3 --- /dev/null +++ b/tests/jvm/src/it/scala/coursier/test/HttpAuthenticationTests.scala @@ -0,0 +1,70 @@ +package coursier.test + +import utest._ + +import coursier.core.Authentication +import coursier.maven.MavenRepository + +object HttpAuthenticationTests extends TestSuite { + + val tests = TestSuite { + 'httpAuthentication - { + // requires an authenticated HTTP server to be running on localhost:8080 with user 'user' + // and password 'pass' + + val address = "localhost:8080" + val user = "user" + val password = "pass" + + def printErrorMessage() = + Console.err.println( + Console.RED + + s"HTTP authentication tests require a running HTTP server on $address, requiring " + + s"basic authentication with user '$user' and password '$password', serving the right " + + "files.\n" + Console.RESET + + "Run one from the coursier sources with\n" + + " ./coursier launch -r http://dl.bintray.com/scalaz/releases " + + "io.get-coursier:simple-web-server_2.11:1.0.0-M12 -- " + + "-d tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm -v" + ) + + * - { + // no authentication -> should fail + + val failed = try { + CacheFetchTests.check( + MavenRepository( + s"http://$address" + ) + ) + + printErrorMessage() + false + } catch { + case e: Throwable => + true + } + + assert(failed) + } + + * - { + // with authentication -> should work + + try { + CacheFetchTests.check( + MavenRepository( + s"http://$address", + authentication = Some(Authentication(user, password)) + ) + ) + } catch { + case e: Throwable => + printErrorMessage() + throw e + } + } + } + } + +} diff --git a/tests/jvm/src/test/scala/coursier/test/IvyLocalTests.scala b/tests/jvm/src/it/scala/coursier/test/IvyLocalTests.scala similarity index 100% rename from tests/jvm/src/test/scala/coursier/test/IvyLocalTests.scala rename to tests/jvm/src/it/scala/coursier/test/IvyLocalTests.scala diff --git a/tests/jvm/src/test/scala/coursier/test/CacheFetchTests.scala b/tests/jvm/src/test/scala/coursier/test/CacheFetchTests.scala index ab2cdc73e..6525a3c5a 100644 --- a/tests/jvm/src/test/scala/coursier/test/CacheFetchTests.scala +++ b/tests/jvm/src/test/scala/coursier/test/CacheFetchTests.scala @@ -13,55 +13,55 @@ import scala.util.Try object CacheFetchTests extends TestSuite { - val tests = TestSuite { + def check(extraRepo: Repository): Unit = { - def check(extraRepo: Repository): Unit = { + val tmpDir = Files.createTempDirectory("coursier-cache-fetch-tests").toFile - val tmpDir = Files.createTempDirectory("coursier-cache-fetch-tests").toFile + def cleanTmpDir() = { + def delete(f: File): Boolean = + if (f.isDirectory) { + val removedContent = Option(f.listFiles()).toSeq.flatten.map(delete).forall(x => x) + val removedDir = f.delete() - def cleanTmpDir() = { - def delete(f: File): Boolean = - if (f.isDirectory) { - val removedContent = Option(f.listFiles()).toSeq.flatten.map(delete).forall(x => x) - val removedDir = f.delete() + removedContent && removedDir + } else + f.delete() - removedContent && removedDir - } else - f.delete() - - if (!delete(tmpDir)) - Console.err.println(s"Warning: unable to remove temporary directory $tmpDir") - } - - val res = try { - val fetch = Fetch.from( - Seq( - extraRepo, - MavenRepository("https://repo1.maven.org/maven2") - ), - Cache.fetch( - tmpDir - ) - ) - - val startRes = Resolution( - Set( - Dependency( - Module("com.github.alexarchambault", "coursier_2.11"), "1.0.0-M9-test" - ) - ) - ) - - startRes.process.run(fetch).run - } finally { - cleanTmpDir() - } - - val errors = res.errors - - assert(errors.isEmpty) + if (!delete(tmpDir)) + Console.err.println(s"Warning: unable to remove temporary directory $tmpDir") } + val res = try { + val fetch = Fetch.from( + Seq( + extraRepo, + MavenRepository("https://repo1.maven.org/maven2") + ), + Cache.fetch( + tmpDir + ) + ) + + val startRes = Resolution( + Set( + Dependency( + Module("com.github.alexarchambault", "coursier_2.11"), "1.0.0-M9-test" + ) + ) + ) + + startRes.process.run(fetch).run + } finally { + cleanTmpDir() + } + + val errors = res.errors + + assert(errors.isEmpty) + } + + val tests = TestSuite { + // using scala-test would allow to put the below comments in the test names... * - { @@ -84,64 +84,6 @@ object CacheFetchTests extends TestSuite { check(MavenRepository(s"${TestprotocolHandler.protocol}://foo/")) } } - - 'httpAuthentication - { - // requires an authenticated HTTP server to be running on localhost:8080 with user 'user' - // and password 'pass' - - val address = "localhost:8080" - val user = "user" - val password = "pass" - - def printErrorMessage() = - Console.err.println( - Console.RED + - s"HTTP authentication tests require a running HTTP server on $address, requiring " + - s"basic authentication with user '$user' and password '$password', serving the right " + - "files.\n" + Console.RESET + - "Run one from the coursier sources with\n" + - " ./coursier launch -r http://dl.bintray.com/scalaz/releases " + - "io.get-coursier:simple-web-server_2.11:1.0.0-M12 -- " + - "-d tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm -v" - ) - - * - { - // no authentication -> should fail - - val failed = try { - check( - MavenRepository( - s"http://$address" - ) - ) - - printErrorMessage() - false - } catch { - case e: Throwable => - true - } - - assert(failed) - } - - * - { - // with authentication -> should work - - try { - check( - MavenRepository( - s"http://$address", - authentication = Some(Authentication(user, password)) - ) - ) - } catch { - case e: Throwable => - printErrorMessage() - throw e - } - } - } } }