src/Tools/quickcheck.ML
changeset 74508 3315c551fe6e
parent 73583 ed5226fdf89d
child 74561 8e6c973003c8
equal deleted inserted replaced
74507:a241eadc0e3f 74508:3315c551fe6e
   536     "try to find counterexample for subgoal"
   536     "try to find counterexample for subgoal"
   537     (parse_args -- Scan.optional Parse.nat 1 >>
   537     (parse_args -- Scan.optional Parse.nat 1 >>
   538       (fn (args, i) => Toplevel.keep_proof (quickcheck_cmd args i)));
   538       (fn (args, i) => Toplevel.keep_proof (quickcheck_cmd args i)));
   539 
   539 
   540 
   540 
   541 (* automatic testing *)
   541 (* 'try' setup *)
   542 
   542 
   543 fun try_quickcheck auto state =
   543 val _ =
   544   let
   544   Try.tool_setup
   545     val ctxt = Proof.context_of state;
   545    {name = quickcheckN, weight = 20, auto_option = \<^system_option>\<open>auto_quickcheck\<close>,
   546     val i = 1;
   546     body = fn auto => fn state =>
   547     val res =
   547       let
   548       state
   548         val ctxt = Proof.context_of state;
   549       |> Proof.map_context (Config.put report false #> Config.put quiet true)
   549         val i = 1;
   550       |> try (test_goal (false, false) ([], []) i);
   550         val res =
   551   in
   551           state
   552     (case res of
   552           |> Proof.map_context (Config.put report false #> Config.put quiet true)
   553       NONE => (unknownN, [])
   553           |> try (test_goal (false, false) ([], []) i);
   554     | SOME results =>
   554       in
   555         let
   555         (case res of
   556           val msg =
   556           NONE => (unknownN, [])
   557             Pretty.string_of
   557         | SOME results =>
   558               (pretty_counterex ctxt auto (Option.map (the o get_first response_of) results))
   558             let
   559         in
   559               val msg =
   560           if is_some results then (genuineN, if auto then [msg] else (writeln msg; []))
   560                 Pretty.string_of
   561           else (noneN, [])
   561                   (pretty_counterex ctxt auto (Option.map (the o get_first response_of) results))
   562         end)
   562             in
   563   end
   563               if is_some results then (genuineN, if auto then [msg] else (writeln msg; []))
   564   |> `(fn (outcome_code, _) => outcome_code = genuineN);
   564               else (noneN, [])
   565 
   565             end)
   566 val _ = Try.tool_setup (quickcheckN, (20, \<^system_option>\<open>auto_quickcheck\<close>, try_quickcheck));
   566       end
       
   567       |> `(fn (outcome_code, _) => outcome_code = genuineN)};
   567 
   568 
   568 end;
   569 end;
   569