Skip to content

Commit 17c235a

Browse files
Remove catch in base64_SUITE
1 parent 1a14bac commit 17c235a

1 file changed

Lines changed: 19 additions & 26 deletions

File tree

lib/stdlib/test/base64_SUITE.erl

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
-module(base64_SUITE).
2424

2525
-include_lib("common_test/include/ct.hrl").
26+
-include_lib("stdlib/include/assert.hrl").
2627

2728
%% Test server specific exports
2829
-export([all/0, suite/0, groups/0, group/1]).
@@ -126,19 +127,15 @@ base64_decode(Config) when is_list(Config) ->
126127
base64:decode(<<"QWxhZGRpbjpvcGVuIHNlc2FtZQ">>, #{padding => false}),
127128
<<"Aladdin:open sesame">> =
128129
base64:decode("QWxhZGRpbjpvcGVuIHNlc2FtZQ", #{padding => false}),
129-
{'EXIT', {'missing_padding', _}} =
130-
catch base64:decode(<<"QWxhZGRpbjpvcGVuIHNlc2FtZQ">>),
131-
{'EXIT', {'missing_padding', _}} =
132-
catch base64:decode("QWxhZGRpbjpvcGVuIHNlc2FtZQ"),
130+
?assertError(missing_padding, base64:decode(<<"QWxhZGRpbjpvcGVuIHNlc2FtZQ">>)),
131+
?assertError(missing_padding, base64:decode("QWxhZGRpbjpvcGVuIHNlc2FtZQ")),
133132
%% One pad
134133
<<"Hello World">> = base64:decode(<<"SGVsbG8gV29ybGQ=">>),
135134
<<"Hello World">> = base64:decode("SGVsbG8gV29ybGQ="),
136135
<<"Hello World">> = base64:decode(<<"SGVsbG8gV29ybGQ">>, #{padding => false}),
137136
<<"Hello World">> = base64:decode("SGVsbG8gV29ybGQ", #{padding => false}),
138-
{'EXIT', {'missing_padding', _}} =
139-
catch base64:decode_to_string(<<"SGVsbG8gV29ybGQ">>),
140-
{'EXIT', {'missing_padding', _}} =
141-
catch base64:decode_to_string("SGVsbG8gV29ybGQ"),
137+
?assertError(missing_padding, base64:decode_to_string(<<"SGVsbG8gV29ybGQ">>)),
138+
?assertError(missing_padding, base64:decode_to_string("SGVsbG8gV29ybGQ")),
142139
%% No pad
143140
<<"Aladdin:open sesam">> =
144141
base64:decode(<<"QWxhZGRpbjpvcGVuIHNlc2Ft">>),
@@ -175,19 +172,15 @@ base64_decode_to_string(Config) when is_list(Config) ->
175172
base64:decode_to_string(<<"QWxhZGRpbjpvcGVuIHNlc2FtZQ">>, #{padding => false}),
176173
"Aladdin:open sesame" =
177174
base64:decode_to_string("QWxhZGRpbjpvcGVuIHNlc2FtZQ", #{padding => false}),
178-
{'EXIT', {'missing_padding', _}} =
179-
catch base64:decode_to_string(<<"QWxhZGRpbjpvcGVuIHNlc2FtZQ">>),
180-
{'EXIT', {'missing_padding', _}} =
181-
catch base64:decode_to_string("QWxhZGRpbjpvcGVuIHNlc2FtZQ"),
175+
?assertError(missing_padding, base64:decode_to_string(<<"QWxhZGRpbjpvcGVuIHNlc2FtZQ">>)),
176+
?assertError(missing_padding, base64:decode_to_string("QWxhZGRpbjpvcGVuIHNlc2FtZQ")),
182177
%% One pad
183178
"Hello World" = base64:decode_to_string(<<"SGVsbG8gV29ybGQ=">>),
184179
"Hello World" = base64:decode_to_string("SGVsbG8gV29ybGQ="),
185180
"Hello World" = base64:decode_to_string(<<"SGVsbG8gV29ybGQ">>, #{padding => false}),
186181
"Hello World" = base64:decode_to_string("SGVsbG8gV29ybGQ", #{padding => false}),
187-
{'EXIT', {'missing_padding', _}} =
188-
catch base64:decode_to_string(<<"SGVsbG8gV29ybGQ">>),
189-
{'EXIT', {'missing_padding', _}} =
190-
catch base64:decode_to_string("SGVsbG8gV29ybGQ"),
182+
?assertError(missing_padding, base64:decode_to_string(<<"SGVsbG8gV29ybGQ">>)),
183+
?assertError(missing_padding, base64:decode_to_string("SGVsbG8gV29ybGQ")),
191184
%% No pad
192185
"Aladdin:open sesam" =
193186
base64:decode_to_string(<<"QWxhZGRpbjpvcGVuIHNlc2Ft">>),
@@ -220,13 +213,13 @@ base64_decode_modes(Config) when is_list(Config) ->
220213

221214
DataBin = base64:decode("F+o/o++B/a+r", #{mode => standard}),
222215
DataBin = base64:decode("F-o_o--B_a-r", #{mode => urlsafe}),
223-
{'EXIT', _} = catch base64:decode("F-o_o--B_a-r", #{mode => standard}),
224-
{'EXIT', _} = catch base64:decode("F+o/o++B/a+r", #{mode => urlsafe}),
216+
?assertError(_, base64:decode("F-o_o--B_a-r", #{mode => standard})),
217+
?assertError(_, base64:decode("F+o/o++B/a+r", #{mode => urlsafe})),
225218

226219
DataStr = base64:decode_to_string("F+o/o++B/a+r", #{mode => standard}),
227220
DataStr = base64:decode_to_string("F-o_o--B_a-r", #{mode => urlsafe}),
228-
{'EXIT', _} = catch base64:decode_to_string("F-o_o--B_a-r", #{mode => standard}),
229-
{'EXIT', _} = catch base64:decode_to_string("F+o/o++B/a+r", #{mode => urlsafe}),
221+
?assertError(_, base64:decode_to_string("F-o_o--B_a-r", #{mode => standard})),
222+
?assertError(_, base64:decode_to_string("F+o/o++B/a+r", #{mode => urlsafe})),
230223

231224
ok.
232225

@@ -238,7 +231,7 @@ base64_otp_5635(Config) when is_list(Config) ->
238231
%%-------------------------------------------------------------------------
239232
%% OTP-6279: Make sure illegal characters are rejected when decoding.
240233
base64_otp_6279(Config) when is_list(Config) ->
241-
{'EXIT',_} = (catch base64:decode("dGVzda==a")),
234+
?assertError(_, base64:decode("dGVzda==a")),
242235
ok.
243236
%%-------------------------------------------------------------------------
244237
%% Encode and decode big binaries.
@@ -255,11 +248,11 @@ big(Config) when is_list(Config) ->
255248
illegal(Config) when is_list(Config) ->
256249
%% A few samples with different error reasons. Nothing can be
257250
%% assumed about the reason for the crash.
258-
{'EXIT',_} = (catch base64:decode("()")),
259-
{'EXIT',_} = (catch base64:decode(<<19:8,20:8,21:8,22:8>>)),
260-
{'EXIT',_} = (catch base64:decode([19,20,21,22])),
261-
{'EXIT',_} = (catch base64:decode_to_string(<<19:8,20:8,21:8,22:8>>)),
262-
{'EXIT',_} = (catch base64:decode_to_string([19,20,21,22])),
251+
?assertError(_, base64:decode("()")),
252+
?assertError(_, base64:decode(<<19:8,20:8,21:8,22:8>>)),
253+
?assertError(_, base64:decode([19,20,21,22])),
254+
?assertError(_, base64:decode_to_string(<<19:8,20:8,21:8,22:8>>)),
255+
?assertError(_, base64:decode_to_string([19,20,21,22])),
263256
ok.
264257
%%-------------------------------------------------------------------------
265258
%% mime_decode and mime_decode_to_string have different implementations

0 commit comments

Comments
 (0)