# tests.coffee
    1. {spawn, exec} = require 'child_process'
    2. path = require 'path'
    3. fs = require 'fs'
    Determine the test and resources paths
    1. testPath = path.dirname fs.realpathSync(__filename)
    2. dataPath = path.join testPath, "data"
    3. resourcesPath = path.normalize path.join(testPath,"/../resources")
    Run a Docco pass and check that the number of output files is equal to what is expected.
    1. testDoccoRun = (testName,sources,options=null,callback=null) ->
    2. destPath = path.join dataPath, testName
    3. cleanup = (callback) -> exec "rm -rf #{destPath}", callback
    4. cleanup ->
    5. options?.output = destPath
    6. Docco.document sources, options, ->
    7. files = []
    8. files = files.concat(Docco.resolveSource(src)) for src in sources
    9. expected = files.length + 1
    10. found = fs.readdirSync(destPath).length
    11. eq found, expected, "find expected output (#{expected} files) - (#{found})"
    12. callback() if callback?
    Custom jst template files should be supported
    1. test "custom JST template file", ->
    2. testDoccoRun "custom_jst",
    3. ["#{testPath}/.coffee"],
    4. template: "#{resourcesPath}/pagelet.jst"
    Custom CSS files should be supported
    1. test "custom CSS file", ->
    2. testDoccoRun "custom_css",
    3. ["#{testPath}/.coffee"],
    4. css: "#{resourcesPath}/pagelet.css"
    Comments should be parsed properly There are special data files located in test/comments for each supported language. The first comment in each file corresponds to the expected number of comments to be parsed from its contents. This test iterates over all the known Docco languages, and tests the ones that have a corresponding data file in test/comments.
    1. test "single line comment parsing", ->
    2. commentsPath = path.join testPath, "comments"
    3. options = template: "#{commentsPath}/comments.jst"
    4. languageKeys = (ext for ext,l of Docco.languages)
    5.  
    6. testNextLanguage = (keys,callback) ->
    7. return callback?() if not keys.length
    8.  
    9. extension = keys.shift()
    10. language = Docco.languages[extension]
    11. languageExample = path.join commentsPath, "#{language.name}#{extension}"
    12. languageTest = "comments_test/#{language.name}"
    13. languagePath = path.join dataPath, languageTest
    14. languageOutput = path.join languagePath, "#{language.name}.html"
    Skip over this language if there is no corresponding test
    1. return testNextLanguage(keys, callback) if not path.existsSync languageExample
    2. testDoccoRun languageTest, [languageExample], options, ->
    3. eq true, path.existsSync(languageOutput), "#{languageOutput} -> output file created properly"
    4.  
    5. content = fs.readFileSync(languageOutput).toString()
    6. comments = (c.trim() for c in content.split(',') when c.trim() != '')
    7.  
    8. eq true, comments.length >= 1, 'expect at least the descriptor comment'
    9.  
    10. expected = parseInt(comments[0])
    11. eq comments.length, expected, [
    12. ""
    13. "#{path.basename(languageOutput)} comments"
    14. "————————————"
    15. " expected : #{expected}"
    16. " found : #{comments.length}"
    17. ].join '\n'
    18.  
    19. testNextLanguage keys, callback
    Kick off the first language test
    1. testNextLanguage languageKeys.slice()
    2.  
    3.