/test/language/assertion/test_attribute03.e

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