Skip to content

Commit 42e8db5

Browse files
Merge pull request #317 from juergenhoetzel/test-code-cleanup
FSI tests: Code cleanup
2 parents 185bfc2 + 84f7369 commit 42e8db5

File tree

3 files changed

+34
-36
lines changed

3 files changed

+34
-36
lines changed

test/expression.fsx

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 + 1;;

test/fsi-tests.el

+27-36
Original file line numberDiff line numberDiff line change
@@ -29,45 +29,36 @@
2929
(require 'fsharp-mode)
3030

3131
(defun fsi-tests-wait-for-regex (timeout regexp)
32-
(while (and (> timeout 0) (not (progn (goto-char (point-min)) (search-forward-regexp regexp nil t))))
33-
(message "[FSI Interactive] Waiting a bit...")
34-
(accept-process-output (get-buffer-process (current-buffer)) 0.2)
35-
(setq timeout (1- timeout))))
32+
(let ((start-time (float-time)))
33+
(while (and (< (- (float-time) start-time) timeout)
34+
(not (progn (goto-char (point-min)) (search-forward-regexp regexp nil t))))
35+
(if (accept-process-output (get-buffer-process (current-buffer)) 0.2)
36+
(message "[FSI Interactive] received output...")
37+
(message "[FSI Interactive] waiting for output...")))))
3638

3739

3840
(describe "F# interactive"
39-
:before-all (run-fsharp inferior-fsharp-program)
40-
:before-each (with-current-buffer (get-buffer inferior-fsharp-buffer-name)
41-
(comint-clear-buffer))
42-
(it "can eval expressions"
43-
(let ((fsharp-autosave-on-file-load t)
44-
(fsx-file (make-temp-file "fsi" nil ".fsx" "
45-
1 + 1;;
46-
")))
47-
(with-current-buffer (find-file-noselect fsx-file)
48-
(fsharp-eval-region (point-min) (point-max))
49-
(with-current-buffer (get-buffer inferior-fsharp-buffer-name)
50-
(fsi-tests-wait-for-regex 25 "it: int = 2$")
51-
(let ((result (match-string-no-properties 0)))
52-
(expect result :to-equal "it: int = 2"))))))
53-
(it "can load nuget references"
54-
(let ((fsharp-autosave-on-file-load t)
55-
(timeout 50)
56-
(fsx-file (make-temp-file "fsi" nil ".fsx" "
57-
#r \"nuget: Newtonsoft.Json\";;
58-
open Newtonsoft.Json;;
59-
60-
let o = {| X = 2; Y = \"Hello\" |};;
61-
62-
printfn \"xxx:%s:xxx\" (JsonConvert.SerializeObject o);;")))
63-
(with-current-buffer (find-file-noselect fsx-file)
64-
(fsharp-load-buffer-file)
65-
(with-current-buffer (get-buffer inferior-fsharp-buffer-name)
66-
(fsi-tests-wait-for-regex 25 "xxx:\\(.*\\):xxx")
67-
(let ((json-str (match-string-no-properties 1)))
68-
(unless json-str
69-
(warn "FSI output doesn't contain marker: %s" (buffer-substring-no-properties (point-min) (point-max))))
70-
(expect json-str :to-equal "{\"X\":2,\"Y\":\"Hello\"}")))))))
41+
:before-all (run-fsharp inferior-fsharp-program)
42+
:before-each (with-current-buffer (get-buffer inferior-fsharp-buffer-name)
43+
(comint-clear-buffer))
44+
(it "can eval expressions"
45+
(with-current-buffer (find-file-noselect "test/expression.fsx")
46+
(fsharp-eval-region (point-min) (point-max))
47+
(with-current-buffer (get-buffer inferior-fsharp-buffer-name)
48+
(fsi-tests-wait-for-regex 25 "it: int = 2$")
49+
(let ((result (match-string-no-properties 0)))
50+
(expect result :to-equal "it: int = 2")))))
51+
(it "can load nuget references"
52+
(let ((timeout 50)
53+
(fsx-file "test/nuget.fsx"))
54+
(with-current-buffer (find-file-noselect fsx-file)
55+
(fsharp-load-buffer-file)
56+
(with-current-buffer (get-buffer inferior-fsharp-buffer-name)
57+
(fsi-tests-wait-for-regex 25 "xxx:\\(.*\\):xxx")
58+
(let ((json-str (match-string-no-properties 1)))
59+
(unless json-str
60+
(warn "FSI output doesn't contain marker: %s" (buffer-substring-no-properties (point-min) (point-max))))
61+
(expect json-str :to-equal "{\"X\":2,\"Y\":\"Hello\"}")))))))
7162

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

test/nuget.fsx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#r "nuget: Newtonsoft.Json";;
2+
open Newtonsoft.Json;;
3+
4+
let o = {| X = 2; Y = "Hello" |};;
5+
6+
printfn "xxx:%s:xxx" (JsonConvert.SerializeObject o);;

0 commit comments

Comments
 (0)