[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/projectile f753cdbcf8 5/9: Update documentation around tes
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/projectile f753cdbcf8 5/9: Update documentation around test/src-dir and update sbt project type |
Date: |
Mon, 27 Dec 2021 07:58:01 -0500 (EST) |
branch: elpa/projectile
commit f753cdbcf890ea935888d8fa30f5f497e65ae0c4
Author: lWarne <laurencewarne@gmail.com>
Commit: Bozhidar Batsov <bozhidar@batsov.dev>
Update documentation around test/src-dir and update sbt project type
---
doc/modules/ROOT/pages/projects.adoc | 50 +++++++++++++++++++++++++-----------
projectile.el | 2 ++
2 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/doc/modules/ROOT/pages/projects.adoc
b/doc/modules/ROOT/pages/projects.adoc
index fd71282266..9b9627aea3 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
diff --git a/projectile.el b/projectile.el
index c2b3e33356..75e5b8da77 100644
--- a/projectile.el
+++ b/projectile.el
@@ -3135,6 +3135,8 @@ a manual COMMAND-TYPE command is created with
;; Scala
(projectile-register-project-type 'sbt '("build.sbt")
:project-file "build.sbt"
+ :src-dir "main"
+ :test-dir "test"
:compile "sbt compile"
:test "sbt test"
:test-suffix "Spec")
- [nongnu] elpa/projectile updated (ac60885f2a -> 24de2940a8), ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile fab2c546fd 8/9: Tweak a changelog entry, ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile f753cdbcf8 5/9: Update documentation around test/src-dir and update sbt project type,
ELPA Syncer <=
- [nongnu] elpa/projectile cd8bcbcb15 2/9: Merge pull request #1735 from eggert/timestamp, ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile f7eba5e164 6/9: Fix emacs 25 incompat in projectile--complementary-file, ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile 24de2940a8 9/9: Merge commit 'ac60885f2a', ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile b7937e212d 7/9: [#1734] Add a changelog entry, ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile 43decc573b 1/9: Port projectile-time-seconds to future Emacs, ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile fad389aecf 3/9: Make src/test-dir as strings take priority over fallback, ELPA Syncer, 2021/12/27
- [nongnu] elpa/projectile 139cb02e20 4/9: Fix tests, ELPA Syncer, 2021/12/27