Skip to content

Commit

Permalink
use require rather than eval
Browse files Browse the repository at this point in the history
Doctests no longer share scope with `fetch` when run headless.
  • Loading branch information
davidchambers committed Dec 9, 2012
1 parent 68631bc commit 92dc561
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
8 changes: 6 additions & 2 deletions lib/doctest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/doctest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ fetch = (path) ->
console.log "running doctests in #{name}..."
source = rewrite text, type
source = CoffeeScript.compile source if type is 'coffee'
eval source
name += "-#{+new Date}"
file = "#{__dirname}/#{name}.js"
fs.writeFileSync file, source, 'utf8'
require "./#{name}"
fs.unlink file
doctest.run()


Expand Down
9 changes: 4 additions & 5 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ do ->
# . 7,8,9]
# [1,2,3,4,5,6,7,8,9]
14: 'multiline assignment'
# > @text = "input " +
# > @string = "input " +
# . "may span many " +
# . "lines"
# > text
# > string
# "input may span many lines"

15: 'spaces following "//" and ">" are optional'
Expand All @@ -88,9 +88,8 @@ do ->
# 25

20: 'variable in creation context is not accessible'
# > @text = "The quick brown fox jumps over the lazy dog"
# > window.text
# "The quick brown fox jumps over the lazy dog"
# > typeof text
# "undefined"

21: 'the rewriter should not rely on automatic semicolon insertion'
# > "the rewriter should not rely"
Expand Down
2 changes: 1 addition & 1 deletion test/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
[true, 25, , 88])

t('variable in creation context is not accessible',
[true, '"The quick brown fox jumps over the lazy dog"', , 93])
[true, '"undefined"', , 92])

start()
}
Expand Down
9 changes: 4 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ global = 'global'
// . 7,8,9]
// [1,2,3,4,5,6,7,8,9]
14, 'multiline assignment'
// > text = "input " +
// > string = "input " +
// . "may span many " +
// . "lines"
// > text
// > string
// "input may span many lines"

15, 'spaces following "//" and ">" are optional'
Expand All @@ -88,9 +88,8 @@ global = 'global'
// 25 // comment

20, 'variable in creation context is not accessible'
// > text = "The quick brown fox jumps over the lazy dog"
// > window.text
// "The quick brown fox jumps over the lazy dog"
// > typeof text
// "undefined"

21, 'the rewriter should not rely on automatic semicolon insertion'
// > "the rewriter should not rely"
Expand Down

0 comments on commit 92dc561

Please sign in to comment.