indexing description: "Test Case base class" author: "Peter Brandt and Martin Geisler" date: "$Date: 2005-06-28 00:06:33 +0200 (Tue, 28 Jun 2005) $" revision: "$Revision: 115 $" deferred class TEST_CASE inherit EXCEPTIONS rename exception as real_exception, class_name as real_class_name, tag_name as real_tag_name end INTERNAL rename class_name as internal_class_name undefine default_create, copy end feature -- Measurement name: STRING is -- Name of test do Result := internal_class_name (Current) end saved_states: LIST [SAVED_STATE] -- Saved states produced during the test execution feature -- Status report has_executed: BOOLEAN -- Was the test executed? has_failed: BOOLEAN -- Did the test fail? exception: INTEGER -- Code of last exception class_name: STRING -- Name of class of last exception routine_name: STRING -- Name of routine which was halted by last exception tag_name: STRING -- Tag of last violated assertion clause feature -- Basic operations execute is -- Run test case and record any exception local state_manager: STATE_MANAGER is_retrying: BOOLEAN do create state_manager if not is_retrying then -- Prepare by clearing any previous saved states state_manager.wipe_out_saved_states -- Execute the test, this might raise an exception execute_test end -- We either end directly here if there was no exception, or -- after a visit to the rescue clause, after which the if statement -- would have been skipped. In any case: the states stored -- in the state mananger are the ones corresponding to this test. saved_states := state_manager.saved_states_twin has_executed := True ensure has_executed_set: has_executed = True saved_states_not_void: saved_states /= Void tag_name_updated: has_failed implies tag_name.is_equal (real_tag_name) execption_updated: has_failed implies exception = real_exception class_name_updated: has_failed implies class_name.is_equal (real_class_name) routine_name_updated: has_failed implies routine_name.is_equal (recipient_name) rescue if assertion_violation then has_failed := True is_retrying := True -- The assignments seems necessary because the values otherwise -- disappear when the rescue clause is finished. tag_name := real_tag_name exception := real_exception class_name := real_class_name routine_name := recipient_name retry end -- If it was no assertion violation, then we just fail. end feature {NONE} -- Implementation execute_test is -- Real code to be executed by the test case deferred end invariant tag_name_set: has_failed implies tag_name /= Void exception_set: has_failed implies valid_code(exception) class_name_set: has_failed implies class_name /= Void routine_name_set: has_failed implies routine_name /= Void saved_states_set: has_executed = not (saved_states = Void) has_failed_consistant: has_failed implies has_executed end -- class TEST_CASE