Assert Package

The Assert built-in package supplies the assertion functions used to write unit tests for twinBASIC code. Each assertion checks an expected condition; on failure, it records a test failure with the call site and an optional message. The test runner — the twinBASIC IDE’s Test Explorer, or any equivalent harness — collects those results, decides which tests passed, failed, or were skipped, and reports them.

The package’s three modules — Exact, Strict, and Permissive — expose the same fifteen assertion functions; only the comparison semantics differ. Each flavour matches a different strictness level for equality evaluation.

Module String comparisons Numeric and other comparisons
Exact case-sensitive no implicit conversions; datatypes must match exactly (55.0); vbNullString is distinct from ""; Empty is distinct from 0, False, and ""; object default members are not evaluated
Strict case-sensitive evaluated as if the comparison were written directly in twinBASIC code; object default members are not evaluated
Permissive case-insensitive evaluated as if the comparison were written directly in twinBASIC code

Null is never considered equal to anything — not even to itself — under any of the three flavours. To test for Null explicitly, use the IsNull / IsNotNull assertions rather than AreEqual(..., Null).

Sub TestStringReverse()
    Strict.AreEqual "olleh", StrReverse("hello")
    Strict.AreEqual "", StrReverse("")
End Sub

Calling convention

Every member of every module is tagged [MustBeQualified(True)] — calls must be written with the module name, even from inside a project that has imported the Assert package:

Strict.IsTrue x > 0          ' OK
IsTrue x > 0                 ' compile error — module qualifier required

If a project references more than one package that exposes a module called Strict, qualify further with the package name as well: Assert.Strict.IsTrue x.

Debug-only

Every assertion is tagged [DebugOnly(True)] — the calls compile to nothing in release builds, in the same way that Debug.Print and the Debug.Assert statement do. A test runner therefore needs to build the project with debug enabled.

Modules

  • Exact – strictest comparisons; datatypes must match and conversions never happen
  • Strict – case-sensitive strings, but otherwise equality matches a direct comparison in twinBASIC code
  • Permissive – case-insensitive strings; otherwise equality matches a direct comparison in twinBASIC code

Members

Each module exposes the same fifteen functions. See the per-module pages for the full signatures and the comparison semantics that apply to each member.

Exact

  • AreEqual – asserts that Actual is equal to Expected under strictest semantics; datatypes must match and no implicit conversions occur
  • AreNotEqual – asserts that Actual is not equal to Expected under strictest semantics; datatypes must match and no implicit conversions occur
  • AreNotSame – asserts that Actual and Expected refer to different objects
  • AreSame – asserts that Actual and Expected refer to the same object
  • Fail – unconditionally records a test failure
  • Inconclusive – records the test as inconclusive — neither a pass nor a failure
  • IsFalse – asserts that Condition evaluates to False
  • IsNothing – asserts that Value is the Nothing object reference
  • IsNotNothing – asserts that Value refers to an object and is not Nothing
  • IsNotNull – asserts that Value is not the Null value of a Variant
  • IsNull – asserts that Value is the Null value of a Variant
  • IsTrue – asserts that Condition evaluates to True
  • NotSequenceEquals – asserts that Actual and Expected differ in length or in at least one element
  • SequenceEquals – asserts that Actual and Expected contain the same elements in the same order
  • Succeed – records that the test reached this point without failure

Permissive

  • AreEqual – asserts that Actual is equal to Expected with case-insensitive strings and numeric promotion
  • AreNotEqual – asserts that Actual is not equal to Expected with case-insensitive strings and numeric promotion
  • AreNotSame – asserts that Actual and Expected refer to different objects
  • AreSame – asserts that Actual and Expected refer to the same object
  • Fail – unconditionally records a test failure
  • Inconclusive – records the test as inconclusive — neither a pass nor a failure
  • IsFalse – asserts that Condition evaluates to False
  • IsNothing – asserts that Value is the Nothing object reference
  • IsNotNothing – asserts that Value refers to an object and is not Nothing
  • IsNotNull – asserts that Value is not the Null value of a Variant
  • IsNull – asserts that Value is the Null value of a Variant
  • IsTrue – asserts that Condition evaluates to True
  • NotSequenceEquals – asserts that Actual and Expected differ in length or in at least one element
  • SequenceEquals – asserts that Actual and Expected contain the same elements in the same order
  • Succeed – records that the test reached this point without failure

Strict

  • AreEqual – asserts that Actual is equal to Expected with case-sensitive strings and normal twinBASIC equality
  • AreNotEqual – asserts that Actual is not equal to Expected with case-sensitive strings and normal twinBASIC equality
  • AreNotSame – asserts that Actual and Expected refer to different objects
  • AreSame – asserts that Actual and Expected refer to the same object
  • Fail – unconditionally records a test failure
  • Inconclusive – records the test as inconclusive — neither a pass nor a failure
  • IsFalse – asserts that Condition evaluates to False
  • IsNothing – asserts that Value is the Nothing object reference
  • IsNotNothing – asserts that Value refers to an object and is not Nothing
  • IsNotNull – asserts that Value is not the Null value of a Variant
  • IsNull – asserts that Value is the Null value of a Variant
  • IsTrue – asserts that Condition evaluates to True
  • NotSequenceEquals – asserts that Actual and Expected differ in length or in at least one element
  • SequenceEquals – asserts that Actual and Expected contain the same elements in the same order
  • Succeed – records that the test reached this point without failure