(util.ps) runlibfile

/test-case {                    % <str> test-case mark
    print (\n) print

    /.test-total-count 0 def
    /.test-failed-count 0 def

    % (*) mark the beginning of messages for the summary
    mark
} def

/should {                       % <str> should
    pop
} def

/assert-equal {                 % <str> <any> <any> assert-equal
    /.test-total-count inc
    eq {
        pop (.) print
    } {
        pop (F) print
        /.test-failed-count inc
    } ifelse
} bind def

/test-summary {	                % test-summary
    (\n) print
    (--------------------------------------------------\n) print
    .test-total-count 5 string cvs print ( tests, ) print
    .test-failed-count 5 string cvs print ( failed\n\n) print

    (return-two)
    (  should return 2)
    (    expected: 2)
    (    actual:   1)

    % release accumulated messages to stdout
    ] % (*) wrap up the array started in test-case
    {
        print (\n) print
    } forall
} def

(util.ps) runlibfile

/test-case {                    % <str> test-case mark
    print (\n) print

    % (*) create a package dict to count the tests
    2 dict begin
    /.test-total-count 0 def
    /.test-failed-count 0 def

    % (**) mark the beginning of test results on the stack
    mark
} def

/should {                       % <str> should
    pop
} def

/assert-equal {                 % <str> <any> <any> assert-equal
    /.test-total-count inc
    eq {
        pop (.) print
    } {
        pop (F) print
        /.test-failed-count inc
    } ifelse
} bind def

/test-summary {	                % test-summary
    (\n) print
    (--------------------------------------------------\n) print
    .test-total-count 5 string cvs print ( tests, ) print
    .test-failed-count 5 string cvs print ( failed\n\n) print

    % (*) now we printed them, we don't need the counts any longer
    end

    (return-two)
    (  should return 2)
    (    expected: 2)
    (    actual:   1)

    % (**) release accumulated messages to stdout
    ] {
        print (\n) print
    } forall
} def
