emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/javaimp 11f3f38: * javaimp-tests-gradle.el: New file


From: Filipp Gunbin
Subject: [elpa] externals/javaimp 11f3f38: * javaimp-tests-gradle.el: New file
Date: Tue, 16 Nov 2021 15:32:25 -0500 (EST)

branch: externals/javaimp
commit 11f3f38a2448ca85eb79132b44ff05b248318517
Author: Filipp Gunbin <fgunbin@fastmail.fm>
Commit: Filipp Gunbin <fgunbin@fastmail.fm>

    * javaimp-tests-gradle.el: New file
---
 javaimp-tests-gradle.el      |  49 +++++++++++++++++++++++++++++++++++++++++++
 javaimp-tests-maven.el       |  18 +---------------
 javaimp-tests.el             |  19 +++++++++++++++++
 testdata/gradle-multi.tar.gz | Bin 0 -> 399 bytes
 4 files changed, 69 insertions(+), 17 deletions(-)

diff --git a/javaimp-tests-gradle.el b/javaimp-tests-gradle.el
new file mode 100644
index 0000000..413c297
--- /dev/null
+++ b/javaimp-tests-gradle.el
@@ -0,0 +1,49 @@
+;;; javaimp-tests-gradle.el --- javaimp Gradle tests  -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2021-2021  Free Software Foundation, Inc.
+
+;; Author: Filipp Gunbin <fgunbin@fastmail.fm>
+;; Maintainer: Filipp Gunbin <fgunbin@fastmail.fm>
+
+(require 'ert)
+(require 'javaimp)
+(require 'javaimp-tests)
+
+;; Tests for Gradle project parsing.
+;;
+;; Note that you have to set up `javaimp-gradle-program' to point to
+;; Gradle installation, which is rather untypical for Gradle projects
+;; (most often, a "Gradle wrapper" is used, resulting in project-local
+;; copy of Gradle).
+
+(ert-deftest javaimp-test--gradle-visit-multi ()
+  :tags '(:runs-build-tool)
+  (javaimp-test--with-data
+   "gradle-multi.tar.gz"
+   (lambda (tmpdir)
+     (should
+      (equal
+       (javaimp-test--gradle-get-tree
+        (concat tmpdir (file-name-as-directory "multi")))
+       '((("<root>:org.example:1.0" . "build.gradle")
+          (("child:org.example:1.0" . "child/build.gradle")
+           (("child.grandchild:org.example:1.0" . 
"child/grandchild/build.gradle")))
+          ;; directory layout different from project layout
+          (("non-direct-child:org.example:1.0" . 
"foo/non-direct-child/build.gradle"))
+          )))))))
+
+(defun javaimp-test--gradle-get-tree (project-dir)
+  (javaimp--map-nodes
+   (lambda (mod)
+     (cons t
+           (cons (javaimp-print-id (javaimp-module-id mod))
+                 (file-relative-name
+                  (javaimp-module-file mod)
+                  ;; Gradle seems to report filenames with symlinks
+                  ;; resolved (so we get /private/var/ instead of
+                  ;; /var/ on macOS), so do it too
+                  (file-truename project-dir)))))
+   #'always
+   (javaimp--gradle-visit (concat project-dir "build.gradle"))))
+
+(provide 'javaimp-tests-gradle)
diff --git a/javaimp-tests-maven.el b/javaimp-tests-maven.el
index 2acf7ef..4dad154 100644
--- a/javaimp-tests-maven.el
+++ b/javaimp-tests-maven.el
@@ -7,6 +7,7 @@
 
 (require 'ert)
 (require 'javaimp)
+(require 'javaimp-tests)
 
 ;; Tests for Maven project parsing.
 
@@ -20,23 +21,6 @@
 ;; `<?xml version="1.0" encoding="UTF-8"?><settings/>'
 ;;
 
-(defun javaimp-test--with-data (filename handler)
-  "Untars testdata/FILENAME into temporary directory and runs
-HANDLER, supplying temp directory name as the only arg."
-  (let ((tmpdir (file-name-as-directory (make-temp-file "javaimp" t))))
-    (unwind-protect
-        (let ((rc (call-process
-                   "tar" nil nil nil
-                   "-x"
-                   "-f" (concat javaimp--basedir
-                                (file-name-as-directory "testdata")
-                                filename)
-                   "-C" tmpdir)))
-          (unless (= rc 0)
-            (error "Cannot untar test data %s: %d" filename rc))
-          (funcall handler tmpdir))
-      (delete-directory tmpdir t))))
-
 (ert-deftest javaimp-test--maven-visit-single ()
   :tags '(:runs-build-tool)
   (javaimp-test--with-data
diff --git a/javaimp-tests.el b/javaimp-tests.el
index b4609e2..6bc2e81 100644
--- a/javaimp-tests.el
+++ b/javaimp-tests.el
@@ -377,5 +377,24 @@ package commented.block;
         (setcdr elt (nth 1 elt))
       (javaimp-test--imenu-simplify-entries (cdr elt)))))
 
+
+;; Utility
+
+(defun javaimp-test--with-data (filename handler)
+  "Untars testdata/FILENAME into temporary directory and runs
+HANDLER, supplying temp directory name as the only arg."
+  (let ((tmpdir (file-name-as-directory (make-temp-file "javaimp" t))))
+    (unwind-protect
+        (let ((rc (call-process
+                   "tar" nil nil nil
+                   "-x"
+                   "-f" (concat javaimp--basedir
+                                (file-name-as-directory "testdata")
+                                filename)
+                   "-C" tmpdir)))
+          (unless (= rc 0)
+            (error "Cannot untar test data %s: %d" filename rc))
+          (funcall handler tmpdir))
+      (delete-directory tmpdir t))))
 
 (provide 'javaimp-tests)
diff --git a/testdata/gradle-multi.tar.gz b/testdata/gradle-multi.tar.gz
new file mode 100644
index 0000000..5f10225
Binary files /dev/null and b/testdata/gradle-multi.tar.gz differ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]