Document some words, move words around to be private
parent
472fe7fa4b
commit
87e64b3a59
|
@ -1,6 +1,7 @@
|
||||||
! Copyright (C) 2011 Doug Coleman.
|
! Copyright (C) 2011 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: help.markup help.syntax kernel sequences ;
|
USING: alien.c-types help.markup help.syntax kernel quotations
|
||||||
|
sequences strings ;
|
||||||
IN: tools.coverage
|
IN: tools.coverage
|
||||||
|
|
||||||
HELP: <coverage>
|
HELP: <coverage>
|
||||||
|
@ -8,7 +9,20 @@ HELP: <coverage>
|
||||||
{ "executed?" boolean }
|
{ "executed?" boolean }
|
||||||
{ "coverage" coverage }
|
{ "coverage" coverage }
|
||||||
}
|
}
|
||||||
{ $description "Makes a coverage tuple. Users should not call this directly." } ;
|
{ $description "Makes a coverage tuple. Users should not call this directly." } ;
|
||||||
|
|
||||||
|
HELP: each-word
|
||||||
|
{ $values
|
||||||
|
{ "string" string } { "quot" quotation }
|
||||||
|
}
|
||||||
|
{ $description "Calls a quotation on every word in the vocabulary and its private vocabulary, if there is one." } ;
|
||||||
|
|
||||||
|
HELP: map-word
|
||||||
|
{ $values
|
||||||
|
{ "string" string } { "quot" quotation }
|
||||||
|
{ "seq" sequence }
|
||||||
|
}
|
||||||
|
{ $description "Calls a quotation on every word in the vocabulary and its private vocabulary, if there is one, and collects the results." } ;
|
||||||
|
|
||||||
HELP: coverage
|
HELP: coverage
|
||||||
{ $values
|
{ $values
|
||||||
|
@ -41,11 +55,20 @@ HELP: coverage.
|
||||||
}
|
}
|
||||||
{ $description "Calls the coverage word on all the words in a vocabalary or on a single word and prints out a report." } ;
|
{ $description "Calls the coverage word on all the words in a vocabalary or on a single word and prints out a report." } ;
|
||||||
|
|
||||||
|
HELP: %coverage
|
||||||
|
{ $values
|
||||||
|
{ "object" object }
|
||||||
|
{ "x" double }
|
||||||
|
}
|
||||||
|
{ $description "Returns a fraction representing the number of quotations called compared to the number of quotations that exist in a vocabulary or word." } ;
|
||||||
|
|
||||||
ARTICLE: "tools.coverage" "Coverage tool"
|
ARTICLE: "tools.coverage" "Coverage tool"
|
||||||
"The " { $vocab-link "tools.coverage" } " vocabulary is a tool for testing code coverage. The implementation uses " { $vocab-link "tools.annotations" } " to place a coverage object at the beginning of every quotation. When the quotation executes, a slot on the coverage object is set to true. By examining the coverage objects after running the code for some time, one can see which of the quotations did not execute and write more tests or refactor the code." $nl
|
"The " { $vocab-link "tools.coverage" } " vocabulary is a tool for testing code coverage. The implementation uses " { $vocab-link "tools.annotations" } " to place a coverage object at the beginning of every quotation. When the quotation executes, a slot on the coverage object is set to true. By examining the coverage objects after running the code for some time, one can see which of the quotations did not execute and write more tests or refactor the code." $nl
|
||||||
"Enabling/disabling coverage:"
|
"Enabling/disabling coverage:"
|
||||||
{ $subsections coverage-on coverage-off toggle-coverage }
|
{ $subsections coverage-on coverage-off toggle-coverage }
|
||||||
"Examining coverage data:"
|
"Examining coverage data:"
|
||||||
{ $subsections coverage coverage. } ;
|
{ $subsections coverage coverage. %coverage }
|
||||||
|
"Combinators for iterating over words in a vocabulary:"
|
||||||
|
{ $subsections each-word map-word } ;
|
||||||
|
|
||||||
ABOUT: "tools.coverage"
|
ABOUT: "tools.coverage"
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2011 Doug Coleman.
|
! Copyright (C) 2011 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs fry kernel quotations sequences strings
|
USING: accessors assocs fry io kernel math prettyprint
|
||||||
tools.annotations vocabs words prettyprint io splitting ;
|
quotations sequences sequences.deep splitting strings
|
||||||
|
tools.annotations vocabs words ;
|
||||||
IN: tools.coverage
|
IN: tools.coverage
|
||||||
|
|
||||||
TUPLE: coverage < identity-tuple executed? ;
|
TUPLE: coverage < identity-tuple executed? ;
|
||||||
|
@ -17,6 +18,8 @@ GENERIC: coverage-off ( object -- )
|
||||||
: private-vocab-name ( string -- string' )
|
: private-vocab-name ( string -- string' )
|
||||||
".private" ?tail drop ".private" append ;
|
".private" ?tail drop ".private" append ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: each-word ( string quot -- )
|
: each-word ( string quot -- )
|
||||||
over ".private" tail? [
|
over ".private" tail? [
|
||||||
[ words ] dip each
|
[ words ] dip each
|
||||||
|
@ -33,8 +36,6 @@ GENERIC: coverage-off ( object -- )
|
||||||
[ [ words ] dip map ] 2bi append
|
[ [ words ] dip map ] 2bi append
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
PRIVATE>
|
|
||||||
|
|
||||||
M: string coverage-on
|
M: string coverage-on
|
||||||
[ coverage-on ] each-word ;
|
[ coverage-on ] each-word ;
|
||||||
|
|
||||||
|
@ -85,6 +86,8 @@ M: word coverage.
|
||||||
[ [ bl bl bl bl . ] each ] bi*
|
[ [ bl bl bl bl . ] each ] bi*
|
||||||
] if-empty ;
|
] if-empty ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
GENERIC: count-callables ( object -- n )
|
GENERIC: count-callables ( object -- n )
|
||||||
|
|
||||||
M: string count-callables
|
M: string count-callables
|
||||||
|
@ -93,11 +96,13 @@ M: string count-callables
|
||||||
M: word count-callables
|
M: word count-callables
|
||||||
def>> [ callable? ] deep-filter length ;
|
def>> [ callable? ] deep-filter length ;
|
||||||
|
|
||||||
GENERIC: %coverage ( object -- x )
|
|
||||||
|
|
||||||
: calculate-%coverage ( object quot -- x )
|
: calculate-%coverage ( object quot -- x )
|
||||||
[ count-callables ] bi [ swap - ] keep /f ; inline
|
[ count-callables ] bi [ swap - ] keep /f ; inline
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
GENERIC: %coverage ( object -- x )
|
||||||
|
|
||||||
M: string %coverage
|
M: string %coverage
|
||||||
[ coverage values concat length ] calculate-%coverage ;
|
[ coverage values concat length ] calculate-%coverage ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue