(use-modules (srfi srfi-64) (stash file-ops) (test-helpers)) (test-begin "file-ops") ;; Test basic file operations (test-group "basic-operations" (with-temporary-directory temp-dir ;; Test directory creation (let ((test-dir (string-append temp-dir "/new-dir"))) (test-assert "Should create directory" (begin (ensure-directory test-dir) (file-exists? test-dir))) (test-assert "Should handle existing directory" (begin (ensure-directory test-dir) (file-exists? test-dir)))) ;; Test file existence checks (let ((test-file (string-append temp-dir "/test.txt"))) (create-test-file test-file) (test-assert "Should detect existing file" (file-exists? test-file)) (test-assert "Should detect non-existing file" (not (file-exists? (string-append temp-dir "/nonexistent"))))))) ;; Test recursive operations (test-group "recursive-operations" (with-temporary-directory temp-dir ;; Create test directory structure (let ((dir1 (string-append temp-dir "/dir1")) (dir2 (string-append temp-dir "/dir2"))) (create-test-file (string-append dir1 "/file1.txt")) (create-test-file (string-append dir1 "/subdir/file2.txt")) ;; Test recursive copy (copy-recursive dir1 dir2) (test-assert "Should copy top-level file" (file-exists? (string-append dir2 "/file1.txt"))) (test-assert "Should copy nested file" (file-exists? (string-append dir2 "/subdir/file2.txt"))) ;; Test recursive delete (delete-recursive dir2) (test-assert "Should delete entire directory" (not (file-exists? dir2)))))) ;; Test file permission operations (test-group "permission-operations" (with-temporary-directory temp-dir (let ((test-file (string-append temp-dir "/permissions.txt"))) ;; Create test file (create-test-file test-file) ;; Test permission changes (make-file-executable test-file) (test-assert "Should make file executable" (file-is-executable? test-file)) (make-file-readable test-file) (test-assert "Should make file readable" (file-is-readable? test-file))))) ;; Test symlink operations (test-group "symlink-operations" (with-temporary-directory temp-dir (let ((source-file (string-append temp-dir "/source.txt")) (link-file (string-append temp-dir "/link.txt"))) ;; Create source file (create-test-file source-file "test content") ;; Test symlink creation (create-symlink source-file link-file) (test-assert "Should create symlink" (file-is-symlink? link-file)) (test-equal "Symlink should point to source" (canonicalize-path source-file) (resolve-symlink link-file)) ;; Test symlink update (let ((new-source (string-append temp-dir "/new-source.txt"))) (create-test-file new-source "new content") (update-symlink new-source link-file) (test-equal "Updated symlink should point to new source" (canonicalize-path new-source) (resolve-symlink link-file)))))) (test-end "file-ops")