Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion core/docs/_docs/contributing/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ Please note that testing runtime involves doing the delicate compilation dance l
Testing code is generally stored in the `core` project under `core/test/src`. Java 17, Java 19, and runtime specific tests may exist in the future, but at the moment, all implementations use a generic testing base.

Tests in Slinc use munit and scalacheck. One can read how to use munit with scalacheck [here](https://scalameta.org/munit/docs/integrations/scalacheck.html) and how to use scalacheck [here](https://github.com/typelevel/scalacheck/blob/main/doc/UserGuide.md).
### ReadWriteModule Tests

The `ReadWriteModule` now has a suite of unit tests that cover all its functions. These tests can be run with the command `./mill core.test`. The tests verify the functionality of reading and writing to memory, as well as handling of unions and arrays.

In order to develop a new test suite for Slinc, add the implementation to `core/test/src`. If the test suite is testing an implementation in `core` then one can define it in the normal way specified by the munit documentation. However, if it's meant to be a test of Slinc implementations, it should be defined in a generic fashion like so:

Expand Down Expand Up @@ -173,4 +175,22 @@ trait MySuite(s: Slinc) extends ScalacheckSuite:
}
}
}
```
```
trait MySuite(s: Slinc) extends ScalacheckSuite:
import s.{*, given}
val ptr = Ptr.blank[CInt]

!ptr = 4
!ptr

property("myProperty") {
forAll{
(i: Int) =>
Scope.confined{
val ptr = Ptr.blank[CInt]

!ptr = i
assertEquals(!ptr, i)
}
}
}
44 changes: 44 additions & 0 deletions core/test/src/fr/hammons/slinc/modules/ReadWriteModuleSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package fr.hammons.slinc.modules

import munit.FunSuite
import fr.hammons.slinc.modules.ReadWriteModule

class ReadWriteModuleSpec extends FunSuite {
val descriptor = // create a TypeDescriptor
val reader = ReadWriteModule.unionReader(descriptor)
// assert that the reader behaves as expected
}
val descriptor = // create a TypeDescriptor
val writer = ReadWriteModule.unionWriter(descriptor)
// assert that the writer behaves as expected
}
val mem = // create a Mem
val bytes = // create Bytes
val descriptor = // create a TypeDescriptor
ReadWriteModule.write(mem, bytes, descriptor)
// assert that the memory was written to as expected
}
test("writeArray writes to memory as expected") {
// create necessary inputs
// call writeArray
// assert that the memory was written to as expected
}

test("read reads from memory as expected") {
// create necessary inputs
// call read
// assert that the output is as expected
}

test("readArray reads from memory as expected") {
// create necessary inputs
// call readArray
// assert that the output is as expected
}

test("readFn reads from memory as expected") {
// create necessary inputs
// call readFn
// assert that the output is as expected
}
}