1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-31 21:52:59 +00:00

Add a whole bunch of tests

Coverage graph goes woosh. Hopefully.

More importantly, all of these are historic regressions, so very much
worth tracking.
This commit is contained in:
Jonathan Coates
2021-01-19 20:02:45 +00:00
parent 657ceda3af
commit eaa7359c8c
22 changed files with 3287 additions and 18 deletions

View File

@@ -10,7 +10,7 @@ class ComputerTest {
/**
* Ensures redstone signals do not travel through computers.
*
* @see [Issue #548](https://github.com/SquidDev-CC/CC-Tweaked/issues/548)
* @see [#548](https://github.com/SquidDev-CC/CC-Tweaked/issues/548)
*/
@GameTest
suspend fun `No through signal`(context: TestContext) {

View File

@@ -0,0 +1,27 @@
package dan200.computercraft.ingame
import dan200.computercraft.ingame.api.*
import net.minecraft.entity.item.ItemEntity
import net.minecraft.item.Items
import net.minecraft.util.math.BlockPos
import org.junit.jupiter.api.Assertions.assertEquals
class DiskDriveTest {
/**
* Ensure audio disks exist and we can play them.
*
* @see [#688](https://github.com/SquidDev-CC/CC-Tweaked/issues/688)
*/
@GameTest
suspend fun `Audio disk`(context: TestContext) = context.checkComputerOk(3)
@GameTest
suspend fun `Ejects disk`(context: TestContext) {
val stackAt = BlockPos(2, 0, 2)
context.checkComputerOk(4)
context.waitUntil { context.getEntity(stackAt) != null }
val stack = context.getEntityOfType<ItemEntity>(stackAt)!!
assertEquals(Items.MUSIC_DISC_13, stack.item.item, "Correct item stack")
}
}

View File

@@ -7,4 +7,44 @@ import dan200.computercraft.ingame.api.checkComputerOk
class TurtleTest {
@GameTest(required = false)
suspend fun `Unequip refreshes peripheral`(context: TestContext) = context.checkComputerOk(1)
/**
* Checks turtles can sheer sheep (and drop items)
*
* @see [#537](https://github.com/SquidDev-CC/CC-Tweaked/issues/537)
*/
@GameTest(required = false)
suspend fun `Shears sheep`(context: TestContext) = context.checkComputerOk(5)
/**
* Checks turtles can place lava.
*
* @see [#518](https://github.com/SquidDev-CC/CC-Tweaked/issues/518)
*/
@GameTest(required = false)
suspend fun `Place lava`(context: TestContext) = context.checkComputerOk(5)
/**
* Checks turtles can place when waterlogged.
*
* @see [#385](https://github.com/SquidDev-CC/CC-Tweaked/issues/385)
*/
@GameTest(required = false)
suspend fun `Place waterlogged`(context: TestContext) = context.checkComputerOk(7)
/**
* Checks turtles can place when waterlogged.
*
* @see [#297](https://github.com/SquidDev-CC/CC-Tweaked/issues/297)
*/
@GameTest(required = false)
suspend fun `Gather lava`(context: TestContext) = context.checkComputerOk(8)
/**
* Checks turtles can place when waterlogged.
*
* @see [#258](https://github.com/SquidDev-CC/CC-Tweaked/issues/258)
*/
@GameTest(required = false)
suspend fun `Hoe dirt`(context: TestContext) = context.checkComputerOk(9)
}

View File

@@ -3,6 +3,9 @@ package dan200.computercraft.ingame.api
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.delay
import net.minecraft.block.BlockState
import net.minecraft.entity.Entity
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.math.AxisAlignedBB
import net.minecraft.util.math.BlockPos
/**
@@ -37,7 +40,7 @@ suspend fun TestContext.sleep(ticks: Int = 1) {
waitUntil { tracker.level.gameTime >= target }
}
private fun TestContext.offset(pos: BlockPos): BlockPos = tracker.testPos.offset(pos.x, pos.y + 2, pos.z)
fun TestContext.offset(pos: BlockPos): BlockPos = tracker.testPos.offset(pos.x, pos.y + 2, pos.z)
/**
* Get a block within the test structure.
@@ -59,3 +62,24 @@ fun TestContext.modifyBlock(pos: BlockPos, modify: (BlockState) -> BlockState) {
val offset = offset(pos)
level.setBlockAndUpdate(offset, modify(level.getBlockState(offset)))
}
/**
* Get a tile within the test structure.
*/
fun TestContext.getTile(pos: BlockPos): TileEntity? = tracker.level.getBlockEntity(offset(pos))
/**
* Get an entity within the test structure.
*/
fun TestContext.getEntity(pos: BlockPos): Entity? {
val entities = tracker.level.getEntitiesOfClass(Entity::class.java, AxisAlignedBB(offset(pos)))
return if (entities.isEmpty()) null else entities.get(0)
}
/**
* Get an entity within the test structure.
*/
inline fun <reified T : Entity> TestContext.getEntityOfType(pos: BlockPos): T? {
val entities = tracker.level.getEntitiesOfClass(T::class.java, AxisAlignedBB(offset(pos)))
return if (entities.isEmpty()) null else entities.get(0)
}