(use-modules (srfi srfi-64) (srfi srfi-1) ; For any (stash tree) (stash paths) (test-helpers)) (test-begin "tree") ;; Test directory tree operations (test-group "directory-tree" (with-temporary-directory temp-dir ;; Create test directory structure (create-test-file (string-append temp-dir "/file1.txt")) (create-test-file (string-append temp-dir "/dir1/file2.txt")) (create-test-file (string-append temp-dir "/dir1/subdir/file3.txt")) ;; Test directory scanning (let ((tree (scan-directory temp-dir))) (test-assert "Tree should contain root file" (tree-contains? tree (string-append temp-dir "/file1.txt"))) (test-assert "Tree should contain nested file" (tree-contains? tree (string-append temp-dir "/dir1/file2.txt"))) (test-assert "Tree should contain deeply nested file" (tree-contains? tree (string-append temp-dir "/dir1/subdir/file3.txt")))))) ;; Test symlink planning (test-group "symlink-planning" (with-temporary-directory temp-dir (let* ((source-dir (string-append temp-dir "/source")) (target-dir (string-append temp-dir "/target"))) ;; Create source files (create-test-file (string-append source-dir "/config.txt")) (create-test-file (string-append source-dir "/dir/nested.txt")) ;; Test operation planning (let* ((tree (scan-directory source-dir)) (ops (plan-operations tree target-dir))) ;; First operation should be to move the source directory (test-assert "Should plan to move source to target" (and (pair? ops) (eq? (caar ops) 'move) (string=? (cadar ops) source-dir) (string=? (caddar ops) target-dir))) ;; Should create target directory structure (test-assert "Should plan to create target directory" (any (lambda (op) (and (eq? (car op) 'mkdir) (string=? (cadr op) (string-append target-dir "/dir")))) ops)) ;; Should create symlinks in source pointing to target (test-assert "Should plan to create symlinks" (any (lambda (op) (and (eq? (car op) 'symlink) (string=? (cadr op) (string-append target-dir "/config.txt")) (string=? (caddr op) (string-append source-dir "/config.txt")))) ops)))))) (test-end "tree")