diff options
author | Mathieu Lirzin <mthl@gnu.org> | 2018-03-25 03:01:45 +0200 |
---|---|---|
committer | Mathieu Lirzin <mthl@gnu.org> | 2018-03-25 03:01:45 +0200 |
commit | 4d636af87621211354cc716e92cd9fe4e1200500 (patch) | |
tree | e3f134c5b05ec68eba1914fbd0546c848db98822 | |
parent | 5af999fb20c5bae645a5f2005f0411a1130b7455 (diff) | |
download | mcron-4d636af87621211354cc716e92cd9fe4e1200500.tar.gz mcron-4d636af87621211354cc716e92cd9fe4e1200500.tar.bz2 mcron-4d636af87621211354cc716e92cd9fe4e1200500.zip |
utils: Check 'mcron-error'
* tests/utils.scm ("mcron-error: exit code", "mcron-error: output")
("mcron-error: output no-exit", "mcron-error: only stderr"): New tests.
-rw-r--r-- | tests/utils.scm | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/utils.scm b/tests/utils.scm index 5ec5d11..fbd32e1 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -16,11 +16,53 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>. -(use-modules (srfi srfi-64) +(use-modules (ice-9 match) + (ice-9 rdelim) + (srfi srfi-64) (mcron utils)) (test-begin "utils") +;;; Check 'mcron-error' error code return value. +(test-equal "mcron-error: exit code" + 42 + (match (primitive-fork) + (0 ;child + (mcron-error 42 "exit with 42")) + ((= waitpid (pid . exit-code)) ;parent + (status:exit-val exit-code)))) + +;;; Check 'mcron-error' output with basic error code. +(test-equal "mcron-error: output" + "mcron: token" + (call-with-output-string + (λ (port) + (match (pipe) + ((in . out) + (match (primitive-fork) + (0 ;child + (close in) + (with-error-to-port out + (λ () (mcron-error 37 "token")))) + ((= waitpid (pid . exit-code)) ;parent + (close out) + (display (read-line in) port)))))))) + +;;; Check mcron-error output when error code is 0. +(test-equal "mcron-error: output no-exit" + "mcron: foobar\n" + (call-with-output-string + (λ (port) + (with-error-to-port port + (λ () + (mcron-error 0 "foo" "bar")))))) + +;;; Check that mcron-error doesn't print anything on the standard output. +(test-equal "mcron-error: only stderr" + "" + (with-output-to-string + (λ () (mcron-error 0 "foo" "bar")))) + (define entry ;; Random user entry. (getpw)) |