stash/tests/package-test.scm

74 lines
2.5 KiB
Scheme

(use-modules (srfi srfi-64)
(stash package)
(test-helpers))
(test-begin "package")
;; Test package record creation and manipulation
(test-group "package-record"
(let ((pkg (make-package "test-pkg" "/source/path" "/target/path" '("*.bak" ".git/"))))
(test-equal "Package name"
"test-pkg"
(package-name pkg))
(test-equal "Source path"
"/source/path"
(package-source pkg))
(test-equal "Target path"
"/target/path"
(package-target pkg))
(test-equal "Ignore patterns"
'("*.bak" ".git/")
(package-ignores pkg))))
;; Test ignore pattern handling
(test-group "ignore-patterns"
(with-temporary-directory temp-dir
;; Create test files
(create-test-file (string-append temp-dir "/normal.txt"))
(create-test-file (string-append temp-dir "/ignore.bak"))
(create-test-file (string-append temp-dir "/.git/config"))
(let ((pkg (make-package "test-pkg" temp-dir "/target" '("*.bak" ".git/"))))
(test-equal "Should ignore backup files"
#f
(should-include-file? pkg (string-append temp-dir "/ignore.bak")))
(test-equal "Should ignore git directory"
#f
(should-include-file? pkg (string-append temp-dir "/.git/config")))
(test-equal "Should include normal files"
#t
(should-include-file? pkg (string-append temp-dir "/normal.txt"))))))
;; Test package file operations
(test-group "package-operations"
(with-temporary-directory temp-dir
(let* ((source-dir (string-append temp-dir "/source"))
(target-dir (string-append temp-dir "/target"))
(pkg (make-package "test-pkg" source-dir target-dir '())))
;; Create test directory structure
(create-test-file (string-append source-dir "/config.txt"))
(create-test-file (string-append source-dir "/subdir/nested.txt"))
;; Test package scanning
(test-assert "Package directory exists"
(package-exists? pkg))
(let ((files (scan-package-files pkg)))
(test-equal "Should find all package files"
2
(length files))
(test-assert "Should find root file"
(member "config.txt" (map basename files)))
(test-assert "Should find nested file"
(member "nested.txt" (map basename files)))))))
(test-end "package")