(.module: [lux #* ["_" test (#+ Test)] [abstract ["." monad (#+ do)]] [control ["." try (#+ Try) ("#\." functor)] ["." exception] [concurrency ["." promise (#+ Promise)]] [security ["!" capability]] [parser ["." environment (#+ Environment)]]] [data ["." maybe] ["." binary] ["." text ("#\." equivalence) ["%" format (#+ format)] ["." encoding]] [format ["." xml]] [collection ["." set (#+ Set)]]] [math ["." random (#+ Random)]] [world ["." file (#+ Path File)] ["." program (#+ Program)] [net ["." uri]]]] [// ["@." version] [// ["@." profile] ["@." artifact]]] {#program ["." / ["/#" // #_ ["#." clean] ["/#" // #_ ["#" profile] ["#." action] ["#." pom] ["#." local] ["#." artifact ["#/." extension]] ["#." repository #_ ["#/." local]]]]]}) (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! program fs sample) (-> (Program Promise) (file.System Promise) ///.Profile (Promise (Try Text))) (do promise.monad [home (\ program home [])] (do ///action.monad [#let [console (@version.echo "")] _ (..make_sources! fs (get@ #///.sources sample)) _ (/.do! console fs (///repository/local.repository program fs) sample)] (!.use (\ console read_line) [])))) (def: #export test Test (<| (_.covering /._) (do {! random.monad} [identity @artifact.random sample (\ ! map (set@ #///.identity (#.Some identity)) @profile.random) home (random.ascii/alpha 5) working_directory (random.ascii/alpha 5)] ($_ _.and (wrap (do {! promise.monad} [#let [fs (file.mock (\ file.default separator)) program (program.async (program.mock environment.empty home working_directory))] verdict (do ///action.monad [logging (..execute! program fs sample) #let [/ uri.separator artifact_path (format (///local.uri identity) / (///artifact.identity identity)) library_path (format artifact_path ///artifact/extension.lux_library) pom_path (format artifact_path ///artifact/extension.pom)] library_exists! (\ promise.monad map exception.return (file.file_exists? promise.monad fs library_path)) pom_exists! (\ promise.monad map exception.return (file.file_exists? promise.monad fs pom_path))] (wrap (and (text\= //clean.success logging) library_exists! pom_exists!)))] (_.cover' [/.do!] (try.default false verdict)))) (wrap (do {! promise.monad} [#let [fs (file.mock (\ file.default separator)) program (program.async (program.mock environment.empty home working_directory))] logging (..execute! program fs (set@ #///.identity #.None sample))] (_.cover' [/.failure] (|> logging (try\map (text\= /.failure)) (try.default false))))) ))))