(.require [library [lux (.except) [abstract [monad (.only do)] [\\specification ["$[0]" equivalence]]] [control ["[0]" try]] [data ["[0]" product] ["[0]" text (.only) [encoding ["[0]" utf8]]] [format ["[0]" xml (.only XML)]] [collection ["[0]" set (.only Set)]]] [math ["[0]" random (.only Random)] [number ["n" nat]]] [world ["[0]" file]] [test ["_" property (.only Test)]]]] [// ["$[0]" profile] [// [lux [data ["$[0]" binary]]]]] [\\program ["[0]" / (.only) ["/[1]" // ["[1]" profile] ["[1][0]" hash (.use "[1]#[0]" equivalence)] ["[1][0]" pom] [dependency ["[1][0]" status]] [repository ["[1][0]" origin]]]]]) (def .public random (Random [//.Profile /.Package]) (do [! random.monad] [content_size (of ! each (n.% 100) random.nat) content ($binary.random content_size) [profile pom] (random.one (function (_ profile) (try.maybe (do try.monad [pom (//pom.write profile)] (in [profile pom])))) $profile.random)] (in [profile (/.local pom content)]))) (def .public test Test (<| (_.covering /._) (_.for [/.Package]) (do [! random.monad] [[profile package] ..random] (all _.and (_.for [/.equivalence] ($equivalence.spec /.equivalence (of ! each product.right ..random))) (_.coverage [/.local?] (/.local? (has /.#origin {//origin.#Local "~/yolo"} package))) (_.coverage [/.remote?] (/.remote? (has /.#origin {//origin.#Remote "https://example.com"} package))) (_.coverage [/.local] (let [expected_pom (|> package (the /.#pom) product.left) expected_library (|> package (the /.#library) product.left) local (/.local expected_pom expected_library) [actual_pom binary_pom pom_status] (the /.#pom local) [actual_library library_status] (the /.#library local)] (and (when (the /.#origin local) {//origin.#Local ""} true _ false) (let [expected_sha1 (//hash.sha1 expected_library) expected_md5 (//hash.md5 expected_library)] (and (same? expected_library actual_library) (when library_status {//status.#Verified actual_sha1 expected_md5} (and (//hash#= expected_sha1 actual_sha1) (//hash#= expected_md5 expected_md5)) _ false))) (let [expected_sha1 (//hash.sha1 binary_pom) expected_md5 (//hash.md5 binary_pom)] (and (same? expected_pom actual_pom) (|> (do try.monad [xml_pom (of utf8.codec decoded binary_pom) decoded_pom (of xml.codec decoded xml_pom)] (in (of xml.equivalence = actual_pom decoded_pom))) (try.else false)) (when pom_status {//status.#Verified actual_sha1 expected_md5} (and (//hash#= expected_sha1 actual_sha1) (//hash#= expected_md5 expected_md5)) _ false)))))) (_.coverage [/.dependencies] (let [expected (the //.#dependencies profile)] (when (/.dependencies package) {try.#Success actual} (of set.equivalence = expected actual) {try.#Failure error} false))) (_.coverage [/.repositories] (let [expected (the //.#repositories profile)] (when (/.repositories package) {try.#Success actual} (of set.equivalence = expected actual) {try.#Failure error} false))) ))))