Перейти к содержимому
Топаз6.0 · До релиза
Загрузка →

Поиск в документации

Спецификация 6.0

Выберите результат стрелками и нажмите Enter, чтобы открыть его.

Введите имя API, номер диагностики, правило или тему проекта.

    Инструменты

    Результаты тестов и утверждения

    Read the result of a SELF test invocation and use equality assertions to check returned values.

    Правилоtopaz.rule.test-result.completion

    Test completion and failure reporting

    topaz test checks the selected entry before execution. After a successful SELF execution, it writes {entry}: test-ok followed by a newline to standard output. A reported runtime failure writes its diagnostic and {entry}: test failed to standard error and exits unsuccessfully. A unit with compilation diagnostics does not execute.

    Success includes deferred cleanup. Deferred errors and process exit codes follow the test command.

    Причина

    Checking before execution prevents invalid programs from producing effects. Separate success and failure channels let test runners distinguish completion from a failed test.

    Правилоtopaz.rule.test-result.assert-eq

    Equality assertions

    The operands of std.test.assertEq(actual, expected) use the ordinary equality domain.

    Equal values return () and execution continues. Unequal values raise TPZ4007 with the rendered actual and expected values.

    Known noncomparable operands produce TPZ5007 during checking.

    Argument evaluation and assertion failure follow Test comparisons.

    Причина

    Using ordinary value equality keeps tests consistent with comparisons in program code. Reporting both operands makes a mismatch inspectable.

    Examples

    Ссылка

    A successful test reports completion

    Ссылка
    test-result.tpzA successful test reports completionОткрыть песочницу →
    1. let value = 1
    Ожидаемый выводКод завершения 0
    test-result.tpz: test-ok
    
    $ topaz test test-result.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. test-result.tpz: test-ok

    Equality returns unit and execution continues

    Ссылка
    assert-eq.tpzEquality returns unit and execution continuesОткрыть песочницу →
    1. import std.io
    2. import std.test
    3. let result: () = test.assertEq([1, 2], [1, 2])
    4. io.writeLine("{result}")
    Ожидаемый выводКод завершения 0
    ()
    
    $ topaz run assert-eq.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Выполнение завершается. Код завершения 0.

    Ожидаемый стандартный вывод
    1. ()

    Reject function equality before execution

    Ссылка
    test-input-bad.tpzReject function equality before executionОткрыть песочницу →
    1. import std.test
    2. function value(x: int) -> int { x }
    3. test.assertEq(value, value)
    Ожидаемый выводНенулевой код завершения
    Нет стандартного вывода.
    $ topaz check test-input-bad.tpz --compiler self · Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    Этап отклонения check. Ненулевой код завершения.

    • TPZ5007 →

      test-assert-eq-non-comparable at test-input-bad.tpz:3:1

    An unequal assertion fails the test

    Ссылка
    test-failure.tpzAn unequal assertion fails the testОткрыть песочницу →
    1. import std.test
    2. test.assertEq(1, 2)
    Целевой продукт 5.21.3
    Ожидаемый результат

    Ожидаемый результат

    The independently intended result is a nonzero exit, TPZ4007, and the test-failed footer. The dedicated installed-CLI product test has not run in this sandbox.

    The intended runtime outcome is TPZ4007, an unsuccessful exit, and test-failure.tpz: test failed on standard error. A dedicated installed-CLI product test checks these observations for this exact fixture. Its execution awaits the public CLI integration run.

    Related

    Ссылка

    Value is not comparable or keyable →

    Assertion failed →

    test →

    std.test.assertEq →

    Меню

    Загрузка →