Commit bdf412cf authored by Rommel M. Martinez's avatar Rommel M. Martinez
Browse files

Added preliminary test/test-source-registry.script

parent 6d0cb832
(load "script-support")
(load "../asdf")
;; TODO:
;; - test for conditions
(defpackage :test-source-registry
(:use #:cl #:asdf))
(in-package :test-source-registry)
(defun getenv (x)
(sb-posix:getenv x))
(defun setenv (x v)
(concatenate 'string x "=" v)))
(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
(defmacro with-env-var ((key value) &rest rest)
(with-gensyms (key-save)
`(let ((,key-save ,(getenv key)))
(setenv ,key ,value)
(setenv ,key ,key-save))))))
(defun make-temporary-directory ()
(let ((str (with-output-to-string (s)
(sb-ext:run-program "mktemp" '("-d") :search t :output s))))
(concatenate 'string
(string-trim '(#\newline) str) "/")))
(defvar *base-directory* (make-temporary-directory))
(defun home-directory (&optional (base *base-directory*))
(let ((s (namestring (user-homedir-pathname))))
(merge-pathnames (subseq s 1 (length s)) base)))
(defun system-directory (&optional (base *base-directory*))
(merge-pathnames "etc/" base))
(defun tmp-directory (&optional (base *base-directory*))
(merge-pathnames "tmp/" base))
(defun home-source-registry ()
(source-registry-under (merge-pathnames ".config/" (home-directory))))
(defun system-source-registry ()
(source-registry-under (system-directory)))
(defvar *asd-temp-path-1*
(merge-temp-under (tmp-directory))
(defvar *system-source-registry-config*
(:tree ,*asd-temp-path-1*)))
(defvar *asd-temp-path-2*
(namestring (tmp-directory)))
(defvar *home-source-registry-config*
(:directory ,(namestring (tmp-directory)))))
(defun write-registry-file (file contents)
(with-open-file (out file
:direction :output
:if-exists :supersede)
(format out "~S" contents))))
(defun write-system-source-registry-config ()
(write-registry-file (system-source-registry)
(defun write-home-source-registry-config ()
(write-registry-file (home-source-registry)
(defun merge-temp-under (path)
(let ((s (string-downcase
(prin1-to-string (gentemp)))))
(concatenate 'string s "/"))
;; test environment variable
;; test files
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment