src/HOL/Spec_Check/output_style.ML
author wenzelm
Thu, 30 May 2013 20:57:55 +0200
changeset 52253 afca6a99a361
parent 52252 81fcc11d8c65
child 52254 994055f7db80
permissions -rw-r--r--
more conventional spelling and grammar;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     1
(*  Title:      HOL/Spec_Check/output_style.ML
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     2
    Author:     Lukas Bulwahn and Nicolai Schaffroth, TU Muenchen
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     3
    Author:     Christopher League
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     4
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     5
Output styles for presenting Spec_Check's results.
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     6
*)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     7
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     8
structure Perl_Style =
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
     9
struct
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    10
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    11
local
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    12
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    13
open StringCvt
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    14
52253
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    15
fun new context tag =
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    16
  let
52253
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    17
    val target = Config.get_generic context Spec_Check.gen_target
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    18
    val namew = Config.get_generic context Spec_Check.column_width
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    19
    val sort_examples = Config.get_generic context Spec_Check.sort_examples
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    20
    val show_stats = Config.get_generic context Spec_Check.show_stats
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    21
    val limit = Config.get_generic context Spec_Check.examples
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    22
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    23
    val resultw = 8
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    24
    val countw = 20
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    25
    val allw = namew + resultw + countw + 2
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    26
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    27
    val maybe_sort = if sort_examples then sort (int_ord o pairself size) else I
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    28
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    29
    fun result ({count=0,...}, _) _ = "dubious"
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    30
      | result (_ : Property.stats, badobjs) false = if null badobjs then "ok" else "FAILED"
52252
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    31
      | result ({count,tags,...}, badobjs) true =
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    32
          if not (null badobjs) then "FAILED"
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    33
          else if AList.defined (op =) tags "__GEN" andalso count < target then "dubious"
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    34
          else "ok"
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    35
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    36
    fun ratio (0, _) = "(0/0 passed)"
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    37
      | ratio (count, 0) = "(" ^ string_of_int count ^ " passed)"
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    38
      | ratio (count, n) = "(" ^ string_of_int (count - n) ^ "/" ^ string_of_int count ^  " passed)"
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    39
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    40
    fun update (stats, badobjs) donep =
52252
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    41
      "\r" ^ padRight #"." namew tag ^ "." ^ padRight #" " resultw (result (stats, badobjs) donep)
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    42
      ^ padRight #" " countw (ratio (#count stats, length badobjs))
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    43
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    44
    fun status (_, result, (stats, badobjs)) =
52250
4dced3d4155c standardized aliases;
wenzelm
parents: 52248
diff changeset
    45
      if Property.failure result then writeln (update (stats, badobjs) false) else ()
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    46
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    47
    fun prtag count (tag, n) first =
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    48
      if String.isPrefix "__" tag then ("", first)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    49
      else
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    50
         let
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    51
           val ratio = round ((real n / real count) * 100.0)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    52
         in
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    53
           (((if first then "" else padRight #" " allw "\n") ^
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    54
             padLeft #" " 3 (string_of_int ratio) ^ "% " ^ tag),
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    55
           false)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    56
         end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    57
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    58
    fun prtags ({count, tags, ...} : Property.stats) =
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    59
      if show_stats then cat_lines (fst (fold_map (prtag count) tags true)) else ""
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    60
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    61
    fun err badobjs =
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    62
      let
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    63
        fun iter [] _ = ()
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    64
          | iter (e :: es) k =
52250
4dced3d4155c standardized aliases;
wenzelm
parents: 52248
diff changeset
    65
              (writeln (padLeft #" " namew (if k > 0 then "" else "counter-examples")
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    66
                ^ padRight #" " resultw (if k > 0 then "" else ":") ^ e);
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    67
              iter es (k + 1))
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    68
      in
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    69
        iter (maybe_sort (take limit (map_filter I badobjs))) 0
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    70
      end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    71
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    72
    fun finish (stats, badobjs) =
52250
4dced3d4155c standardized aliases;
wenzelm
parents: 52248
diff changeset
    73
      if null badobjs then writeln (update (stats, badobjs) true ^ prtags stats)
4dced3d4155c standardized aliases;
wenzelm
parents: 52248
diff changeset
    74
      else (writeln (update (stats, badobjs) true); err badobjs)
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    75
  in
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    76
    {status=status, finish=finish}
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    77
  end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    78
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    79
in
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    80
  val setup = Spec_Check.register_style ("Perl", new)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    81
end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    82
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    83
end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    84
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    85
(* CM style: meshes with CM output; highlighted in sml-mode *)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    86
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    87
structure CMStyle =
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    88
struct
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    89
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    90
local
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    91
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    92
fun pad wd = StringCvt.padLeft #"0" wd o Int.toString
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    93
52253
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    94
fun new context tag =
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
    95
  let
52253
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
    96
    val gen_target = Config.get_generic context Spec_Check.gen_target
52251
2c141c169624 removed pointless comment -- NB: Isabelle output is message-oriented with implicit line-boundaries;
wenzelm
parents: 52250
diff changeset
    97
    val _ = writeln ("[testing " ^ tag ^ "... ")
52252
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    98
    fun finish ({count, ...}, badobjs) =
81fcc11d8c65 minor tuning -- more linebreaks;
wenzelm
parents: 52251
diff changeset
    99
      (case (count, badobjs) of
52250
4dced3d4155c standardized aliases;
wenzelm
parents: 52248
diff changeset
   100
        (0, []) => writeln ("no valid cases generated]")
4dced3d4155c standardized aliases;
wenzelm
parents: 52248
diff changeset
   101
      | (n, []) => writeln (
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   102
            if n >= gen_target then "ok]"
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   103
            else "ok on " ^ string_of_int n ^ "; " ^ string_of_int gen_target ^ " required]")
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   104
      | (_, es) =>
52253
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   105
          let
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   106
            val wd = size (string_of_int (length es))
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   107
            fun each (NONE, _) = ()
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   108
              | each (SOME e, i) = writeln (tag ^ ":" ^ pad wd i ^ ".0 Error: " ^ e)
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   109
          in
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   110
            (writeln "FAILED]"; map each (es ~~ (1 upto (length es))); ())
afca6a99a361 more conventional spelling and grammar;
wenzelm
parents: 52252
diff changeset
   111
          end)
52248
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   112
  in
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   113
    {status = K (), finish = finish}
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   114
  end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   115
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   116
in
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   117
  val setup = Spec_Check.register_style ("CM", new)
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   118
end
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   119
2c893e0c1def added Spec_Check -- a Quickcheck tool for Isabelle's ML environment;
bulwahn
parents:
diff changeset
   120
end