aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/test
diff options
context:
space:
mode:
authorEduardo Julian2022-07-28 18:58:20 -0400
committerEduardo Julian2022-07-28 18:58:20 -0400
commit2d125c27e1ceb0adc14fd82f6984b70a12eda650 (patch)
treefcefab088b8346ba009ec4069d3b392486bcad98 /stdlib/source/library/lux/test
parenta4b64bf1cdf47160b6b615d2c6493039abfd7a94 (diff)
Extracted test-coverage machinery into its own module.
Diffstat (limited to 'stdlib/source/library/lux/test')
-rw-r--r--stdlib/source/library/lux/test/coverage.lux46
-rw-r--r--stdlib/source/library/lux/test/unit.lux49
2 files changed, 53 insertions, 42 deletions
diff --git a/stdlib/source/library/lux/test/coverage.lux b/stdlib/source/library/lux/test/coverage.lux
new file mode 100644
index 000000000..efc2644a6
--- /dev/null
+++ b/stdlib/source/library/lux/test/coverage.lux
@@ -0,0 +1,46 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [data
+ ["[0]" text (.only)
+ ["%" \\format]]
+ [collection
+ ["[0]" list (.use "[1]#[0]" mix functor)]
+ ["[0]" set (.only Set)]]]
+ ["[0]" meta (.only)
+ ["[0]" symbol]
+ ["[0]" code (.only)
+ ["<[1]>" \\parser]]
+ [macro
+ [syntax (.only syntax)]]]]])
+
+(type .public Coverage
+ (Set Symbol))
+
+(def .public of
+ (let [symbol (is (-> Symbol Code)
+ (function (_ symbol)
+ (` (is Symbol
+ [(, (code.text (symbol.module symbol)))
+ (, (code.text (symbol.short symbol)))]))))]
+ (syntax (_ [name <code>.symbol])
+ (do meta.monad
+ [_ (meta.export name)]
+ (in (list (symbol name)))))))
+
+(def separator
+ Text
+ (text.of_char 31))
+
+(def .public encoded
+ (-> (List Text) Text)
+ (text.interposed ..separator))
+
+(def .public (decoded module encoding)
+ (-> Text Text Coverage)
+ (|> encoding
+ (text.all_split_by ..separator)
+ (list#each (|>> [module]))
+ (set.of_list symbol.hash)))
diff --git a/stdlib/source/library/lux/test/unit.lux b/stdlib/source/library/lux/test/unit.lux
index 0077c18a9..0e90bb46c 100644
--- a/stdlib/source/library/lux/test/unit.lux
+++ b/stdlib/source/library/lux/test/unit.lux
@@ -22,10 +22,9 @@
["[0]" code (.only)
["<[1]>" \\parser]]
[macro
- [syntax (.only syntax)]]]]])
-
-(type .public Coverage
- (Set Symbol))
+ [syntax (.only syntax)]]]]]
+ [//
+ ["[0]" coverage (.only Coverage)]])
(type .public Tally
(Record
@@ -121,40 +120,6 @@
(%.Format Symbol)
(|>> %.symbol (format ..clean_up_marker)))
-(def .public reference
- (let [symbol (is (-> Symbol Code)
- (function (_ symbol)
- (` (is Symbol
- [(, (code.text (symbol.module symbol)))
- (, (code.text (symbol.short symbol)))]))))]
- (syntax (_ [name <code>.symbol])
- (do meta.monad
- [_ (meta.export name)]
- (in (list (symbol name)))))))
-
-(def coverage_separator
- Text
- (text.of_char 31))
-
-(def encoded_coverage
- (-> (List Text) Text)
- (list#mix (function (_ short aggregate)
- (case aggregate
- "" short
- _ (format aggregate ..coverage_separator short)))
- ""))
-
-(def (coverage_definitions module encoding)
- (-> Text Text Coverage)
- (loop (again [remaining encoding
- output (set.of_list symbol.hash (list))])
- (case (text.split_by ..coverage_separator remaining)
- {.#Some [head tail]}
- (again tail (set.has [module head] output))
-
- {.#None}
- (set.has [module remaining] output))))
-
(def .public (with_coverage coverage condition)
(-> (List Symbol) Bit Test)
(let [message (|> coverage
@@ -170,7 +135,7 @@
(syntax (_ [coverage (<code>.tuple (<>.many <code>.any))
condition <code>.any])
(let [coverage (list#each (function (_ definition)
- (` (..reference (, definition))))
+ (` (coverage.of (, definition))))
coverage)]
(in (list (` (..with_coverage (is (.List .Symbol)
(.list (,* coverage)))
@@ -191,7 +156,7 @@
(syntax (_ [coverage (<code>.tuple (<>.many <code>.any))
test <code>.any])
(let [coverage (list#each (function (_ definition)
- (` (..reference (, definition))))
+ (` (coverage.of (, definition))))
coverage)]
(in (list (` (..for' (is (.List .Symbol)
(.list (,* coverage)))
@@ -199,7 +164,7 @@
(def .public (covering' module coverage test)
(-> Text Text Test Test)
- (let [coverage (..coverage_definitions module coverage)]
+ (let [coverage (coverage.decoded module coverage)]
(|> (..context' module test)
(async#each (function (_ [tally documentation])
[(revised #expected (set.union coverage) tally)
@@ -219,5 +184,5 @@
{.#Item short aggregate}
aggregate))
{.#End})
- ..encoded_coverage)]]
+ coverage.encoded)]]
(in (list (` (..covering' (, (code.text module)) (, (code.text coverage)) (, test))))))))