Skip to content

Commit

Permalink
#2 tests completed for CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
neocotic committed Dec 11, 2012
1 parent bc657d2 commit aa7faba
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bin/md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ parsePath = (source, topLevel, base) ->
# Parse `input` and write it to a Markdown file, where appropriate.
parseHtml = (file, input, base) ->
try
output = md input, debug: opts.debug
output = md input, opts
if opts.print
console.log output
else
Expand Down
86 changes: 67 additions & 19 deletions test/cli
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,12 @@ VERSION = """

existsSync = fs.existsSync or path.existsSync

# TODO: Complete test fixtures execution

cleanOutput = ->
if existsSync OUTPUT_DIR
for file in fs.readdirSync OUTPUT_DIR
do (file) -> fs.unlinkSync path.join OUTPUT_DIR, file
fs.rmdirSync OUTPUT_DIR

createOutput = ->
fs.mkdirSync OUTPUT_DIR unless existsSync OUTPUT_DIR

testFixture = (t, name) ->
t.test name, (t) ->
htmlPath = path.join FIXTURES_DIR, "#{name}#{HTML_EXT}"
Expand All @@ -68,41 +63,94 @@ testFixture = (t, name) ->
t.equal markdown, md html
exec "#{COMMAND} -p #{htmlPath}", (err, stdout) ->
t.notOk err
t.equal stdout, md html
t.equal stdout, """
#{md html}
"""

testFixtures = ->
test 'fixtures', (t) ->
createOutput()
files = fs.readdirSync FIXTURES_DIR
fixtures = (
for file in files when HTML_EXT is path.extname file
path.basename file, HTML_EXT
)
for fixture in fixtures
do (fixture) -> testFixture t, fixture
cleanOutput()
t.tearDown cleanOutput
t.end()

testStdio = (t, expected) ->
(err, stdout) ->
t.notOk err
t.equal stdout, expected

toFileUrl = (relativePath) ->
"file://#{toPathName relativePath}"

toPathName = (relativePath) ->
pathName = path.resolve __dirname, '../lib', relativePath
pathName = pathName.replace ///\\///g, '/'
pathName = "/#{pathName}" if pathName[0] isnt '/'
pathName

# Tests
# -----

testFixtures()

test 'absolute', (t) ->
t.plan 6 * 2
exec "#{COMMAND} -ep \"<a href='mock'>anchor</a>\"", testStdio t, """
[anchor][0]
[0]: mock
"""
exec "#{COMMAND} -ep \"<a href='/mock'>anchor</a>\"", testStdio t, """
[anchor][0]
[0]: /mock
"""
exec "#{COMMAND} -epa \"<a href='mock'>anchor</a>\"", testStdio t, """
[anchor][0]
[0]: #{toFileUrl 'mock'}
"""
exec "#{COMMAND} -epa \"<a href='/mock'>anchor</a>\"", testStdio t, """
[anchor][0]
[0]: #{toFileUrl '/mock'}
"""
exec "#{COMMAND} -ep \"<img src='mock'>\"", testStdio t, """
![](mock)
"""
exec "#{COMMAND} -epa \"<img src='mock'>\"", testStdio t, """
![](mock)
"""

test 'stdio', (t) ->
t.plan 2
exec "#{COMMAND} -ep \"<strong>strong</strong>\"", testStdio t, """
**strong**
"""

test 'usage', (t) ->
testUsage = (err, stdout) ->
t.notOk err
t.equal stdout, USAGE
t.plan 3 * 2
exec COMMAND, testUsage
exec "#{COMMAND} -h", testUsage
exec "#{COMMAND} --help", testUsage
t.plan 2 * 2
exec COMMAND, testUsage
exec "#{COMMAND} -h", testUsage

test 'version', (t) ->
testVersion = (err, stdout) ->
t.plan 2
exec "#{COMMAND} -v", (err, stdout) ->
t.notOk err
t.equal stdout, VERSION
t.plan 2 * 2
exec "#{COMMAND} -v", testVersion
exec "#{COMMAND} --version", testVersion

# TODO: Complete tests
t.equal stdout, VERSION

0 comments on commit aa7faba

Please sign in to comment.