ctrl-alt-delor
ctrl-alt-delor

Reputation: 7745

How can I get more information when debugging a contract violation that checks for equality

I have the following Eiffel code. I am doing test-driven-design with contracts.

check
    sorter.sorted (<<1>>).is_equal (<<1>>)
end

The code correctly detects that my sort returns the wrong value. However it would be nice to see what sorted returned. I can see that it is too late as is_equals consumes both values, and returns false, before the check throws the exception.

I have seen in other testing frameworks they have a special is_equal for the test framework. That allows better feedback. e.g.

check_equal(expected, value_under_test)

Is there anything like this in eiffel?

Upvotes: 1

Views: 55

Answers (2)

U. Windl
U. Windl

Reputation: 4401

Note that check statements are not "debug" statements: check statements are to ensure the correctness (i.e. trigger on errors), while debug statements help to understand what's going on. To debug your code once a check failed, you would add debug statements that output information before the check triggers.

Upvotes: 0

Alexander Kogtenkov
Alexander Kogtenkov

Reputation: 5810

I would suggest looking at library testing. In particular, class EQA_COMMONLY_USED_ASSERTIONS has feature assert_equal that seems to do what you want to:

assert_equal (a_tag: READABLE_STRING_GENERAL; expected, actual: detachable ANY)
        -- Check that `expected ~ actual'.

The original example would then look like

assert_equal ("Is array sorted?", sorter.sorted (<<1>>), <<1>>)

Upvotes: 2

Related Questions