testutils

package
v0.0.0-...-cfb4354 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2020 License: Zlib Imports: 5 Imported by: 0

README

testutils

GoDoc

Package testutils provides utilities for testing Io code in Go:

  • TestingVM provides synchronized access to a VM for executing code. Also, ResetTestingVM restores that VM to a fresh, clean state.
  • SourceTestCase creates sub-test functions that execute code and check the result using one of various predicates (which Pass* functions provide).
  • CheckSlots is a helper that checks that an object has exactly the expected slots.
  • CheckObjectIsProto is a helper that checks that an object has Core Object as its only proto.

The contents of this package are copied from internal testing code. To read example usage, see e.g. object_test.go in the base iolang package.

Documentation

Overview

Package testutils provides utilities for testing Io code in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckNewSlots

func CheckNewSlots(t *testing.T, obj *iolang.Object, slots []string)

CheckNewSlots is a testing helper to check whether an object has the given slots, and possibly others.

func CheckObjectIsProto

func CheckObjectIsProto(t *testing.T, obj *iolang.Object)

CheckObjectIsProto is a testing helper to check that an object has exactly one proto, which is Core Object. obj must come from the test VM.

func CheckSlots

func CheckSlots(t *testing.T, obj *iolang.Object, slots []string)

CheckSlots is a testing helper to check whether an object has exactly the listed slots.

func PassControl

func PassControl(want *iolang.Object, stop iolang.Stop) func(*iolang.Object, iolang.Stop) bool

PassControl returns a Pass function for a SourceTestCase that predicates on equality with a certain control flow status. The control flow check precedes the value check. Equality here has the same semantics as in PassEqual.

func PassEqual

func PassEqual(want *iolang.Object) func(*iolang.Object, iolang.Stop) bool

PassEqual returns a Pass function for a SourceTestCase that predicates on equality. To determine equality, this first checks for equal identities; if not, it checks that the result of TestingVM().Compare(want, result) is 0. If the Stop is not NoStop, then the predicate returns false.

func PassEqualSlots

func PassEqualSlots(want iolang.Slots) func(*iolang.Object, iolang.Stop) bool

PassEqualSlots returns a Pass function for a SourceTestCase that returns true iff the result has exactly the same slots as want and the slots' values compare equal. If the Stop is not NoStop, then the predicate returns false.

func PassFailure

func PassFailure() func(*iolang.Object, iolang.Stop) bool

PassFailure returns a Pass function for a SourceTestCase that returns true iff the result is a raised exception.

func PassIdentical

func PassIdentical(want *iolang.Object) func(*iolang.Object, iolang.Stop) bool

PassIdentical returns a Pass function for a SourceTestCase that predicates on identity equality, i.e. the result must be exactly the given object. If the Stop is not NoStop, then the predicate returns false.

func PassLocalSlots

func PassLocalSlots(want, exclude []string) func(*iolang.Object, iolang.Stop) bool

PassLocalSlots returns a Pass function for a SourceTestCase that returns true iff the result locally has all of the slots in want and none of the slots in exclude. If the Stop is not NoStop, then the predicate returns false.

func PassSuccess

func PassSuccess() func(*iolang.Object, iolang.Stop) bool

PassSuccess returns a Pass function for a SourceTestCase that returns true iff the control flow status is NoStop.

func PassTag

func PassTag(want iolang.Tag) func(*iolang.Object, iolang.Stop) bool

PassTag returns a Pass function for a SourceTestCase that predicates on equality of the Tag of the result. If the Stop is not NoStop, then the predicate returns false.

func PassUnequal

func PassUnequal(want *iolang.Object) func(*iolang.Object, iolang.Stop) bool

PassUnequal returns a Pass function for a SourceTestCase that predicates on non-equality by checking that the result of testVM.Compare(want, result) is not 0.

func ResetVM

func ResetVM()

ResetVM reinitializes the VM returned by TestVM. It is not safe to call this in parallel tests.

func VM

func VM() *iolang.VM

VM returns a VM for testing Io. The VM is shared by all tests that use this package.

Types

type SourceTestCase

type SourceTestCase struct {
	// Source is the Io source code to execute.
	Source string
	// Pass is a predicate taking the result of executing Source. If Pass
	// returns false, then the test fails.
	Pass func(result *iolang.Object, control iolang.Stop) bool
}

A SourceTestCase is a test case containing Io source code and a predicate to check the result.

func (SourceTestCase) TestFunc

func (c SourceTestCase) TestFunc(name string) func(*testing.T)

TestFunc returns a test function for the test case. This uses TestingVM to parse and execute the code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL