@@ -112,10 +112,16 @@ all(suite) ->
112
112
no_init_suite_config , no_init_config , no_end_config ,
113
113
failed_sequence , repeat_force_stop , config_clash ,
114
114
callbacks_on_skip , fallback , data_dir ,
115
- cth_log , cth_log_formatter , cth_log_unexpect
115
+ { group , cth_log_redirect }
116
116
]
117
117
).
118
118
119
+ groups () ->
120
+ [
121
+ {cth_log_redirect , [], [cth_log_unexpect , cth_log_formatter ,
122
+ cth_log , cth_log_mode_replace ]}
123
+ ].
124
+
119
125
120
126
% %--------------------------------------------------------------------
121
127
% % TEST CASES
@@ -300,36 +306,7 @@ data_dir(Config) when is_list(Config) ->
300
306
cth_log (Config ) when is_list (Config ) ->
301
307
% % test that cth_log_redirect writes properly to
302
308
% % html I/O log
303
- ct :timetrap ({minutes ,10 }),
304
- StartOpts = do_test (cth_log , " cth_log_SUITE.erl" , [], Config ),
305
- Logdir = proplists :get_value (logdir , StartOpts ),
306
- TCLogs =
307
- filelib :wildcard (
308
- filename :join (Logdir ,
309
- " ct_run*/cth.tests*/run*/cth_log_suite.tc*.html" )),
310
- lists :foreach (
311
- fun (TCLog ) ->
312
- {ok ,Bin } = file :read_file (TCLog ),
313
- Ts = string :lexemes (binary_to_list (Bin ),[$\n ]),
314
- Matches = lists :foldl (fun (" =ERROR" ++ _ , {E ,I ,N ,L }) ->
315
- {E + 1 ,I ,N ,L };
316
- (" =INFO" ++ _ , {E ,I ,N ,L }) ->
317
- {E ,I + 1 ,N ,L };
318
- (" =NOTICE" ++ _ , {E ,I ,N ,L }) ->
319
- {E ,I ,N + 1 ,L };
320
- (" Logger" ++ _ , {E ,I ,N ,L }) ->
321
- {E ,I ,N ,L + 1 };
322
- (_ , N ) -> N
323
- end , {0 ,0 ,0 ,0 }, Ts ),
324
- ct :pal (" ~p ({Error,Info,Notice,Log}) matches in ~tp " ,
325
- [Matches ,TCLog ]),
326
- MatchList = tuple_to_list (Matches ),
327
- case [N || N <- MatchList , N < 1 ] of
328
- [] -> ok ;
329
- _ -> exit ({missing_io ,TCLog })
330
- end
331
- end , TCLogs ),
332
- ok .
309
+ verify_cth_log_output (Config , [], []).
333
310
334
311
cth_log_formatter (Config ) when is_list (Config ) ->
335
312
% % test that cth_log_redirect writes properly to
@@ -398,6 +375,12 @@ cth_log_unexpect(Config) when is_list(Config) ->
398
375
end , UnexpIoLogs ),
399
376
ok .
400
377
378
+ cth_log_mode_replace (Config ) when is_list (Config ) ->
379
+ % % test that cth_log_redirect writes properly to
380
+ % % html I/O log when replace mode is used
381
+ verify_cth_log_output (Config , [{cth_log_redirect , [{mode , replace }]}],
382
+ [{enable_builtin_hooks , false }]).
383
+
401
384
% % OTP-10599 adds the Suite argument as first argument to all hook
402
385
% % callbacks that did not have a Suite argument from before. This test
403
386
% % checks that ct_hooks will fall back to old versions of callbacks if
@@ -542,6 +525,39 @@ gen_config(Name,KeyVals,Config) ->
542
525
|| {Key ,Value } <- KeyVals ]),
543
526
File .
544
527
528
+ verify_cth_log_output (Config , CTHooks , ExtraOpts ) ->
529
+ ct :timetrap ({minutes ,10 }),
530
+ StartOpts = do_test (cth_log , " cth_log_SUITE.erl" , CTHooks , Config , ok , 2 , ExtraOpts ),
531
+ Logdir = proplists :get_value (logdir , StartOpts ),
532
+ TCLogs =
533
+ filelib :wildcard (
534
+ filename :join (Logdir ,
535
+ " ct_run*/cth.tests*/run*/cth_log_suite.tc*.html" )),
536
+ lists :foreach (
537
+ fun (TCLog ) ->
538
+ {ok ,Bin } = file :read_file (TCLog ),
539
+ Ts = string :lexemes (binary_to_list (Bin ),[$\n ]),
540
+ Matches = lists :foldl (fun (" =ERROR" ++ _ , {E ,I ,N ,L }) ->
541
+ {E + 1 ,I ,N ,L };
542
+ (" =INFO" ++ _ , {E ,I ,N ,L }) ->
543
+ {E ,I + 1 ,N ,L };
544
+ (" =NOTICE" ++ _ , {E ,I ,N ,L }) ->
545
+ {E ,I ,N + 1 ,L };
546
+ (" Logger" ++ _ , {E ,I ,N ,L }) ->
547
+ {E ,I ,N ,L + 1 };
548
+ (_ , N ) -> N
549
+ end , {0 ,0 ,0 ,0 }, Ts ),
550
+ ct :pal (" ~p ({Error,Info,Notice,Log}) matches in ~tp " ,
551
+ [Matches ,TCLog ]),
552
+ MatchList = tuple_to_list (Matches ),
553
+ case [N || N <- MatchList , N < 1 ] of
554
+ [] -> ok ;
555
+ _ -> exit ({missing_io ,TCLog })
556
+ end
557
+ end , TCLogs ),
558
+ ok .
559
+
560
+
545
561
% %%-----------------------------------------------------------------
546
562
% %% TEST EVENTS
547
563
% %%-----------------------------------------------------------------
0 commit comments