emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] feature/aptel/dynamic-modules-rc3 9a1d734 25/35: modules/:


From: Noah Friedman
Subject: [Emacs-diffs] feature/aptel/dynamic-modules-rc3 9a1d734 25/35: modules/: add proper testing
Date: Mon, 8 May 2017 19:46:38 -0400 (EDT)

branch: feature/aptel/dynamic-modules-rc3
commit 9a1d734df3bc0905f3cbb883a6270b1cc4a15f1d
Author: Aurélien Aptel <address@hidden>
Commit: Aurélien Aptel <address@hidden>

    modules/: add proper testing
    
    modules/tests.py: script to run modules tests
    
    a module is a sub-dir in modules/ if a module has a test.el file, it
    is run with ert (ert-run-tests-batch-and-exit)
---
 modules/fmod/test.el          | 35 +++++++++++++++++++
 modules/opaque/test.el        | 12 +++++++
 modules/tests.py              | 64 +++++++++++++++++++++++++++++++++++
 modules/yaml/test.el          | 78 +++++++++++++++++++++++++++++++++++++++++++
 modules/yaml/tests/alias.yaml | 14 --------
 modules/yaml/tests/map.yaml   |  4 ---
 modules/yaml/tests/multi.yaml | 16 ---------
 modules/yaml/tests/nest.yaml  | 12 -------
 modules/yaml/tests/scal.yaml  |  2 --
 modules/yaml/tests/seq.yaml   |  5 ---
 modules/yaml/yaml-test.el     | 24 -------------
 11 files changed, 189 insertions(+), 77 deletions(-)

diff --git a/modules/fmod/test.el b/modules/fmod/test.el
new file mode 100644
index 0000000..fa94b04
--- /dev/null
+++ b/modules/fmod/test.el
@@ -0,0 +1,35 @@
+(require 'ert)
+
+;; basic module test should go here
+
+(ert-deftest fmod-require ()
+  "Tests bindings after require"
+  (skip-unless (not (fboundp 'fmod)))
+  (require 'fmod)
+  (should (fboundp 'fmod)))
+
+(ert-deftest fmod-doc ()
+  "Tests docstring"
+  ;; core functions docstrings should work
+  (should (string= (documentation 'base64-decode-string 'raw) "Base64-decode 
STRING and return the result."))
+
+  (require 'fmod)
+
+  ;; even after a module was added
+  (should (string= (documentation 'base64-decode-string 'raw) "Base64-decode 
STRING and return the result.
+
+(fn STRING)"))
+  ;; check new function doc
+  (should (string= (documentation 'fmod 'raw) "Returns the floating-point 
remainder of NUMER/DENOM
+
+(fn NUMER DENOM)")))
+
+(ert-deftest fmod-value ()
+  "Tests fmod calls"
+  (require 'fmod)
+  (should (= (fmod 3 2) 1))
+  ;; XXX: edge cases in man fmod(3)
+  ;; (should (= (fmod 3 2) NaN))
+  ;; (should (= (fmod inf 1) NaN))
+  ;; (should (= (fmod 3 0) NaN))
+  )
diff --git a/modules/opaque/test.el b/modules/opaque/test.el
new file mode 100644
index 0000000..b3ee760
--- /dev/null
+++ b/modules/opaque/test.el
@@ -0,0 +1,12 @@
+(require 'ert)
+(require 'opaque)
+
+(ert-deftest opaque-value ()
+  "Tests creation/access/release of opaque objects"
+  (dotimes (i 500)
+    (let ((h))
+      (setq h (opaque-make 4 5 6))
+      (assert (= (opaque-get h 'a) 4))
+      (assert (= (opaque-get h 'b) 5))
+      (assert (= (opaque-get h 'c) 6))
+      (opaque-free h))))
diff --git a/modules/tests.py b/modules/tests.py
new file mode 100755
index 0000000..f224bd0
--- /dev/null
+++ b/modules/tests.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# quick & dirty test script for dynamic modules
+
+import os, sys, glob, subprocess, argparse
+from pprint import pprint as P
+
+def fail():
+    global OK
+    OK = False
+    if not ARGS.keep_going:
+        exit(1)
+
+ROOT_DIR = 
os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
+EMACS_BIN = os.path.join(ROOT_DIR, "src", "emacs")
+MODULES_DIR = []
+MAKE_EXTRA_FLAGS = []
+OK = True
+
+for path in glob.glob(os.path.join(ROOT_DIR, "modules", "*")):
+    if os.path.isdir(path):
+        MODULES_DIR.append(path)
+
+assert len(MODULES_DIR) > 0, "No modules found"
+
+parser = argparse.ArgumentParser(description='Emacs dynamic-module tester')
+parser.add_argument('-e', '--emacs-bin', help='altenative path to the emacs 
binary')
+parser.add_argument('-B', '--rebuild', action='store_true', help='force make 
to build (-B flag)')
+parser.add_argument('-k', '--keep-going', action='store_true', help='keep 
going after a failure')
+parser.add_argument('module', nargs='*', help='explicit list of module to test 
(default: all modules)')
+ARGS = parser.parse_args()
+
+if ARGS.rebuild:
+    MAKE_EXTRA_FLAGS.append('-B')
+if ARGS.emacs_bin:
+    EMACS_BIN = ARGS.emacs_bin
+
+assert os.path.isfile(EMACS_BIN), "No emacs binary found at path %s" % 
EMACS_BIN
+
+for module_dir in MODULES_DIR:
+    base, name = os.path.split(module_dir)
+    print ""
+    print "[*] testing module %s..." % name
+    print "[*] building module..."
+
+    make_call = ["make"] + MAKE_EXTRA_FLAGS
+    ret = subprocess.call(make_call, cwd=module_dir)
+    if ret != 0:
+        print "[!] %s make failed" % name
+        fail()
+
+    test_script = os.path.join(module_dir, "test.el")
+    if os.path.isfile(test_script):
+        print "[*] running test.el..."
+        emacs_call = [EMACS_BIN, "-Q", "-l", "ert", "-L", module_dir, 
"--batch",
+                      "--load", test_script, "-f", 
"ert-run-tests-batch-and-exit"]
+        ret = subprocess.call(emacs_call, cwd=module_dir)
+        if ret != 0:
+            print "[!] %s tests failed" % name
+            fail()
+
+if OK:
+    print "\n[*] all ok"
+else:
+    print "\n[!] something failed"
diff --git a/modules/yaml/test.el b/modules/yaml/test.el
new file mode 100644
index 0000000..a9a1d3d
--- /dev/null
+++ b/modules/yaml/test.el
@@ -0,0 +1,78 @@
+(require 'ert)
+(require 'yaml)
+
+(ert-deftest yaml-scalar ()
+  "Tests scalar parsing"
+  (should (equal '(("abc"))
+                 (yaml-parse-string
+                  "---
+abc
+"))))
+
+(ert-deftest yaml-sequence ()
+  "Tests sequence parsing"
+  (should (equal '(("abc" "def" "ghi" "jkl"))
+                 (yaml-parse-string
+                  "---
+- abc
+- def
+- ghi
+- jkl
+"))))
+
+;; TODO: need deep equal for hash-tables for the rest
+
+;; TODO
+(ert-deftest yaml-map ()
+  "Tests map parsing"
+  (skip-unless nil)
+  (should (equal 'TODO
+                 (yaml-parse-string
+                  "---
+a: 1
+b: 2
+c: 3
+"))))
+
+;; TODO
+(ert-deftest yaml-multi-doc
+    "Tests documents parsing"
+  (should (equal 'TODO
+                 (yaml-parse-string
+                  "---
+a: 1
+b:
+    - 1
+    - 2
+    - 3
+---
+foo:
+    bar: 1
+    baz: 2
+    bad: 3
+zob:
+    - 42
+    - 43
+---
+abc
+"))))
+
+(ert-deftest yaml-alias ()
+  "Tests alias parsing"
+  (should (equal 'TODO
+                 (yaml-parse-string
+                  "---
+invoice: 34843
+date   : 2001-01-23
+bill-to: &id001
+    given  : Chris
+    family : Dumars
+    address:
+        lines: |
+            458 Walkman Dr.
+            Suite #292
+        city    : Royal Oak
+        state   : MI
+        postal  : 48046
+ship-to: *id001
+"))))
diff --git a/modules/yaml/tests/alias.yaml b/modules/yaml/tests/alias.yaml
deleted file mode 100644
index c3dade3..0000000
--- a/modules/yaml/tests/alias.yaml
+++ /dev/null
@@ -1,14 +0,0 @@
----
-invoice: 34843
-date   : 2001-01-23
-bill-to: &id001
-    given  : Chris
-    family : Dumars
-    address:
-        lines: |
-            458 Walkman Dr.
-            Suite #292
-        city    : Royal Oak
-        state   : MI
-        postal  : 48046
-ship-to: *id001
diff --git a/modules/yaml/tests/map.yaml b/modules/yaml/tests/map.yaml
deleted file mode 100644
index 4021d74..0000000
--- a/modules/yaml/tests/map.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
----
-a: 1
-b: 2
-c: 3
diff --git a/modules/yaml/tests/multi.yaml b/modules/yaml/tests/multi.yaml
deleted file mode 100644
index 1eb61f7..0000000
--- a/modules/yaml/tests/multi.yaml
+++ /dev/null
@@ -1,16 +0,0 @@
----
-a: 1
-b:
-    - 1
-    - 2
-    - 3
----
-foo:
-    bar: 1
-    baz: 2
-    bad: 3
-zob:
-    - 42
-    - 43
----
-abc
diff --git a/modules/yaml/tests/nest.yaml b/modules/yaml/tests/nest.yaml
deleted file mode 100644
index 8a453df..0000000
--- a/modules/yaml/tests/nest.yaml
+++ /dev/null
@@ -1,12 +0,0 @@
----
-product:
-    - sku         : BL394D
-      quantity    : 4
-      description : Basketball
-      price       : 450.00
-    - sku         : BL4438H
-      quantity    : 1
-      description : Super Hoop
-      price       : 2392.00
-tax  : 251.42
-total: 4443.52
diff --git a/modules/yaml/tests/scal.yaml b/modules/yaml/tests/scal.yaml
deleted file mode 100644
index aecd198..0000000
--- a/modules/yaml/tests/scal.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
----
-abc
diff --git a/modules/yaml/tests/seq.yaml b/modules/yaml/tests/seq.yaml
deleted file mode 100644
index 15b6a9e..0000000
--- a/modules/yaml/tests/seq.yaml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-- abc
-- def
-- ghi
-- jkl
diff --git a/modules/yaml/yaml-test.el b/modules/yaml/yaml-test.el
deleted file mode 100644
index 5f9b5c0..0000000
--- a/modules/yaml/yaml-test.el
+++ /dev/null
@@ -1,24 +0,0 @@
-
-(defun yaml-expand-file (file)
-  (if (not (string-match-p "/" file))
-      (expand-file-name
-       (concat "~/prog/c/emacs/dyn/modules/yaml/tests/" file))
-    file))
-
-(defun yaml-test-file (file)
-  (require 'yaml)
-  (require 'json)
-  (with-current-buffer (get-buffer-create "out")
-    (erase-buffer)
-    (insert (json-encode (yaml-parse-file (yaml-expand-file file))))
-    (json-pretty-print (point-min) (point-max))))
-
-(defun yaml-test-buffer (file)
-  (require 'yaml)
-  (require 'json)
-  (with-current-buffer (get-buffer-create "out")
-    (erase-buffer)
-    (insert (json-encode (with-temp-buffer
-                           (insert-file-contents (yaml-expand-file file))
-                           (yaml-parse))))
-    (json-pretty-print (point-min) (point-max))))



reply via email to

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