(use test svn-client posix srfi-1 utils) (when (file-exists? "testrepo") ; This probably doesn't work under Windows ;) (system "rm -rf testrepo")) (when (file-exists? "testcheckout") (system "rm -rf testcheckout")) (when (file-exists? "testcheckout2") (system "rm -rf testcheckout2")) (define repo-dir (make-pathname (current-directory) "testrepo")) (define repo-uri (conc "file://" repo-dir)) (define checkout-dir (make-pathname (current-directory) "testcheckout")) (define checkout-dir2 (make-pathname (current-directory) "testcheckout2")) (define user "testuser") (define user2 "different-testuser") (define pass "testpass") (define (svn-file f) (make-pathname checkout-dir f)) (define (write-svn-file file data) (with-output-to-file (svn-file file) (lambda () (print data)))) (test-begin "subversion client library") (test-assert "Create a testrepo" (svn-repos-create "testrepo")) (test "Make a checkout of revision 0" 0 (svn-checkout repo-uri checkout-dir svn-opt-revision-head #t user pass)) (test "Make another checkout of revision 0" 0 (svn-checkout repo-uri checkout-dir2 svn-opt-revision-head #t user pass)) (test-group "initial state" (let ((info (svn-client-info checkout-dir svn-opt-revision-head svn-opt-revision-head #t user pass))) (test "At revision 0" 0 (svn-info-rev (cadar info))) (test "Last changed revision of root also 0" 0 (svn-info-last-changed-rev (cadar info))) (test "Root URI equals repo URI" repo-uri (svn-info-repos-root-url (cadar info))) (test "Directory item representing root's URI also equals repo URI" repo-uri (svn-info-url (cadar info))))) (test-group "adding files" (write-svn-file "foo" "Just added") (test-assert "File can be added" (svn-add (svn-file "foo") #f user pass)) (test-assert "File can be committed" (svn-commit (svn-file "foo") #t user pass "initial add")) (let ((info (svn-client-info (svn-file "foo") svn-opt-revision-head svn-opt-revision-head #f user pass))) (test "After adding a file, it is listed by info" "foo" (caar info)) (test "File is at revision 1" 1 (svn-info-rev (cadar info))) (test "File last changed at revision 1" 1 (svn-info-last-changed-rev (cadar info))) (create-directory (svn-file "testdir")) (test-assert "Directory can be added" (svn-add (svn-file "testdir") #f user pass)) (write-svn-file "testdir/bar" "Also just added") (test-assert "Another file can be added" (svn-add (svn-file "testdir/bar") #f user pass)) (test-assert "Directory can be committed recursively" (svn-commit (svn-file "testdir") #t user2 pass "another initial add"))) (let ((info (svn-client-info (svn-file "testdir/bar") svn-opt-revision-head svn-opt-revision-head #f user pass))) (test "After adding another file, it is listed by info" "bar" (caar info)) (test "File is at revision 2" 2 (svn-info-rev (cadar info))) (test "File last changed at revision 2" 2 (svn-info-last-changed-rev (cadar info)))) (let ((info (svn-client-info (svn-file "foo") svn-opt-revision-head svn-opt-revision-head #f user pass))) (test "After adding another file, first file is also at revision 2" 2 (svn-info-rev (cadar info))) (test "First file's last changed revision is still 1" 1 (svn-info-last-changed-rev (cadar info))))) (test-group "listing" (test "Files and directories are all listed" '("" "foo" "testdir" "testdir/bar") (map svn-file-path (svn-client-list checkout-dir svn-opt-revision-head #t user pass))) (test "Files are marked as such" '("foo" "testdir/bar") (filter-map (lambda (f) (and (eq? (svn-file-kind f) 'file) (svn-file-path f))) (svn-client-list checkout-dir svn-opt-revision-head #t user pass))) (test "secondary checkout still empty" '("") (map svn-file-path (svn-client-list checkout-dir2 svn-opt-revision-unspecified #t user pass))) (svn-update checkout-dir2 svn-opt-revision-head #t user pass) (test "Everything listed after update of secondary checkout" '("" "foo" "testdir" "testdir/bar") (map svn-file-path (svn-client-list checkout-dir2 svn-opt-revision-unspecified #t user pass)))) (test-group "modification" (write-svn-file "testdir/bar" "Changed") (let* ((diff-file (svn-diff (svn-file "testdir/bar") #t user pass)) (diff (with-input-from-file diff-file read-lines))) (delete-file* diff-file) (test "Unified context diff file contents" '("@@ -1 +1 @@" "-Also just added" "+Changed") (cddddr diff))) (test-assert "Reverting file" (svn-client-revert (list (svn-file "testdir/bar")) #f user pass)) (let* ((diff-file (svn-diff (svn-file "testdir/bar") #t user pass)) (diff (with-input-from-file diff-file read-lines))) (delete-file* diff-file) (test "Empty after revert" '() `,diff)) (write-svn-file "testdir/bar" "Changed") (test-assert "Changed file can be committed" (svn-commit (svn-file "testdir/bar") #t user pass "Modified for the first time"))) (test-group "basic log" (let ((log-info (svn-client-log checkout-dir (make-svn-opt-revision-number 0) svn-opt-revision-head 0 #t #f user pass))) (test "Last revision first" 3 (svn-log-revision (car log-info))) (test "Log-message of r3 ok" "Modified for the first time" (svn-log-message (car log-info))) (test "Author of r3 is normal user" user (svn-log-author (car log-info))) (test "Files of r3 ok" '("/testdir/bar") (map svn-log-change-path (svn-log-changes (car log-info)))) (test "Actions of r3 OK" '(modified) (map svn-log-change-action (svn-log-changes (car log-info)))) (test "Log-message of r2 ok" "another initial add" (svn-log-message (cadr log-info))) (test "Files of r2 ok" '("/testdir" "/testdir/bar") (sort (map svn-log-change-path (svn-log-changes (cadr log-info))) string<=?)) (test "Author of r2 is alternative user" user (svn-log-author (car log-info))) (test "Actions of r2 OK" '(added added) (map svn-log-change-action (svn-log-changes (cadr log-info)))) (test "Log-message of r1 ok" "initial add" (svn-log-message (caddr log-info))) (test "Files of r1 ok" '("/foo") (map svn-log-change-path (svn-log-changes (caddr log-info)))) (test "Actions of r1 OK" '(added) (map svn-log-change-action (svn-log-changes (caddr log-info)))) (test "No log-message for r0" #f (svn-log-message (cadddr log-info))) (test "No changes for r0" '() (svn-log-changes (cadddr log-info))))) (test-group "catenation" (let* ((f (svn-client-cat (svn-file "testdir/bar") svn-opt-revision-unspecified user pass)) (contents (read-all f))) (delete-file* f) (test "Working dir" "Changed\n" contents)) (let* ((f (svn-client-cat (svn-file "testdir/bar") (make-svn-opt-revision-number 2) user pass)) (contents (read-all f))) (delete-file* f) (test "Historical revision" "Also just added\n" contents))) (test-group "properties" (svn-propset-local "testing" "123" (svn-file "testdir/bar") #f #f) (test "After setting property, it can be retrieved" `((,(svn-file "testdir/bar") "123")) (svn-propget "testing" (svn-file "testdir/bar") svn-opt-revision-unspecified #t user pass))) (test-end) (when (file-exists? "testrepo") (system "rm -rf testrepo")) (when (file-exists? "testcheckout") (system "rm -rf testcheckout")) (when (file-exists? "testcheckout2") (system "rm -rf testcheckout2")) (unless (zero? (test-failure-count)) (exit 1))