Commit b5949c53 authored by Elias Pipping's avatar Elias Pipping

Test public rather than internal interfaces

The run-program interface generally behaves as if

  :if-input-does-not-exist :error
  :if-output-exists :supersede

were specified and deviations from this set will generally not be
handled correctly, e.g. on CLISP or whenever %system is used. Hence
we remove the corresponding tests for now
parent b051b7dd
......@@ -187,15 +187,15 @@
;; Wrapper that keeps us from special-casing CLISP since it
;; always requires :error-output :interactive to be set.
(defun %run-program (command &rest named-pairs
&key (error-output nil error-output-set)
&allow-other-keys)
(defun %launch-program (command &rest named-pairs
&key (error-output nil error-output-set)
&allow-other-keys)
(declare (ignore error-output #-clisp error-output-set))
(let ((args (append (list command)
named-pairs
#+clisp (unless error-output-set
(list :error-output :interactive)))))
(apply #'uiop/run-program::%run-program args)))
(apply #'launch-program args)))
;; Skips the test if terminate-process cannot be called
(defun my-terminate-process (&rest rest)
......@@ -205,29 +205,29 @@
;;; The actual tests
(new-test-suite "%run-program")
(new-test-suite "run-program/launch-program")
(define-test
":input/:output/:error-output nil (default)"
(%run-program (format nil "./exiter.sh 0 ~a" output-string)
:wait nil :input nil :output nil))
(run-program (format nil "./exiter.sh 0 ~a" output-string)
:input nil :output nil))
(define-test
":error-output :interactive"
(%run-program (format nil "./exiter.sh 0 ~a" output-string)
:wait t :error-output :interactive))
(run-program (format nil "./exiter.sh 0 ~a" output-string)
:error-output :interactive))
(define-test
":error-output :output"
(%run-program (format nil "./exiter.sh 0 ~a" output-string)
:wait t :error-output :output))
(run-program (format nil "./exiter.sh 0 ~a" output-string)
:error-output :output))
(define-test
":output <file> (file e.)"
(progn
(create-file-from-string *output-file* "")
(%run-program (format nil "./exiter.sh 0 ~a" output-string)
:wait t :output *output-file*)
(run-program (format nil "./exiter.sh 0 ~a" output-string)
:output *output-file*)
(check-output (format nil "~a~%" output-string))))
(define-test
......@@ -235,42 +235,35 @@
(progn
(create-file-from-string *output-file* "")
(create-file-from-string *error-output-file* "")
(%run-program (format nil "./exiter.sh 0 ~a ~a"
output-string error-string)
:wait t :output *output-file*
:error-output *error-output-file*)
(run-program (format nil "./exiter.sh 0 ~a ~a"
output-string error-string)
:output *output-file*
:error-output *error-output-file*)
(check-output (format nil "~a~%" output-string))
(check-error-output (format nil "~a~%" error-string))))
(define-test
":input <file> (file m.)"
(progn
(delete-file-if-exists *input-file*)
(%run-program "cat" :wait t :input *input-file*
:if-input-does-not-exist :create)))
(define-test
":input <file> (file e.)"
(progn
(let ((in-string (format nil "A line.~%And another.~%")))
(create-file-from-string *input-file* in-string))
(%run-program "cat" :wait t :input *input-file*
:if-input-does-not-exist :create)))
(run-program "cat" :input *input-file*
:if-input-does-not-exist :create)))
(define-test
":input <file> (as pathname; file e.)"
(progn
(let ((in-string (format nil "A line.~%And another.~%")))
(create-file-from-string *input-file* in-string))
(%run-program "cat" :wait t :input (truename *input-file*)
:if-input-does-not-exist :create)))
(run-program "cat" :input (truename *input-file*)
:if-input-does-not-exist :create)))
(define-test
":input <file> :output <file> (files e.)"
(let ((in-string (format nil "A line.~%And another.~%")))
(create-file-from-string *input-file* in-string)
(create-file-from-string *output-file* "")
(%run-program "cat" :wait t :input *input-file* :output *output-file*)
(run-program "cat" :input *input-file* :output *output-file*)
(check-output in-string)))
(define-test
......@@ -278,25 +271,10 @@
(let ((in-string (format nil "A line.~%And another.~%")))
(create-file-from-string *input-file* in-string)
(delete-file-if-exists *output-file*)
(%run-program "cat" :wait t :input *input-file*
:output *output-file*)
(run-program "cat" :input *input-file*
:output *output-file*)
(check-output in-string)))
(define-test
":input <file> :output <file> (files e.), :i-o-e :append"
(progn
(let ((in-string1 (format nil "A line.~%"))
(in-string2 (format nil "And another.~%")))
(delete-file-if-exists *output-file*)
(create-file-from-string *input-file* in-string1)
(%run-program "cat" :wait t :input *input-file*
:output *output-file*)
(create-file-from-string *input-file* in-string2)
(%run-program "cat" :wait t :input *input-file*
:output *output-file*
:if-output-exists :append)
(check-output (concatenate 'string in-string1 in-string2)))))
(define-test
":output <fstream> :error-output <fstream>"
(progn
......@@ -306,9 +284,9 @@
(with-open-file (error-output *error-output-file* :direction :output
:if-exists :supersede
#+clozure :sharing #+clozure :lock)
(%run-program (format nil "./exiter.sh 0 ~a ~a"
output-string error-string)
:wait t :output output :error-output error-output)))
(run-program (format nil "./exiter.sh 0 ~a ~a"
output-string error-string)
:output output :error-output error-output)))
(check-output (format nil "~a~%" output-string))
(check-error-output (format nil "~a~%" error-string))))
......@@ -317,7 +295,7 @@
(let ((in-string (format nil "A line.~%And another.~%")))
(create-file-from-string *input-file* in-string)
(with-output-to-string (out-stream)
(%run-program "cat" :wait t :input *input-file* :output out-stream)
(run-program "cat" :input *input-file* :output out-stream)
(check-strings in-string (get-output-stream-string out-stream)))))
(define-test
......@@ -325,31 +303,17 @@
(let ((in-string (format nil "A line.~%And another.~%")))
(with-output-to-string (out-stream nil)
(with-input-from-string (in-stream in-string)
(%run-program "cat" :wait t :input in-stream :output out-stream))
(run-program "cat" :input in-stream :output out-stream))
(check-strings in-string (get-output-stream-string out-stream)))))
(define-test
":input <file> :output :stream"
(let ((in-string (format nil "A line.~%And another.~%")))
(with-open-file (input *input-file* :direction :output
:if-exists :supersede)
(format input in-string))
(let* ((process (%run-program "cat" :wait t :input *input-file*
:output :stream))
(output (process-info-output process))
(out-string (make-string (length in-string))))
(read-sequence out-string output)
(check-strings in-string out-string)
(close-streams process))))
(define-test
":input <file> :output :stream :wait nil"
(let ((in-string (format nil "A line.~%And another.~%")))
(with-open-file (input *input-file* :direction :output
:if-exists :supersede)
(format input in-string))
(let* ((process (%run-program "cat" :wait nil :input *input-file*
:output :stream))
(let* ((process (launch-program "cat" :input *input-file*
:output :stream))
(output (process-info-output process))
(out-string (make-string (length in-string))))
(wait-process process)
......@@ -370,9 +334,9 @@
:if-does-not-exist :error)
(let* ((*dynamic-input* input)
(input-synonym (make-synonym-stream '*dynamic-input*)))
(%run-program "cat" :wait t
:input input-synonym
:output *output-file*))
(run-program "cat"
:input input-synonym
:output *output-file*))
(check-output in-string))))
(define-test
......@@ -383,9 +347,9 @@
(with-input-from-string (input in-string)
(let* ((*dynamic-input* input)
(input-synonym (make-synonym-stream '*dynamic-input*)))
(%run-program "cat" :wait t
:input input-synonym
:output *output-file*)))
(run-program "cat"
:input input-synonym
:output *output-file*)))
(check-output in-string))))
(define-test
......@@ -402,15 +366,15 @@
(create-file-from-string temporary-file in-string)
(delete-file-if-exists *output-file*)
(%run-program (format nil "cat ~a" relative-filename)
:wait t :output *output-file* :directory temporary-directory)
(run-program (format nil "cat ~a" relative-filename)
:output *output-file* :directory temporary-directory)
(check-output in-string)))
(new-test-suite "process-info-pid")
(define-test
"basic functionality"
(let* ((process-info (%run-program "./sleeper.sh 12 1" :wait nil))
(let* ((process-info (launch-program "./sleeper.sh 12 1"))
(pid (process-info-pid process-info)))
(handle-result "obtainable and plausible?"
(and (numberp pid) (plusp pid)))
......@@ -419,36 +383,32 @@
(new-test-suite "wait-process")
(define-test
"exit code after exit: synchronous (repeated)"
(let ((process-info (%run-program "./exiter.sh 12" :wait t)))
(handle-result "exit code matches?"
(equal 12 (wait-process process-info)))
(handle-result "exit code matches? (no. 2)"
(equal 12 (wait-process process-info)))))
"exit code after exit: synchronous"
(let ((exit-code (nth-value 2 (run-program "./exiter.sh 12"
:ignore-error-status t))))
(handle-result "exit code matches?" (equal 12 exit-code))))
(define-test
"exit code after exit: asynchronous (repeated)"
(let ((process-info (%run-program "./sleeper.sh 12 1" :wait nil)))
(let ((process-info (launch-program "./sleeper.sh 12 1")))
(handle-result "exit code matches?"
(equal 12 (wait-process process-info)))
(handle-result "exit code matches? (no. 2)"
(equal 12 (wait-process process-info)))))
(define-test
"exit code after signal: synchronous (repeated)"
"exit code after signal: synchronous"
#+(and lispworks (not lispworks7+))
(skip-test "Known to fail")
(let ((process-info (%run-program "./killer.sh" :wait t)))
(handle-result "exit code matches?"
(equal (+ 128 15) (wait-process process-info)))
(handle-result "exit code matches? (no. 2)"
(equal (+ 128 15) (wait-process process-info)))))
(let ((exit-code (nth-value 2 (run-program "./killer.sh"
:ignore-error-status t))))
(handle-result "exit code matches?" (equal (+ 128 15) exit-code))))
(define-test
"exit code after signal: asynchronous (repeated)"
#+(and lispworks (not lispworks7+))
(skip-test "Known to fail")
(let ((process-info (%run-program "./killer.sh" :wait nil)))
(let ((process-info (launch-program "./killer.sh")))
(handle-result "exit code matches?"
(equal (+ 128 15) (wait-process process-info)))
(handle-result "exit code matches? (no. 2)"
......@@ -458,7 +418,7 @@
(define-test
"not alive (we slept)"
(let ((process-info (%run-program "./sleeper.sh 12 1" :wait nil)))
(let ((process-info (launch-program "./sleeper.sh 12 1")))
(handle-result "alive?"
(process-alive-p process-info))
(sleep 2)
......@@ -469,7 +429,7 @@
(define-test
"not alive (we waited)"
(let ((process-info (%run-program "./sleeper.sh 12 1" :wait nil)))
(let ((process-info (launch-program "./sleeper.sh 12 1")))
(handle-result "alive?"
(process-alive-p process-info))
(wait-process process-info)
......@@ -479,7 +439,7 @@
(define-test
"not alive (we terminated it)"
(let ((process-info (%run-program "./sleeper.sh 12 2" :wait nil)))
(let ((process-info (launch-program "./sleeper.sh 12 2")))
(handle-result "alive?"
(process-alive-p process-info))
(my-terminate-process process-info :urgent t)
......@@ -490,7 +450,7 @@
(define-test
"not alive (we terminated it repeatedly)"
(let ((process-info (%run-program "./sleeper.sh 12 3" :wait nil)))
(let ((process-info (launch-program "./sleeper.sh 12 3")))
(handle-result "alive?"
(process-alive-p process-info))
(my-terminate-process process-info :urgent t)
......@@ -503,8 +463,8 @@
(define-test
"multiple processes: proper exit sequence"
(let ((process-info1 (%run-program "./sleeper.sh 12 1" :wait nil))
(process-info2 (%run-program "./sleeper.sh 12 2" :wait nil)))
(let ((process-info1 (launch-program "./sleeper.sh 12 1"))
(process-info2 (launch-program "./sleeper.sh 12 2")))
(handle-result "#1 alive?"
(process-alive-p process-info1))
(handle-result "#2 alive?"
......@@ -527,7 +487,7 @@
(define-test
":exited (we slept; repeated query)"
(let* ((process-info (%run-program "./sleeper.sh 12 1" :wait nil))
(let* ((process-info (launch-program "./sleeper.sh 12 1"))
(status (uiop/run-program::%process-status process-info)))
(handle-result "running?" (equal :running status))
(sleep 2)
......@@ -545,7 +505,7 @@
":exited/:signaled (it killed itself; repeated query)"
#+(and lispworks (not lispworks7+))
(skip-test "Known to fail")
(let* ((process-info (%run-program "./killer.sh" :wait nil)))
(let* ((process-info (launch-program "./killer.sh")))
(sleep 1)
(multiple-value-bind (status code)
(uiop/run-program::%process-status process-info)
......@@ -565,7 +525,7 @@
(define-test
":exited (it exited >128; repeated query)"
(let* ((process-info (%run-program "./killercontainer.sh" :wait nil)))
(let* ((process-info (launch-program "./killercontainer.sh")))
(sleep 1)
(multiple-value-bind (status code)
(uiop/run-program::%process-status process-info)
......@@ -581,7 +541,7 @@
":signaled (we terminated it; repeated query)"
#+(and lispworks (not lispworks7+))
(skip-test "Known to fail")
(let* ((process-info (%run-program "./sleeper.sh 12 2" :wait nil))
(let* ((process-info (launch-program "./sleeper.sh 12 2"))
(status (uiop/run-program::%process-status process-info)))
(handle-result "running?" (equal :running status))
(my-terminate-process process-info :urgent t)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment