Skip to content

Commit

Permalink
Merge pull request #309 from juergenhoetzel/fsi-tests
Browse files Browse the repository at this point in the history
Add FSI tests
  • Loading branch information
juergenhoetzel committed Jun 19, 2022
2 parents 03fc1f4 + 7d82855 commit 20ca755
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions test/fsi-tests.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
;;; fsi-tests.el --- Tests for F# interactive -*- lexical-binding: t; -*-

;; Copyright (C) 2022 Jürgen Hötzel

;; Author: Jürgen Hötzel <juergen@hoetzel.info>
;; Keywords: processes

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(load "project") ;Emacs 27 workaround: https://github.com/joaotavora/eglot/issues/549
(require 'buttercup)
(require 'fsharp-mode)

(defun fsi-tests-wait-for-regex (timeout regexp)
(while (and (> timeout 0) (not (progn (goto-char (point-min)) (search-forward-regexp regexp nil t))))
(message "[FSI Interactive] Waiting a bit...")
(accept-process-output (get-buffer-process (current-buffer)) 0.2)
(setq timeout (1- timeout))))


(describe "F# interactive"
:before-all (run-fsharp inferior-fsharp-program)
:before-each (with-current-buffer (get-buffer inferior-fsharp-buffer-name)
(comint-clear-buffer))
(it "can eval expressions"
(let ((fsharp-autosave-on-file-load t)
(fsx-file (make-temp-file "fsi" nil ".fsx" "
1 + 1;;
")))
(with-current-buffer (find-file-noselect fsx-file)
(fsharp-eval-region (point-min) (point-max))
(with-current-buffer (get-buffer inferior-fsharp-buffer-name)
(fsi-tests-wait-for-regex 25 "it: int = 2$")
(let ((result (match-string-no-properties 0)))
(expect result :to-equal "it: int = 2"))))))
(it "can load nuget references"
(let ((fsharp-autosave-on-file-load t)
(timeout 50)
(fsx-file (make-temp-file "fsi" nil ".fsx" "
#r \"nuget: Newtonsoft.Json\";;
open Newtonsoft.Json;;
let o = {| X = 2; Y = \"Hello\" |};;
printfn \"xxx:%s:xxx\" (JsonConvert.SerializeObject o);;")))
(with-current-buffer (find-file-noselect fsx-file)
(fsharp-load-buffer-file)
(with-current-buffer (get-buffer inferior-fsharp-buffer-name)
(fsi-tests-wait-for-regex 25 "xxx:\\(.*\\):xxx")
(let ((json-str (match-string-no-properties 1)))
(unless json-str
(warn "FSI output doesn't contain marker: %s" (buffer-substring-no-properties (point-min) (point-max))))
(expect json-str :to-equal "{\"X\":2,\"Y\":\"Hello\"}")))))))

(provide 'fsi-tests)
;;; fsi-tests.el ends here

0 comments on commit 20ca755

Please sign in to comment.