(in-package "KPML-I")

;;; 4.2, Dec 2007, Bremen
;;; First cut at regrression tests supported from the GUI.
;;;

(defun REGRESSION-TEST (example-list)
  (let* ((results-hash (make-hash-table))
         (patch-directories (kpml::get-patches-to-check))
         (old-loading-saving-profile kpml::*loading-saving-profile*)
         (diffs nil)
         )
    (when patch-directories
      (example-runner-noting-progress 
       example-list "Regression testing on all examples loaded (pre)")
      (loop for ex in example-list
            do (setf (gethash ex results-hash) 
                     (kpml::fetch-example-info ex  'kpml-i::generatedform)))
      ;;
      ;; first cycle done, now load the selected patches...
      ;;
      (setf kpml::*patch-status* T)
      (unless (or (member :systems kpml::*loading-saving-profile*)
                  (member :choosers kpml::*loading-saving-profile*)
                  (member :inquiries kpml::*loading-saving-profile*))      ;; 0.9.23a
        (kpml::reset-loading-saving-profile))
      (loop for patches-directory in patch-directories             ;; 1.0.20
            do
            (kpml::load-single-language-resources 
             kpml::curlan patches-directory :clear nil))
      (setf kpml::*loading-saving-profile* old-loading-saving-profile)
      ;; 2.1 following should have coerce the result to boolean but didn't...
      (setf kpml::*patch-status* 
            (if (member :resource-patches
                        kpml::*loading-saving-profile*) T nil))

      (example-runner-noting-progress 
       example-list "Regression testing on all examples loaded (post)")
      (loop for ex in example-list
            unless (equal (gethash ex results-hash) 
                          (kpml::fetch-example-info ex  'kpml-i::generatedform))
            collect ex))
    ))

