diff options
| author | lWarne <laurencewarne@gmail.com> | 2021-12-13 13:48:58 +0000 |
|---|---|---|
| committer | Bozhidar Batsov <bozhidar@batsov.dev> | 2021-12-20 13:44:46 +0200 |
| commit | f753cdbcf890ea935888d8fa30f5f497e65ae0c4 (patch) | |
| tree | ffd1ab93301578c4f5adff57084aa0e40c747416 /doc | |
| parent | 139cb02e20894cdf874d7a65659ef58d4b8f268b (diff) | |
Update documentation around test/src-dir and update sbt project type
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/modules/ROOT/pages/projects.adoc | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/doc/modules/ROOT/pages/projects.adoc b/doc/modules/ROOT/pages/projects.adoc index fd71282..9b9627a 100644 --- a/doc/modules/ROOT/pages/projects.adoc +++ b/doc/modules/ROOT/pages/projects.adoc @@ -483,35 +483,55 @@ This will keep all existing options for the `sbt` project type, but change the v === `:test-dir`/`:src-dir` vs `:related-files-fn` -Setting the `:test-dir` and `:src-dir` options to functions is useful if the -test location for a given implementation file is almost always going to be in -the same place across all projects belonging to a given project type, `maven` -projects are an example of this: +Whilst setting the `:test-dir` and `:src-dir` to strings is sufficient for most +purposes, using functions can give more flexibility. As an example consider +(also using `f.el`): [source,elisp] ---- +(defun my-get-python-test-file (impl-file-path) + "Return the corresponding test file directory for IMPL-FILE-PATH" + (let* ((rel-path (f-relative impl-file-path (projectile-project-root))) + (src-dir (car (f-split rel-path)))) + (cond ((f-exists-p (f-join (projectile-project-root) "test")) + (projectile-complementary-dir impl-file-path src-dir "test")) + ((f-exists-p (f-join (projectile-project-root) "tests")) + (projectile-complementary-dir impl-file-path src-dir "tests")) + (t (error "Could not locate a test file for %s!" impl-file-path))))) + +(defun my-get-python-impl-file (test-file-path) + "Return the corresponding impl file directory for TEST-FILE-PATH" + (if-let* ((root (projectile-project-root)) + (rel-path (f-relative test-file-path root)) + (src-dir-guesses `(,(f-base root) ,(downcase (f-base root)) "src")) + (src-dir (cl-find-if (lambda (d) (f-exists-p (f-join root d))) + src-dir-guesses))) + (projectile-complementary-dir test-file-path "tests?" src-dir) + (error "Could not locate a impl file for %s!" test-file-path))) + (projectile-update-project-type - 'maven - :src-dir - (lambda (file-path) (projectile-complementary-dir file-path "test" "main")) - :test-dir - (lambda (file-path) (projectile-complementary-dir file-path "main" "test"))) + 'python-pkg + :src-dir #'my-get-python-impl-dir + :test-dir #'my-get-python-test-dir) ---- -If instead you work on a lot of elisp projects using `eldev`, the -`:related-files-fn` option may be more appropriate since the test locations tend -to vary across projects: +This attempts to recognise projects using both `test` and `tests` as top level +directories for test files. An alternative using the `related-files-fn` option +could be: [source,elisp] ---- (projectile-update-project-type - 'emacs-eldev + 'python-pkg :related-files-fn (list - (projectile-related-files-fn-test-with-suffix "el" "-test") - (projectile-related-files-fn-test-with-prefix "el" "test-"))) + (projectile-related-files-fn-test-with-suffix "py" "_test") + (projectile-related-files-fn-test-with-prefix "py" "test_"))) ---- +In fact this is a lot more flexible in terms of finding test files in different +locations, but will not create test files for you. + == Customizing Project Detection Project detection is pretty simple - Projectile just runs a list of |
