Skip to content

Commit 897424b

Browse files
pragdaveJosé Valim
authored andcommitted
Spruce up the output format of ex_unit
Conflicts: lib/ex_unit/lib/ex_unit/assertions.ex
1 parent f4c61da commit 897424b

File tree

7 files changed

+620
-268
lines changed

7 files changed

+620
-268
lines changed

lib/ex_unit/examples/one_of_each.exs

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
ExUnit.start [seed: 0]
2+
3+
defmodule TestOneOfEach do
4+
@moduledoc """
5+
This module contains one of each type of failing test.
6+
It is used simply to document the style of each.
7+
"""
8+
9+
use ExUnit.Case, async: false
10+
11+
@one 1
12+
@two 2
13+
14+
@long_data_1 [ field1: "one", field2: { :two1, :two2 }, field3: 'three', field4: [1,2,3,4]]
15+
@long_data_2 [ field1: "one", field2: { :two1, :two3 }, field3: 'three', field4: [1,2,3,4]]
16+
17+
test "1. assert with a match" do
18+
assert [@one] = [@two]
19+
end
20+
21+
test "2. assert with a binary operator" do
22+
assert @one * 4 > @two *3
23+
end
24+
25+
test "3. assert match with a long argument" do
26+
assert @long_data_1 = @long_data_2
27+
end
28+
29+
test "4. assert equality with a long argument" do
30+
assert @long_data_1 == @long_data_2
31+
end
32+
33+
test "5. refute with a match" do
34+
refute [@one] = [@one]
35+
end
36+
37+
test "6. refute with a binary operator" do
38+
refute @one * 6 > @two *2
39+
end
40+
41+
test "7. refute match with a long argument" do
42+
refute @long_data_1 = @long_data_1
43+
end
44+
45+
test "8. refute equality with a long argument" do
46+
refute @long_data_1 == @long_data_1
47+
end
48+
49+
test "9. assert of an expression with a message" do
50+
assert 1 > 2, "is one greater than two?"
51+
end
52+
53+
test "10. assert with explicit expected and actual values" do
54+
assert @one > @two, @one, @two, "one should be greater than two"
55+
end
56+
57+
test "11. assert that a message is ready to be received" do
58+
assert_received :no_message_there
59+
end
60+
61+
test "12. assert that a message is received within a timeout" do
62+
assert_receive :no_message_after_timeout
63+
end
64+
65+
test "13. assert an exception with a given message is raised, but no exception" do
66+
assert_raise(SomeException, "some message", fn -> end)
67+
end
68+
69+
test "14. assert an exception with a given message is raised" do
70+
assert_raise(SomeException, "some message", fn ->
71+
raise "other exception"
72+
end)
73+
end
74+
75+
test "15. assert an exception with a given message is raised, but the message is wrong" do
76+
assert_raise(RuntimeError, "some message", fn ->
77+
raise "other error"
78+
end)
79+
end
80+
81+
test "16. assert an exception is raised" do
82+
assert_raise(SomeException, fn -> end)
83+
end
84+
85+
test "17. assert two values are within some delta" do
86+
assert_in_delta 3.1415926, 22.0/7, 0.001
87+
end
88+
89+
test "18. refute a value with a message" do
90+
refute @one != @two, "one should equal two"
91+
end
92+
93+
test "19. refute a message is received within a timeout" do
94+
send self, {:hello, "Dave"}
95+
refute_receive {:hello, _}, 1000
96+
end
97+
98+
test "20. refute a message is ready to be received" do
99+
send self, :hello_again
100+
refute_received :hello_again
101+
end
102+
103+
test "21. refute two values are within delta" do
104+
refute_in_delta @one, @two, 1.5
105+
end
106+
107+
test "22. refute two values are within delta with message" do
108+
refute_in_delta @one, @two, 1.5, "they shouldn't be this close"
109+
end
110+
111+
test "23. flunk" do
112+
flunk "we failed. totally"
113+
end
114+
115+
test "24. exception raised while running test" do
116+
assert blows_up
117+
end
118+
119+
defp blows_up do
120+
ignite(0) + 1
121+
end
122+
123+
defp ignite(val) do
124+
1/val
125+
end
126+
end

0 commit comments

Comments
 (0)