diff --git a/tests/common.ml b/tests/common.ml new file mode 100644 index 00000000..af8f2abc --- /dev/null +++ b/tests/common.ml @@ -0,0 +1,4 @@ +let normalize_html s = + String.trim s + |> Soup.parse + |> Soup.pretty_print diff --git a/tests/dune b/tests/dune index f8f6743d..6478096a 100644 --- a/tests/dune +++ b/tests/dune @@ -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 @@ -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 diff --git a/tests/extract_tests.ml b/tests/extract_tests.ml index 4a377bed..886eef00 100644 --- a/tests/extract_tests.ml +++ b/tests/extract_tests.ml @@ -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 = @@ -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; @@ -117,18 +117,13 @@ let write_dune_file test_specs tests = "@[(alias@ (name runtest)@ @[(deps%t)@])@]@." (fun ppf -> List.iter (pp ppf) tests) -let li_begin_re = Str.regexp_string "
  • \n" -let li_end_re = Str.regexp_string "\n
  • " - -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 diff --git a/tests/omd.ml b/tests/omd.ml index 03119d65..9f55eaf1 100644 --- a/tests/omd.ml +++ b/tests/omd.ml @@ -1,10 +1,3 @@ -(* let li_begin_re = Str.regexp_string "
  • \n" - * let li_end_re = Str.regexp_string "\n
  • " *) - -(* let normalize_html s = - * Str.global_replace li_end_re "" - * (Str.global_replace li_begin_re "
  • " s) *) - let with_open_in fn f = let ic = open_in fn in Fun.protect ~finally:(fun () -> close_in_noerr ic) @@ -12,22 +5,9 @@ let with_open_in fn f = (* 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 "
    ", "
    \n" - (* ; Str.regexp_string ">\n\n", ">\n" *) - (* ; Str.regexp "\n\n$", "\n" *) - (* Str.regexp "\"/>", "\" />" - * ; Str.regexp_string "
    ", "
    \n" - * ; Str.regexp_string "
      ", "
        \n" - * ; Str.regexp_string "", "\n" - * ; Str.regexp_string "

          ", "

          \n
            " - * ; Str.regexp_string "

          ", "

        \n

        " - * ; Str.regexp_string "

          <", "
            \n<" - * ; Str.regexp_string "
              <", "
                \n<" *) + ; Str.regexp_string "
                \n
                 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
                 
                @@ -49,6 +27,6 @@ let () =
                   ic
                   |> Omd.of_channel
                   |> html_of_omd
                -  |> normalize_html
                +  |> Common.normalize_html
                   |> denormalize_html
                   |> print_string