@@ -556,4 +556,74 @@ moves over sexps."
556
556
(should (equal " -e\n -x\n ./T1.hs\n ./src/T2.hs\n "
557
557
(buffer-substring (point-min ) (point-max ))))))))
558
558
559
+ (defun haskell-stylish-haskell-add-first-line ()
560
+ (message-stdout " -- HEADER" )
561
+ (let (line)
562
+ (while (setq line (read-stdin))
563
+ (message-stdout line))))
564
+
565
+ (defun haskell-stylish-haskell-no-change ()
566
+ (let (line)
567
+ (while (setq line (read-stdin))
568
+ (message-stdout line))))
569
+
570
+ (defun haskell-stylish-haskell-bad-exit-code ()
571
+ (when noninteractive
572
+ (kill-emacs 34 )))
573
+
574
+ (defun haskell-stylish-haskell-error-message ()
575
+ (message-stderr " Something wrong" ))
576
+
577
+ (ert-deftest haskell-stylish-on-save-add-first-line ()
578
+ (with-temp-dir-structure
579
+ ((" T.hs" . " main :: IO ()" ))
580
+ (with-script-path
581
+ haskell-mode-stylish-haskell-path
582
+ haskell-stylish-haskell-add-first-line
583
+ (let ((haskell-stylish-on-save t ))
584
+ (with-current-buffer (find-file-noselect " T.hs" )
585
+ (insert " main = return ()\n " )
586
+ (save-buffer )
587
+ (goto-char (point-min ))
588
+ (should (looking-at-p " -- HEADER" )))))))
589
+
590
+ (ert-deftest haskell-stylish-on-save-no-change ()
591
+ (with-temp-dir-structure
592
+ ((" T.hs" . " main :: IO ()" ))
593
+ (with-script-path
594
+ haskell-mode-stylish-haskell-path
595
+ haskell-stylish-haskell-no-change
596
+ (let ((haskell-stylish-on-save t ))
597
+ (with-current-buffer (find-file-noselect " T.hs" )
598
+ (insert " main = return ()\n " )
599
+ (save-buffer )
600
+ (goto-char (point-min ))
601
+ (should (looking-at-p " main = return" )))))))
602
+
603
+ (ert-deftest haskell-stylish-on-save-bad-exit-code ()
604
+ (with-temp-dir-structure
605
+ ((" T.hs" . " main :: IO ()" ))
606
+ (with-script-path
607
+ haskell-mode-stylish-haskell-path
608
+ haskell-stylish-haskell-bad-exit-code
609
+ (let ((haskell-stylish-on-save t ))
610
+ (with-current-buffer (find-file-noselect " T.hs" )
611
+ (insert " main = return ()\n " )
612
+ (save-buffer )
613
+ (goto-char (point-min ))
614
+ (should (looking-at-p " main = return ()" )))))))
615
+
616
+ (ert-deftest haskell-stylish-on-save-error-message ()
617
+ (with-temp-dir-structure
618
+ ((" T.hs" . " main :: IO ()" ))
619
+ (with-script-path
620
+ haskell-mode-stylish-haskell-path
621
+ haskell-stylish-haskell-error-message
622
+ (let ((haskell-stylish-on-save t ))
623
+ (with-current-buffer (find-file-noselect " T.hs" )
624
+ (insert " main = return ()\n " )
625
+ (save-buffer )
626
+ (goto-char (point-min ))
627
+ (should (looking-at-p " main = return ()" )))))))
628
+
559
629
(provide 'haskell-mode-tests )
0 commit comments