Skip to content

Commit

Permalink
Merge pull request #5 from ryan-williams/misc
Browse files Browse the repository at this point in the history
1.1.2: plugin upgrade, resource, matcher, dependency improvements
  • Loading branch information
ryan-williams committed Dec 30, 2016
2 parents 3647aed + 3f30580 commit a482e56
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 44 deletions.
13 changes: 9 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name := "test-utils"
version := "1.1.1"
crossScalaVersions += "2.12.1"
version := "1.1.3-SNAPSHOT"

addScala212

libraryDependencies ++= Seq(
libraries.value('scalatest),
"commons-io" % "commons-io" % "2.4"
libs.value('commons_io),
libs.value('scalatest)
)

// Don't inherit default test-deps from parent plugin.
testDeps := Seq()
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.13
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("org.hammerlab" % "sbt-parent" % "1.3.0")
addSbtPlugin("org.hammerlab" % "sbt-parent" % "1.5.2")
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package org.hammerlab.test.matchers.seqs

import org.scalatest.matchers.{ MatchResult, Matcher }

// Operate on common superclass of collection.{im,}mutable.Map
import collection.Map

case class MapMatcher[K: Ordering, V: Ordering](expected: Map[K, V]) extends Matcher[Map[K, V]] {
val seqMatcher = PairSeqMatcher[K, V](expected.toSeq, matchOrder = false)

Expand All @@ -12,4 +15,5 @@ case class MapMatcher[K: Ordering, V: Ordering](expected: Map[K, V]) extends Mat

object MapMatcher {
def mapMatch[K: Ordering, V: Ordering](expected: Map[K, V]): Matcher[Map[K, V]] = MapMatcher(expected)
def mapMatch[K: Ordering, V: Ordering](expected: (K, V)*): Matcher[Map[K, V]] = MapMatcher(expected.toMap)
}
1 change: 1 addition & 0 deletions src/main/scala/org/hammerlab/test/resources/File.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ class File private(val path: String) extends AnyVal {

object File {
def apply(path: String): File = new File(Url(path).getFile)
implicit def unmake(file: File): String = file.path
}
7 changes: 6 additions & 1 deletion src/main/scala/org/hammerlab/test/resources/Url.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package org.hammerlab.test.resources

import java.io.FileNotFoundException
import java.net.URL

object Url {
def apply(path: String): URL = {
Thread.currentThread().getContextClassLoader.getResource(path)
Option(Thread.currentThread().getContextClassLoader.getResource(path)) match {
case Some(url) url
case None
throw new FileNotFoundException(s"Test resource not found: $path")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hammerlab.test.matchers.seqs

import org.hammerlab.test.matchers.utils.MatcherResultTest
import MapMatcher.mapMatch

class MapMatcherTest extends MatcherResultTest {

Expand All @@ -22,33 +23,33 @@ class MapMatcherTest extends MatcherResultTest {

test("single match") {
check(
"a" -> 1
"a" 1
)(
"a" -> 1
"a" 1
)()
}

test("multiple match") {
check(
"a" -> 1,
"b" -> 2,
"c" -> 3
"a" 1,
"b" 2,
"c" 3
)(
"a" -> 1,
"b" -> 2,
"c" -> 3
"a" 1,
"b" 2,
"c" 3
)()
}

test("single differing key") {
check(
"a" -> 1,
"b" -> 2,
"c" -> 3
"a" 1,
"b" 2,
"c" 3
)(
"a" -> 1,
"b" -> 4,
"c" -> 3
"a" 1,
"b" 4,
"c" 3
)(
"""Sequences didn't match!
|
Expand All @@ -60,13 +61,13 @@ class MapMatcherTest extends MatcherResultTest {

test("multiple differing keys") {
check(
"a" -> 1,
"b" -> 2,
"c" -> 3
"a" 1,
"b" 2,
"c" 3
)(
"a" -> 1,
"b" -> 4,
"c" -> 5
"a" 1,
"b" 4,
"c" 5
)(
"""Sequences didn't match!
|
Expand All @@ -78,7 +79,7 @@ class MapMatcherTest extends MatcherResultTest {
}

test("empty vs single elem") {
check()("a" -> 1)(
check()("a" 1)(
"""Sequences didn't match!
|
|Extra elems:
Expand All @@ -88,7 +89,7 @@ class MapMatcherTest extends MatcherResultTest {
}

test("single elem vs empty") {
check("a" -> 1)()(
check("a" 1)()(
"""Sequences didn't match!
|
|Missing elems:
Expand All @@ -99,13 +100,13 @@ class MapMatcherTest extends MatcherResultTest {

test("missing and extra elems") {
check(
"a" -> 1,
"b" -> 2,
"c" -> 3
"a" 1,
"b" 2,
"c" 3
)(
"d" -> 4,
"a" -> 1,
"e" -> 5
"d" 4,
"a" 1,
"e" 5
)(
"""Sequences didn't match!
|
Expand All @@ -122,23 +123,33 @@ class MapMatcherTest extends MatcherResultTest {

test("two out of order elems") {
check(
"a" -> 1,
"b" -> 2
"a" 1,
"b" 2
)(
"b" -> 2,
"a" -> 1
"b" 2,
"a" 1
)()
}

test("three out of order elems") {
check(
"a" -> 1,
"b" -> 2,
"a" -> 3
"a" 1,
"b" 2,
"a" 3
)(
"b" -> 2,
"a" -> 1,
"a" -> 3
"b" 2,
"a" 1,
"a" 3
)()
}

test("mapMatch map") {
Map(1 "a", 2 "b") should mapMatch(Map(2 "b", 1 "a"))
Map(1 "a", 2 "b") should not(mapMatch(Map(2 "b", 1 "c")))
}

test("mapMatch varargs") {
Map(1 "a", 2 "b") should mapMatch(2 "b", 1 "a")
Map(1 "a", 2 "b") should not(mapMatch(2 "b", 1 "c"))
}
}
37 changes: 37 additions & 0 deletions src/test/scala/org/hammerlab/test/resources/ResourcesTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.hammerlab.test.resources

import java.io.FileNotFoundException

import org.hammerlab.test.Suite

class ResourcesTest extends Suite {
test("non-existent url") {
intercept[FileNotFoundException] {
Url("foo")
}
}

test("non-existent file") {
intercept[FileNotFoundException] {
File("foo")
}
}

test("read file") {
File("a/numbers").read should ===(
"""1
|2
|3
|""".stripMargin
)
}

test("read file bytes") {
File("a/numbers").readBytes should ===(
"""1
|2
|3
|""".stripMargin.getBytes
)
}
}

0 comments on commit a482e56

Please sign in to comment.