 If ARG is non nil then `dotspacemacs/config' is skipped."
   (interactive "P")
   (when (file-exists-p dotspacemacs-filepath)
-    (with-current-buffer (find-file-noselect dotspacemacs-filepath)
-      (let ((dotspacemacs-loading-progress-bar nil))
-        (setq spacemacs-loading-string "")
-        (save-buffer)
-        (load-file buffer-file-name)
-        (dotspacemacs|call-func dotspacemacs/init "Calling dotfile init...")
-        (configuration-layer/sync)
-        (if arg
-            (message "Done (`dotspacemacs/config' function has been skipped).")
-          (dotspacemacs|call-func dotspacemacs/config
-                                  "Calling dotfile config...")
-          (message "Done."))
-        (when (configuration-layer/package-usedp 'powerline)
-          (spacemacs//restore-powerline (current-buffer)))))))
+    (let ((tests-ok (dotspacemacs/test-dotfile t)))
+      (if tests-ok
+          (with-current-buffer (find-file-noselect dotspacemacs-filepath)
+            (let ((dotspacemacs-loading-progress-bar nil))
+              (setq spacemacs-loading-string "")
+              (save-buffer)
+              (load-file buffer-file-name)
+              (dotspacemacs|call-func dotspacemacs/init "Calling dotfile init...")
+              (configuration-layer/sync)
+              (if arg
+                  (message "Done (`dotspacemacs/config' function has been skipped).")
+                (dotspacemacs|call-func dotspacemacs/config
+                                        "Calling dotfile config...")
+                (message "Done."))
+              (when (configuration-layer/package-usedp 'powerline)
+                (spacemacs//restore-powerline (current-buffer)))))
+        (switch-to-buffer-other-window dotspacemacs-test-results-buffer)
+        (spacemacs-buffer/warning "Some tests failed, check `%s' buffer"
+                                  dotspacemacs-test-results-buffer)))))
 
 (defmacro dotspacemacs|symbol-value (symbol)
   "Return the value of SYMBOL corresponding to a dotspacemacs variable.

     'dotspacemacs-configuration-layers  "can be found" "layer")
    (insert (format
             "** RESULTS: [[file:%s::dotspacemacs/layers][dotspacemacs/layers]] passed %s out of %s tests\n"
             dotspacemacs-filepath passed-tests total-tests))))

(defun dotspacemacs//test-dotspacemacs/init ()
  "Tests for `dotspacemacs/init'"

    (spacemacs//test-var 'stringp 'dotspacemacs-command-key "is a string")
    (insert (format
             "** RESULTS: [[file:%s::dotspacemacs/init][dotspacemacs/init]] passed %s out of %s tests\n"
             dotspacemacs-filepath passed-tests total-tests))
    (equal passed-tests total-tests)))

(defun dotspacemacs/test-dotfile (&optional hide-buffer)
  "Test settings in dotfile for correctness.
 Return non-nil if all the tests passed."
  (interactive)
  (let ((min-version "0.0"))
    ;; dotspacemacs-version not implemented yet
    ;; (if (version< dotspacemacs-version min-version)
    (if nil
        (error (format "error: dotspacemacs/test-dotfile requires dotspacemacs-version %s" min-version))
      (with-current-buffer (get-buffer-create dotspacemacs-test-results-buffer)
        (unless hide-buffer
          (switch-to-buffer-other-window dotspacemacs-test-results-buffer))
        (erase-buffer)
        (org-mode)
        (insert (format "* Running tests on [[file:%s][%s]] (v%s)\n"
                        dotspacemacs-filepath dotspacemacs-filepath "0.0"))
        ;; dotspacemacs-version not implemented yet
        ;; (insert (format "* Running tests on %s (v%s)\n" dotspacemacs-filepath dotspacemacs-version))
        (prog1
            (and (dotspacemacs//test-dotspacemacs/layers)
                 (dotspacemacs//test-dotspacemacs/init))
          (goto-char (point-min)))))))

(provide 'core-dotspacemacs)
