tpapp / julia-repl

Run an inferior Julia REPL in a terminal inside Emacs
Other
169 stars 35 forks source link

Extra functionality: run tests in runtests.jl #142

Open CasBex opened 1 year ago

CasBex commented 1 year ago

In my development workflow I like to write lots of tests and comment in/out in runtests.jl when necessary. To aid with this I have written two functions to automatically run tests either using Pkg.test() or using include("project/test/runtests.jl") to avoid recompiling every time. I was wondering whether you would be interested in adding these to the repo?

To not keep you in suspense the definitions are below

  (defun julia-repl-run-tests (arg)
    (interactive "P")
    (julia-repl-activate-parent arg)
    (julia-repl--send-string "Pkg.test()"))
  (defun julia-repl-include-tests (arg)
    (interactive "P")
    (if arg
    (progn
      (message "activating home project")
      (julia-repl--send-string "import Pkg; Pkg.activate()"))
      (cl-flet ((find-projectfile (filename)
                  (locate-dominating-file (buffer-file-name) filename)))
    (if-let ((projectfile (or (find-projectfile "Project.toml")
                  (find-projectfile "JuliaProject.toml"))))
        (progn
          (message "activating %s" projectfile)
          (julia-repl--send-string
           (concat "import Pkg; Pkg.activate(\""
               (expand-file-name (file-name-directory projectfile))
               "\"); include(\""
               (expand-file-name
            (concat (file-name-directory projectfile)
                (file-name-as-directory "test")
                "runtests.jl"))
               "\")")))
      (message "could not find project file")))))

You will notice that the last one is mainly a copy of julia-repl-activate-parent. It may thus be interesting to create an auxiliary function julia-repl-find-project-directory to avoid code duplication