Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9d75e4c

Browse files
committedMar 14, 2016
test for @precondition
1 parent 258aa74 commit 9d75e4c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

‎test/misc.jl

+26
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,32 @@ let deepthought(x, y) = 42
101101
end
102102
end
103103

104+
# test @precondition
105+
let
106+
f1(n) = begin @precondition n > 0; n end
107+
f2(n) = begin @precondition n != 0 "non-zero n"; n end
108+
109+
@test f1(1) == 1
110+
@test f2(1) == 1
111+
112+
try
113+
f1(0)
114+
error("unexpected")
115+
catch ex
116+
@test isa(ex, ArgumentError)
117+
@test ismatch(r"f1(.*) requires n > 0", ex.msg)
118+
end
119+
120+
try
121+
f2(0)
122+
error("unexpected")
123+
catch ex
124+
@test isa(ex, ArgumentError)
125+
@test ismatch(r"f2(.*) requires non-zero n", ex.msg)
126+
end
127+
end
128+
129+
104130
let # test the process title functions, issue #9957
105131
oldtitle = Sys.get_process_title()
106132
Sys.set_process_title("julia0x1")

0 commit comments

Comments
 (0)
Please sign in to comment.