(.require [library [lux (.except Type) [abstract ["[0]" monad (.only do)]] [control ["[0]" try] [concurrency ["[0]" async (.only Async)]] [parser ["[0]" environment]]] [data [binary (.only Binary)] ["[0]" text] [format [xml (.only XML)]] [collection ["[0]" set] ["[0]" dictionary] ["[0]" list]]] [math ["[0]" random (.only Random) (.use "[1]#[0]" monad)] [number ["n" nat]]] [world ["[0]" file] ["[0]" program]] ["_" test (.only Test) ["[0]" unit]]]] [// ["@[0]" profile] ["@[0]" artifact] [// [lux [data ["_[0]" binary]]]]] [\\program ["[0]" / (.only) ["/[1]" // ["[1]" profile (.only Profile)] ["[1][0]" package (.only Package)] ["[1][0]" pom] ["[1][0]" dependency (.only Dependency) ["[1]/[0]" resolution (.only Resolution)]] ["[1][0]" artifact (.only Artifact) ["[1]/[0]" type (.only Type)]] ["[1][0]" repository ["[1]/[0]" origin]]]]]) (def type (Random Type) (all random.either (random#in //artifact/type.lux_library) (random#in //artifact/type.jvm_library))) (def profile (Random [Artifact Profile XML]) (random.one (function (_ profile) (try.maybe (do try.monad [pom (//pom.write profile) identity (try.of_maybe (the //.#identity profile))] (in [identity profile pom])))) @profile.random)) (def content (Random Binary) (do [! random.monad] [content_size (at ! each (n.% 100) random.nat)] (_binary.random content_size))) (def package (Random [Dependency Package]) (do [! random.monad] [[identity profile pom] ..profile type ..type content ..content] (in [[//dependency.#artifact identity //dependency.#type type] (has //package.#origin {//repository/origin.#Remote ""} (//package.local pom content))]))) (def resolution (Random Resolution) (do [! random.monad] [[main_dependency main_package] ..package dependencies (|> (//package.dependencies main_package) (at try.monad each set.list) (try.else (list)) (monad.each ! (function (_ dependency) (do ! [pom (random.one (function (_ [identity profile pom]) (|> profile (has //.#dependencies (set.empty //dependency.hash)) (has //.#identity {.#Some (the //dependency.#artifact dependency)}) //pom.write try.maybe)) ..profile) content ..content] (in [dependency (has //package.#origin {//repository/origin.#Remote ""} (//package.local pom content))])))))] (in (dictionary.of_list //dependency.hash (list.partial [main_dependency main_package] dependencies))))) (def singular Test (do [! random.monad] [[dependency expected_package] ..package home (random.alphabetic 5) working_directory (random.alphabetic 5) .let [fs (is (file.System Async) (file.mock (at file.default separator))) program (program.async (program.mock environment.empty home working_directory))]] (in (do async.monad [wrote! (/.write_one program fs dependency expected_package) read! (/.read_one program fs dependency)] (unit.coverage [/.write_one /.read_one] (<| (try.else false) (do try.monad [_ wrote! actual_package read!] (in (at //package.equivalence = (has //package.#origin {//repository/origin.#Local ""} expected_package) actual_package))))))))) (def plural Test (do [! random.monad] [expected ..resolution home (random.alphabetic 5) working_directory (random.alphabetic 5) .let [fs (is (file.System Async) (file.mock (at file.default separator))) program (program.async (program.mock environment.empty home working_directory))]] (in (do async.monad [wrote! (/.write_all program fs expected) read! (/.read_all program fs (dictionary.keys expected) //dependency/resolution.empty)] (unit.coverage [/.write_all /.read_all] (<| (try.else false) (do try.monad [_ wrote! actual read!] (in (at //dependency/resolution.equivalence = (at dictionary.functor each (has //package.#origin {//repository/origin.#Local ""}) expected) actual))))))))) (def .public test Test (<| (_.covering /._) (all _.and ..singular ..plural )))