Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nadavwr/makeshift
Makeshift unit testing library for Scala Native
https://github.com/nadavwr/makeshift
mit-license scala-native unit-testing
Last synced: 25 days ago
JSON representation
Makeshift unit testing library for Scala Native
- Host: GitHub
- URL: https://github.com/nadavwr/makeshift
- Owner: nadavwr
- Created: 2017-04-27T14:23:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-10T23:32:18.000Z (almost 7 years ago)
- Last Synced: 2024-04-22T13:32:45.566Z (8 months ago)
- Topics: mit-license, scala-native, unit-testing
- Language: Scala
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-scala-native - Makeshift - Library for unit tests. (Unit Tests)
README
A unit testing library I quickly hacked together for personal use, until one of the established libraries becomes available for Scala Native.
To use it:
```scala
resolvers += Resolver.bintrayRepo("nadavwr", "maven")
libraryDependencies += "com.github.nadavwr" %%% "makeshift" % "0.1.1"
```* Unit tests are aggregated under `Spec` instances.
* Each unit test makes use of a `Fixture`
* Using fixtures enables sharing code across test cases, as well as orderly resource initialization and cleanup.
* The method `assertThat()` provides some rudimentary papertrail for what specific checks pass/fail. Make sure your terminal can render π and β.
* No effort is made by the library to aggregate specs into test suites. Having a `Spec` extend `App` has been a guilty pleasure for me so far.
* SBT test framework integration isn't there yet, so just place your specs in a separate module and plain-old `run` them.Given a heap-allocated buffer such as the following:
```scala
class Buffer(val size: Int) {
import scalanative.native._
val ptr: Ptr[Byte] = stdlib.malloc(1024)
def dispose(): Unit = stdlib.free(ptr)def put(bytes: Array[Byte]): Unit =
bytes.zipWithIndex.foreach { case (b, i) => !(ptr+i) = b }
def get(size: Int): Array[Byte] = {
val out = new Array[Byte](size)
for (i <- 0 until size) {
out(i) = !(ptr+i)
}
out
}
}
```It can be tested as seen below:
```scala
import com.github.nadavwr.makeshift._object MySpec extends Spec with App {
trait BufferFixture extends Fixture {
lazy val buffer = new Buffer(1024)
.withCleanup("buffer") { _.dispose() }
}test("manipulate heap memory") runWith new BufferFixture {
val message = "hello"
val messageBytes = message.toArray.map(_.toByte)
buffer.put(messageBytes)
val output = buffer.get(messageBytes.length)
assertThat(output sameElements messageBytes,
s"buffer should be assigned expected value '$message'")
}
}
```producing the following output:
```
_______________________
βmanipulate heap memory
bufer created
π buffer should be assigned expected value 'hello'
π
cleaning up bufer
```See more usage examples in [SampleSpec](sample/src/main/scala/com/github/nadavwr/makeshift/SampleSpec.scala)