Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
(On my machine in any case.)
  • Loading branch information
shonfeder committed Jan 22, 2021
1 parent 60fb234 commit 9409796
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 53 deletions.
4 changes: 4 additions & 0 deletions tests/common.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let normalize_html s =
String.trim s
|> Soup.parse
|> Soup.pretty_print
10 changes: 8 additions & 2 deletions tests/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
(executable
(name extract_tests)
(libraries str lambdasoup)
(libraries str common)
(modules extract_tests))

; Code shared between various parts of the testing apartus
(library
(name common)
(libraries lambdasoup)
(modules common))

; Generate and run tests for the core omd package
(rule
(with-stdout-to
Expand All @@ -16,7 +22,7 @@

(executable
(name omd)
(libraries str omd omd_tyxml tyxml lambdasoup)
(libraries str omd omd_tyxml tyxml common)
(modules omd))

; Generate the rules for diff-based tests
Expand Down
49 changes: 22 additions & 27 deletions tests/extract_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

let disabled =
[
164;
175;
184;
185;
334;
353;
410;
411;
414;
415;
416;
428;
468;
469;
486;
516;
536;
570;
519;
591;
(* 164;
* 175;
* 184;
* 185;
* 334;
* 353;
* 410;
* 411;
* 414;
* 415;
* 416;
* 428;
* 468;
* 469;
* 486;
* 516;
* 536;
* 570;
* 519;
* 591; *)
]

let with_open_in fn f =
Expand Down Expand Up @@ -75,7 +75,7 @@ let parse_test_spec filename =
let rec get_html () =
let line = input_line ic in
if begins_with line test_delim then
let html = Buffer.contents buf in
let html = Buffer.contents buf |> Common.normalize_html in
{filename; example; markdown; html}
else begin
add_line buf line;
Expand Down Expand Up @@ -117,18 +117,13 @@ let write_dune_file test_specs tests =
"@[<v1>(alias@ (name runtest)@ @[<v1>(deps%t)@])@]@."
(fun ppf -> List.iter (pp ppf) tests)

let li_begin_re = Str.regexp_string "<li>\n"
let li_end_re = Str.regexp_string "\n</li>"

let normalize_html s = Soup.(parse s |> pretty_print)

let generate_test_files tests =
let f {filename; example; markdown; html} =
let base = Filename.remove_extension filename in
with_open_out (Printf.sprintf "%s-%03d.md" base example)
(fun oc -> output_string oc markdown);
with_open_out (Printf.sprintf "%s-%03d.html" base example)
(fun oc -> output_string oc (normalize_html html))
(fun oc -> output_string oc html)
in
List.iter f tests

Expand Down
26 changes: 2 additions & 24 deletions tests/omd.ml
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
(* let li_begin_re = Str.regexp_string "<li>\n"
* let li_end_re = Str.regexp_string "\n</li>" *)

(* let normalize_html s =
* Str.global_replace li_end_re "</li>"
* (Str.global_replace li_begin_re "<li>" s) *)

let with_open_in fn f =
let ic = open_in fn in
Fun.protect ~finally:(fun () -> close_in_noerr ic)
(fun () -> f ic)

(* FIXME: Resolve preferred backend *)

(* FIXME: This is getting rediculous. Probably better, imo, to programmatically
format the spec HTML and compare the ASTs of the HTMl instead of doing this
string munging *)

let replacements =
[ Str.regexp_string "<br>", "<br>\n"
(* ; Str.regexp_string ">\n\n</a>", ">\n</a>" *)
(* ; Str.regexp "\n\n$", "\n" *)
(* Str.regexp "\"/>", "\" />"
* ; Str.regexp_string "<br/>", "<br />\n"
* ; Str.regexp_string "<ul>", "<ul>\n"
* ; Str.regexp_string "</li>", "</li>\n"
* ; Str.regexp_string "</p><ul>", "</p>\n<ul>"
* ; Str.regexp_string "</ul><p>", "</ul>\n<p>"
* ; Str.regexp_string "<ol><", "<ol>\n<"
* ; Str.regexp_string "<ul><", "<ul>\n<" *)
; Str.regexp_string "</pre><pre ", "</pre>\n<pre "
]


Expand All @@ -39,8 +19,6 @@ let html_of_omd s =
|> List.map (fun b -> b |> Omd_tyxml.of_block |> tyxml_elt_to_string)
|> String.concat ""

let normalize_html s = Soup.(parse s |> pretty_print)

let denormalize_html str =
List.fold_left (fun s (re, rep) -> Str.global_replace re rep s) str replacements

Expand All @@ -49,6 +27,6 @@ let () =
ic
|> Omd.of_channel
|> html_of_omd
|> normalize_html
|> Common.normalize_html
|> denormalize_html
|> print_string

0 comments on commit 9409796

Please sign in to comment.