|
29 | 29 | (require 'fsharp-mode)
|
30 | 30 |
|
31 | 31 | (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..."))))) |
36 | 38 |
|
37 | 39 |
|
38 | 40 | (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\"}"))))))) |
71 | 62 |
|
72 | 63 | (provide 'fsi-tests)
|
73 | 64 | ;;; fsi-tests.el ends here
|
0 commit comments