…to refactorTests
…to refactorTests
* _test_existence.coffee * _test_pattern_matching.coffee
Also added `global ?= window` where necessary. Firefox seems to be complaining about an unexpected lambda still, though.
…to refactorTests
reference to global
…guments) instead of call(this)
This change allows files to be `--require`d before entering the REPL. It's also an opimization, since files are `--require`d only once, rather than being required again every time a file is compiled. A secondary change is that `module.filename` is temporarily modified. This is somewhat less aesthetically appealing than the old approach of using fs.realpathSync, but it allows you to run `coffee -r ./foo` rather than having to write `coffee -r ./foo.coffee`, since Node does not accept absolute paths without a file extension.
| @@ -16,7 +16,7 @@ header = """ | ||
| * CoffeeScript Compiler v#{CoffeeScript.VERSION} | ||
| * http://coffeescript.org | ||
| * | ||
| * Copyright 2010, Jeremy Ashkenas | ||
| * Copyright 2011, Jeremy Ashkenas | ||
| * Released under the MIT License | ||
| */ | ||
| """ | ||
| @@ -50,10 +50,10 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) | ||
| exec([ | ||
| "mkdir -p #{lib} #{bin}" | ||
| "cp -rf bin lib LICENSE README package.json src #{lib}" | ||
| "ln -sf #{lib}/bin/coffee #{bin}/coffee" | ||
| "ln -sf #{lib}/bin/cake #{bin}/cake" | ||
| "ln -sfn #{lib}/bin/coffee #{bin}/coffee" | ||
| "ln -sfn #{lib}/bin/cake #{bin}/cake" | ||
| "mkdir -p ~/.node_libraries" | ||
| "ln -sf #{lib}/lib #{node}" | ||
| "ln -sfn #{lib}/lib #{node}" | ||
| ].join(' && '), (err, stdout, stderr) -> | ||
| if err then console.log stderr.trim() else log 'done', green | ||
| ) | ||
| @@ -104,6 +104,7 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser', | ||
| """ | ||
| code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle ast, extra: yes | ||
| fs.writeFileSync 'extras/coffee-script.js', header + '\n' + code | ||
| console.log "built ... running browser tests:" | ||
| invoke 'test:browser' | ||
|
|
||
|
|
||
| @@ -150,6 +151,9 @@ runTests = (CoffeeScript) -> | ||
| passedTests = 0 | ||
| failures = [] | ||
|
|
||
| # make "global" reference available to tests | ||
| global.global = global | ||
|
|
||
| # Mix in the assert module globally, to make it available for tests. | ||
| addGlobal = (name, func) -> | ||
| global[name] = -> | ||
| @@ -165,7 +169,8 @@ runTests = (CoffeeScript) -> | ||
| # Our test helper function for delimiting different test cases. | ||
| global.test = (description, fn) -> | ||
| try | ||
| fn() | ||
| fn.test = {description, currentFile} | ||
| fn.call(fn) | ||
| catch e | ||
| e.description = description if description? | ||
| e.source = fn.toString() if fn.toString? | ||
| @@ -208,11 +213,11 @@ runTests = (CoffeeScript) -> | ||
| fs.readdir 'test', (err, files) -> | ||
| files.forEach (file) -> | ||
| return unless file.match(/\.coffee$/i) | ||
| fileName = path.join 'test', file | ||
| fs.readFile fileName, (err, code) -> | ||
| currentFile = fileName | ||
| filename = path.join 'test', file | ||
| fs.readFile filename, (err, code) -> | ||
| currentFile = filename | ||
| try | ||
| CoffeeScript.run code.toString(), {fileName} | ||
| CoffeeScript.run code.toString(), {filename} | ||
| catch e | ||
| failures.push file: currentFile, error: e | ||
|
|
||
| @@ -1,4 +1,4 @@ | ||
| Copyright (c) 2010 Jeremy Ashkenas | ||
| Copyright (c) 2011 Jeremy Ashkenas | ||
|
|
||
| Permission is hereby granted, free of charge, to any person | ||
| obtaining a copy of this software and associated documentation | ||
| @@ -1,5 +1,5 @@ | ||
| ### | ||
| CoffeeScript Compiler v1.0.0 | ||
| CoffeeScript Compiler v1.0.1 | ||
| Released under the MIT License | ||
| ### | ||
|
|
||
| @@ -1,4 +1,4 @@ | ||
| for fileName in list | ||
| do (fileName) -> | ||
| fs.readFile fileName, (err, contents) -> | ||
| compile fileName, contents.toString() | ||
| for filename in list | ||
| do (filename) -> | ||
| fs.readFile filename, (err, contents) -> | ||
| compile filename, contents.toString() |
| @@ -45,6 +45,7 @@ table { | ||
| } | ||
| td { | ||
| padding: 9px 15px 9px 0; | ||
| vertical-align: top; | ||
| } | ||
| table.definitions { | ||
| width: auto; | ||
| @@ -25,7 +25,7 @@ | ||
| <span class="nx">path</span><span class="p">.</span><span class="nx">exists</span> <span class="s1">'Cakefile'</span><span class="p">,</span> <span class="p">(</span><span class="nx">exists</span><span class="p">)</span> <span class="o">-></span> | ||
| <span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s2">"Cakefile not found in #{process.cwd()}"</span><span class="p">)</span> <span class="nx">unless</span> <span class="nx">exists</span> | ||
| <span class="nv">args = </span><span class="nx">process</span><span class="p">.</span><span class="nx">argv</span><span class="p">.</span><span class="nx">slice</span> <span class="mi">2</span> | ||
| <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s1">'Cakefile'</span><span class="p">).</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">fileName</span><span class="o">:</span> <span class="s1">'Cakefile'</span> | ||
| <span class="nx">CoffeeScript</span><span class="p">.</span><span class="nx">run</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s1">'Cakefile'</span><span class="p">).</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">filename</span><span class="o">:</span> <span class="s1">'Cakefile'</span> | ||
| <span class="nv">oparse = </span><span class="k">new</span> <span class="nx">optparse</span><span class="p">.</span><span class="nx">OptionParser</span> <span class="nx">switches</span> | ||
| <span class="k">return</span> <span class="nx">printTasks</span><span class="p">()</span> <span class="nx">unless</span> <span class="nx">args</span><span class="p">.</span><span class="nx">length</span> | ||
| <span class="nv">options = </span><span class="nx">oparse</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">args</span><span class="p">)</span> | ||
Showing you all comments on commits in this comparison.
|
Just for the record, this was for issue #972. |
|
Much much more clean -- thank you Michael :) |
|
Maybe you should instead use |
|
Thanks -- I've changed it to |
|
This should use the |
|
'fraid I disagree, in the name of clarity. But I'd be fine with exchanging it for a less controversial example. |
|
Take one from underscore: Too simple? |
|
Too tautological. We need the "when" clause to express the conditional bit. Revised here: 6fb2088 |
|
This is definitely an improvement. |
|
The condition was a truthiness check on |