/test/language/assertion/test_attribute03.e
Specman e | 89 lines | 51 code | 11 blank | 27 comment | 2 complexity | 5eb3c3801abb8fa4baa2244a9be53b30 MD5 | raw file
1-- This file is part of SmartEiffel The GNU Eiffel Compiler Tools and Libraries. 2-- See the Copyright notice at the end of this file. 3-- 4class TEST_ATTRIBUTE03 5 6insert 7 EIFFELTEST_TOOLS 8 9create {} 10 main 11 12feature {ANY} 13 main 14 local 15 aux: AUX_ATTRIBUTE03B; x: INTEGER 16 do 17 set_flags 18 create aux 19 assert(aux.attribute_require_counter = 0) 20 assert(aux.deferred_require_counter = 0) 21 assert(aux.attribute_ensure_counter = 0) 22 assert(aux.deferred_ensure_counter = 0) 23 24 x := aux.value + aux.value 25 -- TODO, Rmk: clarify, what ECMA specifies about contracts 26 -- of attributes. Why did I once add " + aux.value"? 27 28 -- aux.value cannot change between the two successive calls, 29 -- as no feature with side effects is called in between. 30 -- Therefore the optimizer might choose to evaluate it (and 31 -- therefore also its contracts) only once. 32 if require_flag then 33 label_assert("precondition evaluated (1 or 2 times)", 34 aux.attribute_require_counter = 1 35 or aux.attribute_require_counter = 2) 36 assert(aux.deferred_require_counter = 0) 37 end 38 if ensure_flag then 39 label_assert("postcondition evaluated (1 or 2 times)", 40 aux.attribute_ensure_counter = 1 41 or aux.attribute_ensure_counter = 2) 42 label_assert("inherited postcondition evaluated (equal times)", 43 aux.deferred_ensure_counter = aux.attribute_ensure_counter) 44 end 45 end 46 47 require_flag: BOOLEAN 48 49 ensure_flag: BOOLEAN 50 51 set_flags_require: BOOLEAN 52 do 53 require_flag := True 54 Result := True 55 end 56 57 set_flags 58 require 59 set_flags_require 60 do 61 ensure 62 set_flags_ensure 63 end 64 65 set_flags_ensure: BOOLEAN 66 do 67 ensure_flag := True 68 Result := True 69 end 70 71end -- class TEST_ATTRIBUTE03 72-- 73-- ------------------------------------------------------------------------------------------------------------------------------ 74-- Copyright notice below. Please read. 75-- 76-- SmartEiffel is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, 77-- as published by the Free Software Foundation; either version 2, or (at your option) any later version. 78-- SmartEiffel is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty 79-- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have 80-- received a copy of the GNU General Public License along with SmartEiffel; see the file COPYING. If not, write to the Free 81-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 82-- 83-- Copyright(C) 1994-2002: INRIA - LORIA (INRIA Lorraine) - ESIAL U.H.P. - University of Nancy 1 - FRANCE 84-- Copyright(C) 2003-2006: INRIA - LORIA (INRIA Lorraine) - I.U.T. Charlemagne - University of Nancy 2 - FRANCE 85-- 86-- Authors: Dominique COLNET, Philippe RIBET, Cyril ADRIAN, Vincent CROIZIER, Frederic MERIZEN 87-- 88-- http://SmartEiffel.loria.fr - SmartEiffel@loria.fr 89-- ------------------------------------------------------------------------------------------------------------------------------