aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/spec
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/spec/lux/world/shell.lux97
1 files changed, 97 insertions, 0 deletions
diff --git a/stdlib/source/spec/lux/world/shell.lux b/stdlib/source/spec/lux/world/shell.lux
new file mode 100644
index 000000000..286cc7ce2
--- /dev/null
+++ b/stdlib/source/spec/lux/world/shell.lux
@@ -0,0 +1,97 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["." try]
+ [security
+ ["!" capability]]
+ [concurrency
+ ["." promise (#+ Promise)]]]
+ [data
+ ["." product]
+ ["." text ("#@." equivalence)
+ ["%" format (#+ format)]]
+ [number
+ ["n" nat]
+ ["i" int]]
+ [format
+ ["." context]]]
+ [math
+ ["." random]]]
+ {1
+ ["." /]})
+
+(template [<name> <command> <type> <prep>]
+ [(def: <name>
+ (-> <type> [/.Environment /.Command (List /.Argument)])
+ (|>> <prep> list [context.empty <command>]))]
+
+ [echo! "echo" Text (|>)]
+ [sleep! "sleep" Nat %.nat]
+ )
+
+(def: (read-test expected process)
+ (-> Text (/.Process Promise) _.Assertion)
+ (do promise.monad
+ [?read (!.use (:: process read) [])
+ ?await (!.use (:: process await) [])]
+ ($_ _.and'
+ (_.claim [/.Can-Read]
+ (case ?read
+ (#try.Success actual)
+ (text@= expected actual)
+
+ (#try.Failure error)
+ false))
+ (_.claim [/.Can-Wait /.Exit /.normal]
+ (case ?await
+ (#try.Success exit)
+ (i.= /.normal exit)
+
+ (#try.Failure error)
+ false))
+ )))
+
+(def: (destroy-test process)
+ (-> (/.Process Promise) _.Assertion)
+ (do promise.monad
+ [?destroy (!.use (:: process destroy) [])
+ ?await (!.use (:: process await) [])]
+ (_.claim [/.Can-Destroy]
+ (and (case ?destroy
+ (#try.Success _)
+ true
+
+ (#try.Failure error)
+ false)
+ (case ?await
+ (#try.Success _)
+ false
+
+ (#try.Failure error)
+ true)))))
+
+(with-expansions [<shell-coverage> (as-is [/.Can-Execute
+ /.Environment /.Command /.Argument])]
+ (def: #export (spec shell)
+ (-> (/.Shell Promise) Test)
+ (<| (_.with-cover [/.Shell /.Process])
+ (do {! random.monad}
+ [message (random.ascii/alpha 10)
+ seconds (:: ! map (|>> (n.% 5) (n.+ 5)) random.nat)]
+ (wrap (do promise.monad
+ [?echo (!.use (:: shell execute) (..echo! message))
+ ?sleep (!.use (:: shell execute) (..sleep! seconds))]
+ (case [?echo ?sleep]
+ [(#try.Success echo) (#try.Success sleep)]
+ ($_ _.and'
+ (_.claim <shell-coverage>
+ true)
+ (..read-test message echo)
+ (..destroy-test sleep))
+
+ _
+ (_.claim <shell-coverage>
+ false))))))))