0

Eiffel has a feature Design by Contract. According to this, for any routine, there is a check that assertions such as require and ensure must be true. However, I haven't been able to find out how to enforce the rule through command line that if the assertions are false, there must be an error/exception thrown by the compiler or during run time.

For example, if this is the root class,

class
    APPLICATION

inherit
    ARGUMENTS

create
    make

feature {NONE}


    object: TEST1
    make
            -- Run application.
        do          
            create object
            object.function(-1)
            print(object.value)
        end
end

and this is the TEST1 class

class
    TEST1

feature

    value: INTEGER
            -- value for testing
    function(val: INTEGER)
            -- Assign
        require
            val>0
        do
            value:=val
        ensure
            value>0     
        end

end

The program compiles and executes without any error, even though both the assertions are violated.

I am compiling using

ec application.e

However, Eiffel Studio does report a violation of contract.

So, how can one enforce this through command line? Is there a particular flag to use?

GoodDeeds
  • 7,956
  • 5
  • 34
  • 61

1 Answers1

1

It looks like GUI version of EiffelStudio and command-line version of EiffelStudio use different defaults when they create new projects: command-line version turns off assertion monitoring and GUI version turns on assertion monitoring. In fact you can open a project created with a command-line version in GUI, or, conversely, compile a project created in GUI version by a command-line compiler. The project settings are kept in a .ecf file and are part of a project, i.e. this .ecf file should be distributed together with the project.

To address the particular issue you describe, open the .ecf in GUI (File | Open Project | Add Project | Open), then navigate to Project | Project Settings | Assertions, turn on all assertions and press Save, exit from the GUI version. Now when you recompile your project from the command-line, the assertions will be turned on and you'll get an exception trace during execution as expected.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • This is not working for me. The setting shows that all assertions are set to true, but still the program passes even when the assertion is violated when I run it using bash. – GoodDeeds Nov 05 '16 at 19:03
  • @GoodDeeds, Would you try to remove `EIFGENs` directory, preserving `application.ecf` at the top of the project and recompile from scratch? – Alexander Kogtenkov Nov 05 '16 at 20:18