branch: elpa/idris-mode
commit aa580b61eb3d409ae9ceb141547937ad27fae24c
Merge: 37c6b81990 658229f1d1
Author: Jan de Muijnck-Hughes <j...@users.noreply.github.com>
Commit: GitHub <nore...@github.com>

    Merge pull request #623 from keram/issue-622-idris-start-project-ipkg
    
    Add quotes around sourcedir value in generated .ipkg file
---
 idris-commands.el           |  2 +-
 test/idris-commands-test.el | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/idris-commands.el b/idris-commands.el
index 6c72fa5ef6..95975e1aab 100644
--- a/idris-commands.el
+++ b/idris-commands.el
@@ -1275,7 +1275,7 @@ of the term to replace."
     (newline)
     (insert "opts = \"\"")
     (newline)
-    (when src-dir (insert "sourcedir = " src-dir) (newline))
+    (when src-dir (insert "sourcedir = \"" src-dir "\"") (newline))
     (insert "modules = ")
     (insert first-mod)
     (newline)
diff --git a/test/idris-commands-test.el b/test/idris-commands-test.el
index ec5b6fda4d..4d1f95e49a 100644
--- a/test/idris-commands-test.el
+++ b/test/idris-commands-test.el
@@ -280,6 +280,39 @@ myReverse xs = revAcc [] xs where
         (kill-buffer buffer)
         (idris-quit)))))
 
+(ert-deftest idris-test-idris-start-project ()
+  "Test generating valid .ipkg file."
+  (let ((mock-project-name "TestProject")
+        (mock-package-file-name "test-project.ipkg")
+        (mock-source-directory "src")
+        (mock-first-module "TestModule")
+        (mock-directory-name "test-start-project"))
+    (unwind-protect
+        (cl-letf (((symbol-function 'read-string)
+                   (lambda (prompt &rest _)
+                     (cond ((string-prefix-p "Project name:" prompt)
+                            mock-project-name)
+                           ((string-prefix-p "Package file name" prompt)
+                            mock-package-file-name)
+                           ((string-prefix-p "Source directory" prompt)
+                            mock-source-directory)
+                           ((string-prefix-p "First module name" prompt)
+                            mock-first-module))))
+                  ((symbol-function 'read-directory-name)
+                   (lambda (&rest _) mock-directory-name)))
+          (idris-start-project)
+          (with-current-buffer mock-package-file-name
+            (goto-char (point-min))
+            (should (search-forward "package test-project"))
+            (should (search-forward "opts = \"\""))
+            (should (search-forward "sourcedir = \"src\""))
+            (should (search-forward "modules = TestModule"))
+            (kill-buffer)))
+      (if (get-buffer (concat mock-first-module ".idr"))
+          (kill-buffer (concat mock-first-module ".idr")))
+      (delete-directory mock-directory-name t)
+      (idris-quit))))
+
 ;; Tests by Yasuhiko Watanabe
 ;; https://github.com/idris-hackers/idris-mode/pull/537/files
 (idris-ert-command-action "test-data/CaseSplit.idr" idris-case-split 
idris-test-eq-buffer)

Reply via email to