2011-08-26 15:32:41 -04:00
|
|
|
! Copyright (C) 2011 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2015-06-08 15:02:25 -04:00
|
|
|
USING: accessors arrays assocs classes combinators.short-circuit
|
|
|
|
continuations fry io kernel math namespaces prettyprint
|
|
|
|
quotations sequences sequences.deep splitting strings
|
2015-06-09 11:43:51 -04:00
|
|
|
tools.annotations tools.test.private vocabs words words.symbol ;
|
2011-08-26 15:32:41 -04:00
|
|
|
IN: tools.coverage
|
|
|
|
|
2013-03-24 13:06:50 -04:00
|
|
|
TUPLE: coverage-state < identity-tuple executed? ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2013-03-24 13:06:50 -04:00
|
|
|
C: <coverage-state> coverage-state
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2011-11-29 00:26:06 -05:00
|
|
|
SYMBOL: covered
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
: flag-covered ( coverage -- )
|
2011-11-29 00:26:06 -05:00
|
|
|
covered get-global [ t >>executed? ] when drop ;
|
2011-09-25 22:12:05 -04:00
|
|
|
|
2011-11-29 00:26:06 -05:00
|
|
|
: coverage-on ( -- ) t covered set-global ;
|
2011-09-25 22:12:05 -04:00
|
|
|
|
2011-11-29 00:26:06 -05:00
|
|
|
: coverage-off ( -- ) f covered set-global ;
|
2011-09-25 22:12:05 -04:00
|
|
|
|
|
|
|
GENERIC: add-coverage ( object -- )
|
|
|
|
|
|
|
|
GENERIC: remove-coverage ( object -- )
|
|
|
|
|
|
|
|
GENERIC: reset-coverage ( object -- )
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2011-08-27 02:04:02 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: private-vocab-name ( string -- string' )
|
|
|
|
".private" ?tail drop ".private" append ;
|
|
|
|
|
2011-08-27 17:12:41 -04:00
|
|
|
: coverage-words ( string -- words )
|
2015-06-09 11:43:51 -04:00
|
|
|
vocab-words [
|
|
|
|
{
|
|
|
|
[ primitive? not ]
|
|
|
|
[ symbol? not ]
|
|
|
|
[ predicate? not ]
|
|
|
|
} 1&&
|
|
|
|
] filter ;
|
2011-08-27 17:12:41 -04:00
|
|
|
|
2011-08-27 13:52:01 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
2011-08-27 13:34:05 -04:00
|
|
|
: each-word ( string quot -- )
|
2011-08-27 01:56:02 -04:00
|
|
|
over ".private" tail? [
|
2011-08-27 17:12:41 -04:00
|
|
|
[ coverage-words ] dip each
|
2011-08-27 01:56:02 -04:00
|
|
|
] [
|
2011-08-27 17:12:41 -04:00
|
|
|
[ [ private-vocab-name coverage-words ] dip each ]
|
|
|
|
[ [ coverage-words ] dip each ] 2bi
|
2011-08-27 01:56:02 -04:00
|
|
|
] if ; inline
|
|
|
|
|
2011-08-27 16:54:25 -04:00
|
|
|
: map-words ( string quot -- sequence )
|
2011-08-27 13:34:05 -04:00
|
|
|
over ".private" tail? [
|
2011-08-27 17:12:41 -04:00
|
|
|
[ coverage-words ] dip map
|
2011-08-27 13:34:05 -04:00
|
|
|
] [
|
2011-08-27 17:12:41 -04:00
|
|
|
[ [ private-vocab-name coverage-words ] dip map ]
|
|
|
|
[ [ coverage-words ] dip map ] 2bi append
|
2011-08-27 13:34:05 -04:00
|
|
|
] if ; inline
|
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
M: string add-coverage
|
|
|
|
[ add-coverage ] each-word ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
M: string remove-coverage
|
|
|
|
[ remove-coverage ] each-word ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2015-06-29 19:43:15 -04:00
|
|
|
M: word add-coverage
|
2011-08-26 15:32:41 -04:00
|
|
|
H{ } clone [ "coverage" set-word-prop ] 2keep
|
|
|
|
'[
|
2013-03-24 13:06:50 -04:00
|
|
|
\ coverage-state new [ _ set-at ] 2keep
|
2011-09-25 22:12:05 -04:00
|
|
|
'[ _ flag-covered ] prepend
|
2011-08-26 15:32:41 -04:00
|
|
|
] deep-annotate ;
|
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
M: word remove-coverage
|
2011-08-26 15:32:41 -04:00
|
|
|
[ reset ] [ f "coverage" set-word-prop ] bi ;
|
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
M: string reset-coverage
|
|
|
|
[ reset-coverage ] each-word ;
|
2011-08-27 01:56:02 -04:00
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
M: word reset-coverage
|
2013-03-24 13:06:50 -04:00
|
|
|
[ dup coverage-state? [ f >>executed? ] when drop ] each-word ;
|
2011-08-27 01:56:02 -04:00
|
|
|
|
2011-08-26 15:32:41 -04:00
|
|
|
GENERIC: coverage ( object -- seq )
|
|
|
|
|
|
|
|
M: string coverage
|
2011-08-27 16:54:25 -04:00
|
|
|
[ dup coverage 2array ] map-words ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
|
|
|
M: word coverage ( word -- seq )
|
2015-06-09 11:43:51 -04:00
|
|
|
"coverage" word-prop
|
2015-05-12 22:08:42 -04:00
|
|
|
[ drop executed?>> ] assoc-reject values ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
|
|
|
GENERIC: coverage. ( object -- )
|
|
|
|
|
|
|
|
M: string coverage.
|
2011-08-27 17:12:41 -04:00
|
|
|
[ coverage. ] each-word ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
2015-06-09 11:43:51 -04:00
|
|
|
: pair-coverage. ( word seq -- )
|
|
|
|
[ drop ] [
|
2011-08-26 15:32:41 -04:00
|
|
|
[ name>> ":" append print ]
|
2011-08-27 16:54:25 -04:00
|
|
|
[ [ " " write . ] each ] bi*
|
2015-06-09 11:43:51 -04:00
|
|
|
] if-empty ;
|
2011-09-25 22:12:05 -04:00
|
|
|
|
|
|
|
M: word coverage.
|
|
|
|
dup coverage pair-coverage. ;
|
|
|
|
|
|
|
|
M: sequence coverage.
|
|
|
|
[ first2 pair-coverage. ] each ;
|
2011-08-27 13:34:05 -04:00
|
|
|
|
2011-08-27 13:52:01 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
2011-08-27 13:34:05 -04:00
|
|
|
GENERIC: count-callables ( object -- n )
|
|
|
|
|
|
|
|
M: string count-callables
|
2011-08-27 16:54:25 -04:00
|
|
|
[ count-callables ] map-words sum ;
|
2011-08-27 13:34:05 -04:00
|
|
|
|
|
|
|
M: word count-callables
|
2015-06-09 11:43:51 -04:00
|
|
|
def>> 0 [ callable? [ 1 + ] when ] deep-reduce ;
|
2011-08-27 13:34:05 -04:00
|
|
|
|
2011-08-27 13:52:01 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
2011-09-25 22:12:05 -04:00
|
|
|
: test-coverage ( vocab -- coverage )
|
|
|
|
[
|
|
|
|
add-coverage
|
|
|
|
] [
|
|
|
|
dup '[
|
|
|
|
[
|
|
|
|
_
|
2014-06-03 21:11:26 -04:00
|
|
|
[ coverage-on test-vocab coverage-off ]
|
2011-09-25 22:12:05 -04:00
|
|
|
[ coverage ] bi
|
|
|
|
] [ _ remove-coverage ] [ ] cleanup
|
|
|
|
] call
|
|
|
|
] bi ;
|
|
|
|
|
2014-06-09 10:04:15 -04:00
|
|
|
: coverage-vocab? ( vocab -- ? )
|
|
|
|
{ [ ".private" tail? ] [ ".tests" tail? ] } 1|| not ;
|
|
|
|
|
2014-06-03 21:11:26 -04:00
|
|
|
: test-coverage-recursively ( prefix -- assoc )
|
2015-06-09 11:03:35 -04:00
|
|
|
loaded-child-vocab-names [ coverage-vocab? ] filter
|
2014-06-09 10:04:15 -04:00
|
|
|
[ dup test-coverage ] { } map>assoc ;
|
2014-03-11 22:20:34 -04:00
|
|
|
|
2011-08-27 16:54:25 -04:00
|
|
|
: %coverage ( string -- x )
|
2011-11-01 19:46:02 -04:00
|
|
|
[ test-coverage values concat length ]
|
2011-08-27 16:54:25 -04:00
|
|
|
[ count-callables ] bi [ swap - ] keep /f ; inline
|