19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

19.5 Test Suites<br />

In order to allow programmers to run strict subsets of all tests defined in a program, <strong>Fortress</strong> allows tests to be<br />

assembled into test suites.<br />

<strong>The</strong> convenience object TestSuite is defined in the <strong>Fortress</strong> standard libraries. An instance of this object contains a<br />

set of test functions that can all be called by invoking the method run :<br />

test object TestSuite(testFunctions = {})<br />

add(f:() → ()) = testFunctions.insert(f)<br />

run() =<br />

for t ← testFunctions do<br />

t()<br />

end<br />

end<br />

Note that all tests in a TestSuite are run in parallel.<br />

19.6 Property Declarations<br />

Syntax:<br />

PropertyDecl ::= property [Id = ] [∀ ValParam] Expr<br />

ValParam ::= ParamId<br />

| ([ValParams])<br />

ParamId ::= Id<br />

|<br />

ValParams ::= PlainParam( , PlainParam) ∗<br />

| [PlainParam( , PlainParam) ∗ , ] Id : TypeRef ...<br />

| [PlainParam( , PlainParam) ∗ , ] [Id : TypeRef ... , ] PlainParam = Expr ( , PlainParam=Expr) ∗<br />

PlainParam ::= ParamId [IsType]<br />

| TypeRef<br />

Components and APIs may include property declarations, documenting boolean conditions that a program is expected<br />

to obey. Syntactically, a property declaration begins with the special reserved word property followed by an optional<br />

identifier followed by the token = , an optional value parameter, which may be a tuple, preceded by the token ∀ , and<br />

a boolean subexpression. In any execution of the program, the boolean subexpression is expected to evaluate to true<br />

at any time for any binding of the property declaration’s parameter to any value of its declared type. When a property<br />

declaration includes an identifier, the property identifier is bound to a function whose parameter and body are that of<br />

the property, and whose return type is Boolean. A function bound in this manner is referred to as a property function.<br />

Properties can also be declared in trait or object declarations. Such properties are expected to hold for all instances of<br />

the trait or object and for all bindings of the property’s parameter. If a property in a trait or object includes a name,<br />

the name is bound to a method whose parameter and body are that of the property, and whose return type is Boolean.<br />

A method bound in this manner is referred to as a property method. A property method of a trait T can be called, via<br />

dotted method notation, on an instance of T .<br />

Property functions and methods can be referred to in a program’s tests. If the result of a call to a property function or<br />

method is not true , a TestFailure exception is thrown. For example, we can write:<br />

property fIsMonotonic = ∀(x: Z, y: Z) (x < y) → (f(x) < f(y))<br />

151

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!