[jenkinscat-docs] master: Added new test: test_exec.clj. (e7b7bb5)
immanetize at fedoraproject.org
immanetize at fedoraproject.org
Fri Feb 6 07:39:57 UTC 2015
Repository : http://git.fedorahosted.org/cgit/jenkinscat-docs.git
On branch : master
>---------------------------------------------------------------
commit e7b7bb53dd1256a26b6e926563d5f692f3f5a21b
Author: Pavel Tisnovsky <ptisnovs at redhat.com>
Date: Tue Dec 2 11:30:32 2014 +0100
Added new test: test_exec.clj.
>---------------------------------------------------------------
ChangeLog | 5 +
test/jenkinscat/test_exec.clj | 277 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 282 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c064481..cf58944 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-02 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * test/jenkinscat/test_exec.clj:
+ Added new test: test_exec.clj.
+
2014-12-01 Pavel Tisnovsky <ptisnovs at redhat.com>
* test/jenkinscat/test_config.clj:
diff --git a/test/jenkinscat/test_exec.clj b/test/jenkinscat/test_exec.clj
new file mode 100644
index 0000000..5ddcfcb
--- /dev/null
+++ b/test/jenkinscat/test_exec.clj
@@ -0,0 +1,277 @@
+;;;
+;;; Jenkinscat HTTP server that handles all requests send from clients/browsers.
+;;;
+;;; Copyright (c) 2014 Pavel Tisnovsky, Red Hat
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions are met:
+;;; * Redistributions of source code must retain the above copyright
+;;; notice, this list of conditions and the following disclaimer.
+;;; * Redistributions in binary form must reproduce the above copyright
+;;; notice, this list of conditions and the following disclaimer in the
+;;; documentation and/or other materials provided with the distribution.
+;;; * Neither the name of the Red Hat nor the
+;;; names of its contributors may be used to endorse or promote products
+;;; derived from this software without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;; DISCLAIMED. IN NO EVENT SHALL Pavel Tisnovsky BE LIABLE FOR ANY
+;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+;;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+;;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;;
+
+; Tests for defs and functions defined in the following namespace: jenkinscat.exec
+(ns jenkinscat.test-exec
+ (:require [clojure.test :refer :all]
+ [clojure.java.io]
+ [jenkinscat.exec :refer :all]))
+
+
+
+;
+; Common functions used by tests
+;
+
+(defn callable?
+ "Test if given function-name is bound to the real function."
+ [function-name]
+ (clojure.test/function? function-name))
+
+(defn call-exec-without-args
+ "Check if exec could/could not be called without arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec without args
+ (exec)
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-empty-arg
+ "Check if exec could/could not be called with one empty argument."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with empty
+ (exec "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-two-empty-args
+ "Check if exec could/could not be called with two empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with two empty arguments
+ (exec "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-three-empty-args
+ "Check if exec could/could not be called with three empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with three empty arguments
+ (exec "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-four-empty-args
+ "Check if exec could/could not be called with four empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with four empty arguments
+ (exec "" "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-five-empty-args
+ "Check if exec could/could not be called with five empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with five empty arguments
+ (exec "" "" "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-six-empty-args
+ "Check if exec could/could not be called with six empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with six empty arguments
+ (exec "" "" "" "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-improper-command
+ "Check if exec could/could not be called with improper command."
+ [command]
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with improper command
+ (exec command)
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-improper-command-arg
+ "Check if exec could/could not be called with improper command."
+ [command arg]
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with improper command
+ (exec command arg)
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+
+
+;
+; Tests for the (defn exec)
+;
+
+(deftest test-exec-existence
+ "Check that the jenkinscat.exec/exec definition exists."
+ (testing "if the jenkinscat.exec/exec def exists"
+ (is (callable? 'jenkinscat.exec/exec))))
+
+(deftest test-exec-function-without-args
+ "Test exec function behaviour"
+ (testing "exec function behaviour"
+ ; call (exec)
+ (is (call-exec-without-args))))
+
+(deftest test-exec-function-with-empty-arg
+ "Test exec function behaviour"
+ (testing "exec function behaviour"
+ ; call (exec "")
+ (is (call-exec-with-empty-arg))))
+
+(deftest test-exec-function-with-empty-args
+ "Test exec function behaviour"
+ (testing "exec function behaviour"
+ ; call (exec "" "")
+ (is (call-exec-with-two-empty-args))
+ ; call (exec "" "" "")
+ (is (call-exec-with-three-empty-args))
+ ; call (exec "" "" "" "")
+ (is (call-exec-with-four-empty-args))
+ ; call (exec "" "" "" "" "")
+ (is (call-exec-with-five-empty-args))
+ ; call (exec "" "" "" "" "" "")
+ (is (call-exec-with-six-empty-args))))
+
+(deftest test-exec-function-with-real-commands
+ "Test exec function with real commands (ls etc.)"
+ (testing "exec function behaviour"
+ ; call (exec "date")
+ (is (exec "date"))
+ ; call (exec "ls")
+ (is (exec "ls"))
+ ; call (exec "ls -1")
+ (is (exec "ls -1"))
+ ; call (exec "ls -1 -c")
+ (is (exec "ls -1 -c"))
+ ; call (exec "ls -a -1 -c")
+ (is (exec "ls -a -1 -c"))
+ ; call (exec "ls -a -1 -c -C")
+ (is (exec "ls -a -1 -c -C"))
+ ; call (exec "ls -a -1 -c -C -d")
+ (is (exec "ls -a -1 -c -C -d"))
+ ; call (exec "ls -a -1 -c -C -d -g")
+ (is (exec "ls -a -1 -c -C -d -g"))
+ ; call (exec "ls" "-1")
+ (is (exec "ls" "-1"))
+ ; call (exec "ls" "-1" "-c")
+ (is (exec "ls" "-1" "-c"))
+ ; call (exec "ls" "-a" "-1" "-c")
+ (is (exec "ls" "-a" "-1 -c"))
+ ; call (exec "ls" "-a" "-1" "-c" "-C")
+ (is (exec "ls" "-a" "-1" "-c" "-C"))
+ ; call (exec "ls" "-a" "-1" "-c" "-C" "-d")
+ (is (exec "ls" "-a" "-1" "-c" "-C" "-d"))
+ ; call (exec "ls" "-a" "-1" "-c" "-C" "-d" "-g")
+ (is (exec "ls" "-a" "-1" "-c" "-C" "-d" "-g"))))
+
+(deftest test-exec-function-with-improper-commands
+ "Test exec function with improper commands."
+ (testing "exec function behaviour"
+ ; call (exec "-")
+ (is (call-exec-with-improper-command "-"))
+ ; call (exec "---")
+ (is (call-exec-with-improper-command "---"))
+ ; call (exec "/")
+ (is (call-exec-with-improper-command "/"))
+ ; call (exec "//")
+ (is (call-exec-with-improper-command "//"))
+ ; call (exec "?")
+ (is (call-exec-with-improper-command "?"))
+ ; call (exec "??")
+ (is (call-exec-with-improper-command "??"))
+ ; call (exec "xyzzy")
+ (is (call-exec-with-improper-command "xyzzy"))))
+
+(deftest test-exec-function-with-improper-commands-arg
+ "Test exec function with improper commands."
+ (testing "exec function behaviour"
+ ; call (exec "-" "x")
+ (is (call-exec-with-improper-command-arg "-" "x"))
+ ; call (exec "---" "x")
+ (is (call-exec-with-improper-command-arg "---" "x"))
+ ; call (exec "/" "x")
+ (is (call-exec-with-improper-command-arg "/" "x"))
+ ; call (exec "//" "x")
+ (is (call-exec-with-improper-command-arg "//" "x"))
+ ; call (exec "?" "x")
+ (is (call-exec-with-improper-command-arg "?" "x"))
+ ; call (exec "??" "x")
+ (is (call-exec-with-improper-command-arg "??" "x"))
+ ; call (exec "xyzzy" "x")
+ (is (call-exec-with-improper-command-arg "xyzzy" "x"))))
+
More information about the docs-commits
mailing list