Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim the end of output #166

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions bin/test/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ let ansi_color_strip str =
in
loop 0

let trim_end s =
let l = String.length s in
let rec f i =
if i > l
then
i
else
match s.[l - i - 1] with
| ' ' | '\t' | '\011'..'\013' -> f (succ i)
| _ -> i
in
String.sub s 0 (l - (f 0))
clecat marked this conversation as resolved.
Show resolved Hide resolved

let with_dir root f =
match root with
| None -> f ()
Expand Down Expand Up @@ -118,7 +131,7 @@ let run_cram_tests ?syntax t ?root ppf temp_file pad tests =
let n = run_test ?root blacklist temp_file test in
let lines = read_lines temp_file in
let output =
let output = List.map (fun x -> `Output x) lines in
let output = List.map (fun x -> `Output (trim_end x)) lines in
NathanReb marked this conversation as resolved.
Show resolved Hide resolved
if Output.equal output test.output then test.output
else Output.merge output test.output
in
Expand Down Expand Up @@ -167,7 +180,7 @@ let run_toplevel_tests ?root c ppf tests t =
let lines = lines (eval_test ?root t c test) in
let lines = split_lines lines in
let output =
let output = List.map (fun x -> `Output x) lines in
let output = List.map (fun x -> `Output (trim_end x)) lines in
if Output.equal output test.output then test.output
else output
in
Expand Down Expand Up @@ -340,7 +353,7 @@ let run_exn ()
match eval_test t ?root c test with
| Ok _ -> ()
| Error e ->
let output = List.map (fun l -> `Output l) e in
let output = List.map (fun x -> `Output (trim_end x)) e in
if Output.equal test.output output then ()
else err_eval ~cmd:test.command e
) tests
Expand Down