(.module: [lux #* ["_" test (#+ Test)] [abstract ["." monad (#+ do)]] [control ["." try (#+ Try) ("#\." functor)] ["." exception] [concurrency ["." promise (#+ Promise)]] [security ["!" capability]]] [data ["." maybe] ["." binary] ["." text ("#\." equivalence) ["%" format (#+ format)] ["." encoding]] ["." format #_ ["#" binary] ["." tar] ["." xml]] [collection ["." set (#+ Set)] ["." dictionary (#+ Dictionary)]]] [math ["." random (#+ Random)]] [world ["." file (#+ Path File)]]] [program [compositor ["." export]]] [/// ["@." profile] ["@." repository]] {#program ["." / ["//#" /// #_ ["#" profile] ["#." action] ["#." pom] ["#." local] ["#." hash] ["#." repository (#+ Identity Repository)] ["#." artifact (#+ Artifact) ["#/." extension]]]]}) (def: (make-sources! fs sources) (-> (file.System Promise) (Set Path) (Promise (Try Any))) (loop [sources (set.to-list sources)] (case sources #.Nil (|> [] (:: try.monad wrap) (:: promise.monad wrap)) (#.Cons head tail) (do (try.with promise.monad) [_ (: (Promise (Try Path)) (file.make-directories promise.monad fs head)) _ (: (Promise (Try (File Promise))) (file.get-file promise.monad fs (format head (:: fs separator) head ".lux")))] (recur tail))))) (def: (execute! repository fs identity artifact profile) (-> (Repository Promise) (file.System Promise) Identity Artifact ///.Profile (Promise (Try Any))) (do ///action.monad [_ (..make-sources! fs (get@ #///.sources profile)) _ (: (Promise (Try Path)) (file.make-directories promise.monad fs (///local.repository fs)))] (/.do! repository fs identity artifact profile))) (def: #export test Test (<| (_.covering /._) (do {! random.monad} [[artifact expected-pom profile] (random.one (function (_ profile) (do maybe.monad [artifact (get@ #///.identity profile) expected-pom (try.to-maybe (///pom.write profile))] (wrap [artifact expected-pom profile]))) @profile.random) identity @repository.identity #let [repository (///repository.mock (@repository.simulation identity) @repository.empty) fs (file.mock (:: file.default separator))]] (wrap (do {! promise.monad} [verdict (do {! ///action.monad} [_ (..execute! repository fs identity artifact profile) expected-library (|> profile (get@ #///.sources) set.to-list (export.library fs) (:: ! map (format.run tar.writer))) actual-pom (:: repository download artifact ///artifact/extension.pom) actual-library (:: repository download artifact ///artifact/extension.lux-library) actual-sha-1 (:: repository download artifact ///artifact/extension.sha-1) actual-md5 (:: repository download artifact ///artifact/extension.md5) #let [deployed-library! (:: binary.equivalence = expected-library actual-library) deployed-pom! (:: binary.equivalence = (|> expected-pom (:: xml.codec encode) encoding.to-utf8) actual-pom) deployed-sha-1! (:: binary.equivalence = (///hash.data (///hash.sha-1 expected-library)) actual-sha-1) deployed-md5! (:: binary.equivalence = (///hash.data (///hash.md5 expected-library)) actual-md5)]] (wrap (and deployed-library! deployed-pom! deployed-sha-1! deployed-md5!)))] (_.cover' [/.do!] (try.default false verdict)))))))