DocTest icon indicating copy to clipboard operation
DocTest copied to clipboard

Add option to run on code blocks with custom annotations

Open mattt opened this issue 5 years ago • 0 comments

Currently, swift doctest looks for any fenced code blocks starting with ```swift doctest (and soon with tildes, #23). By taking an opt-in approach, we can ensure that code expectations are annotated correctly. This should remain the default behavior.

It might be also useful to be able to run swift doctest on unannotated code blocks. Although they wouldn't have annotations for expected output, they could be run through the REPL to check for errors.

Implementation-wise, we should support the most likely alternatives, swift</code> and <code>. We should also probably make the delimiter fully configurable (support, for example, ```foo bar).

Maybe something like the enumeration below:

enum CodeBlockFencedInfo {
  case empty
  case swift
  case swiftDoctest
  case custom(String)
}

...which would allow for each option to be enabled / disabled with a flag:

$ swift doctest --include-empty-fenced-info --no-include-swift-doctest-fenced-info --include-custom-fenched-info "foo bar"

mattt avatar May 11 '20 13:05 mattt