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

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

[elpa] externals/pq bc939f732e 30/63: Setup emacs ert tests


From: ELPA Syncer
Subject: [elpa] externals/pq bc939f732e 30/63: Setup emacs ert tests
Date: Mon, 14 Feb 2022 23:24:23 -0500 (EST)

branch: externals/pq
commit bc939f732ecdff70c6b44c0d24a2bf3d10cec88d
Author: Mario Rodas <marsam@users.noreply.github.com>
Commit: Mario Rodas <marsam@users.noreply.github.com>

    Setup emacs ert tests
---
 .travis.yml | 13 ++++++++++---
 Makefile    |  5 +++++
 test.el     | 44 +++++++++++++++++++++-----------------------
 3 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 5e9e8e8415..bbd20362c7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,8 +11,11 @@ addons:
     packages:
       - libpq-dev
 env:
-  - EMACS_VERSION=25.1
-  - EMACS_VERSION=snapshot
+  global:
+    - EMACSCONFFLAGS="--with-x-toolkit=no --without-x --without-all 
--with-xml2 --with-modules"
+  matrix:
+    - EMACS_VERSION=25.1
+    - EMACS_VERSION=snapshot
 matrix:
   allow_failures:
     - env: EMACS_VERSION=snapshot
@@ -22,5 +25,9 @@ before_install:
   - make -f emacs-travis.mk install_emacs
   - make -f emacs-travis.mk install_cask
   - curl -OL 
https://github.com/emacs-mirror/emacs/raw/emacs-25.1/src/emacs-module.h
-script:
+install:
   - make
+before_script:
+  - psql -c 'create database travis_ci_test;' -U postgres
+script:
+  - make PG_CONNINFO="user=postgres dbname=travis_ci_test" check
diff --git a/Makefile b/Makefile
index fbea451bb5..474ed3a4c1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,5 @@
+EMACS = emacs
+
 PG_CONFIG = pg_config
 PGINCLUDEDIR := $(shell $(PG_CONFIG) --pkgincludedir)
 
@@ -21,3 +23,6 @@ all: $(TARGET)
 
 clean:
        $(RM) $(TARGET)
+
+check:
+       $(EMACS) --batch -Q -l ert -l test.el -f ert-run-tests-batch-and-exit
diff --git a/test.el b/test.el
index 91327e7c74..3eafc21736 100644
--- a/test.el
+++ b/test.el
@@ -2,30 +2,28 @@
              (file-name-directory (or #$ (expand-file-name 
(buffer-file-name)))))
 
 (require 'pq)
+(require 'ert)
 
-(setq con (pq:connectdb "port=5432 dbname=smith"))
-(pq:query con "select version()")
-;; ("PostgreSQL 9.4.8 on i686-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 
4.9.2, 32-bit")
-(pq:query con "select 1 union select 2")
-;; (1 2)
-(pq:query con "select 1,2")
-;; ([1 2])
-(pq:query con "select 1,2 union select 3,4")
-;; ([1 2] [3 4])
-(pq:query con "select 'Hello, ' || $1::text" (user-login-name))
-;; ("Hello, andreas")
-(pq:escapeLiteral con "mo'oo\"oo")
-;; "'mo''oo\"oo'"
-(pq:escapeIdentifier con "moo'oo\"oo")
-;; "\"moo'oo\"\"oo\""
-(pq:query con "select true, false, NULL, version()")
+(defvar *conninfo* (or (getenv "PG_CONNINFO") "port=5432 dbname=smith"))
 
-;; provoke a warning
-(pq:query con "drop table if exists nonexisting_table")
+(ert-deftest pq-query-test ()
+  (let ((conn (pq:connectdb *conninfo*)))
+    (should (equal (pq:query conn "select 1 union select 2") '(1 2)))
+    (should (equal (pq:query conn "select 1,2") '([1 2])))
+    (should (equal (pq:query conn "select 1,2 union select 3,4") '([1 2] [3 
4])))
+    (should (equal (pq:query conn "select 'Hello, ' || $1::text" 
(user-login-name))
+                   (list (concat "Hello, " (user-login-name)))))
 
-;; Multiple statements
-(pq:query con "select 1; select 2; select 3;")
+    (should (equal (pq:query conn "select true, false, NULL, 42")
+                   '([t nil nil 42])))
 
-(setq con (pq:connectdb))
-(setq con nil)
-(garbage-collect)
+    ;; provoke a warning
+    ;; (pq:query con "drop table if exists nonexisting_table")
+
+    ;; Multiple statements
+    (should (equal (pq:query conn "select 1; select 2; select 3;") '(3)))))
+
+(ert-deftest pq-escape-test ()
+  (let ((conn (pq:connectdb *conninfo*)))
+    (should (equal (pq:escapeLiteral conn "mo'oo\"oo") "'mo''oo\"oo'"))
+    (should (equal (pq:escapeIdentifier conn "moo'oo\"oo") 
"\"moo'oo\"\"oo\""))))



reply via email to

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