aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library
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
parenta4b64bf1cdf47160b6b615d2c6493039abfd7a94 (diff)
Extracted test-coverage machinery into its own module.
Diffstat (limited to 'stdlib/source/library')
-rw-r--r--stdlib/source/library/lux/test.lux20
-rw-r--r--stdlib/source/library/lux/test/coverage.lux46
-rw-r--r--stdlib/source/library/lux/test/unit.lux49
3 files changed, 63 insertions, 52 deletions
diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux
index eafb394a5..411c6c1c7 100644
--- a/stdlib/source/library/lux/test.lux
+++ b/stdlib/source/library/lux/test.lux
@@ -3,9 +3,8 @@
[lux (.except and for)
["[0]" debug]
[abstract
- ["[0]" monad (.only do)]]
+ [monad (.only do)]]
[control
- ["<>" parser]
["[0]" pipe]
["[0]" maybe]
["[0]" try]
@@ -20,7 +19,7 @@
["%" \\format (.only format)]]
[collection
["[0]" list (.use "[1]#[0]" functor mix)]
- ["[0]" set (.only Set)]
+ ["[0]" set]
["[0]" dictionary
["[1]" ordered (.only Dictionary)]]]]
[math
@@ -28,21 +27,22 @@
[number (.only hex)
["n" nat]
["f" frac]]]
- ["[0]" meta (.only)
+ [meta
["@" target]
["[0]" symbol]
- ["[0]" code (.only)
+ ["[0]" code
["<[1]>" \\parser]]
- [macro (.only with_symbols)
+ [macro
[syntax (.only syntax)]]]
[world
["[0]" environment]
["[0]" console]
[time
- ["[0]" instant]
- ["[0]" duration (.only Duration)]]]]]
+ [duration (.only Duration)]
+ ["[0]" instant]]]]]
[/
- ["//" unit]])
+ ["//" unit]
+ ["[0]" coverage (.only Coverage)]])
(type .public Test
(Random //.Test))
@@ -134,7 +134,7 @@
(the //.#expected tally))
unexpected (set.difference (the //.#expected tally)
(the //.#actual tally))
- report (is (-> //.Coverage Text)
+ report (is (-> Coverage Text)
(|>> set.list
(list.sorted (at symbol.order <))
(exception.listing %.symbol)))
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))))))))