scheme-libraries/retropikzel/dot-locking/test.scm

74 lines
2.3 KiB
Scheme

(import (scheme base)
(scheme write)
(scheme read)
(scheme char)
(scheme file)
(scheme process-context)
(retropikzel tap)
(retropikzel dot-locking)
(srfi 64))
(test-runner-current (tap-runner))
(test-begin "dot-locking")
(test-begin "obtain-dot-lock")
(let* ((testfile "/tmp/scshtestfile.txt")
(lockfile (string-append testfile ".lock")))
(when (file-exists? testfile) (delete-file testfile))
(when (file-exists? lockfile) (delete-file lockfile))
(with-output-to-file testfile (lambda () (display 1)))
(obtain-dot-lock testfile)
(test-assert (file-exists? lockfile)))
(test-end "obtain-dot-lock")
(test-begin "break-dot-lock")
(let* ((testfile "/tmp/scshtestfile.txt")
(lockfile (string-append testfile ".lock")))
(when (file-exists? testfile) (delete-file testfile))
(when (file-exists? lockfile) (delete-file lockfile))
(with-output-to-file testfile (lambda () (display 1)))
(obtain-dot-lock testfile)
(break-dot-lock testfile)
(test-assert (not (file-exists? lockfile))))
(test-end "break-dot-lock")
(test-begin "release-dot-lock")
(let* ((testfile "/tmp/scshtestfile.txt")
(lockfile (string-append testfile ".lock")))
(when (file-exists? testfile) (delete-file testfile))
(when (file-exists? lockfile) (delete-file lockfile))
(with-output-to-file testfile (lambda () (display 1)))
(obtain-dot-lock testfile)
(test-assert (release-dot-lock testfile)))
(test-end "release-dot-lock")
(test-begin "with-dot-lock*")
(let* ((testfile "/tmp/scshtestfile.txt")
(lockfile (string-append testfile ".lock")))
(when (file-exists? testfile) (delete-file testfile))
(when (file-exists? lockfile) (delete-file lockfile))
(with-output-to-file testfile (lambda () (display 1)))
(with-dot-lock*
testfile
(lambda ()
(test-assert (file-exists? lockfile)))))
(test-end "with-dot-lock*")
(test-begin "with-dot-lock")
(let* ((testfile "/tmp/scshtestfile.txt")
(lockfile (string-append testfile ".lock")))
(when (file-exists? testfile) (delete-file testfile))
(when (file-exists? lockfile) (delete-file lockfile))
(with-output-to-file testfile (lambda () (display 1)))
(with-dot-lock testfile (test-assert (file-exists? lockfile))))
(test-end "with-dot-lock")
(test-end "dot-locking")