def compile_coffeescript(file)
      begin
        require 'coffee-script'
      rescue LoadError
        $stderr.puts <<-ERROR_MSG
You must install an additional gem to use CoffeeScript source or test files.
Run the following command (with sudo if necessary): gem install coffee-script
        ERROR_MSG

        return <<-ERROR_MSG_SCRIPT
module('CoffeeScript');
test('coffee-script gem must be installed to compile this file: #{file}', function() {
  ok(false, 'Install CoffeeScript support with `gem install coffee-script`')
});
        ERROR_MSG_SCRIPT
      end

      previously_compiled_file = compiled_coffeescript_files[file]
      if previously_compiled_file && File.mtime(file) < File.mtime(previously_compiled_file.path)
        return File.read previously_compiled_file.path
      end

      compiled_js_file = Tempfile.new(["compiled_#{File.basename(file).gsub('.', '_')}", '.js'])

      begin
        contents = CoffeeScript.compile(File.read(file))
      rescue => e
        return <<-COMPILATION_ERROR_SCRIPT
module('CoffeeScript');
test('CoffeeScript compilation error', function() {
  ok(false, "#{e.message.gsub('"', '\"')}")
});
        COMPILATION_ERROR_SCRIPT
      end

      compiled_js_file.write contents
      compiled_js_file.close

      compiled_coffeescript_files[file] = compiled_js_file

      contents
    end
def compile_coffeescript(file)
      begin
        require 'coffee-script'
      rescue LoadError
        $stderr.puts <<-ERROR_MSG
You must install an additional gem to use CoffeeScript source or test files.
Run the following command (with sudo if necessary): gem install coffee-script
        ERROR_MSG

        return <<-ERROR_MSG_SCRIPT
module('CoffeeScript');
test('coffee-script gem must be installed to compile this file: #{file}', function() {
  ok(false, 'Install CoffeeScript support with `gem install coffee-script`')
});
        ERROR_MSG_SCRIPT
      end

      previously_compiled_file = compiled_coffeescript_files[file]
      if previously_compiled_file && File.mtime(file) < File.mtime(previously_compiled_file.path)
        return File.read previously_compiled_file.path
      end

      compiled_js_file = Tempfile.new(["compiled_#{File.basename(file).gsub('.', '_')}", '.js'])

      begin
        contents = CoffeeScript.compile(File.read(file))
      rescue => e
        return <<-COMPILATION_ERROR_SCRIPT
module('CoffeeScript');
test('CoffeeScript compilation error', function() {
  ok(false, "#{e.message.gsub('"', '\"')}")
});
        COMPILATION_ERROR_SCRIPT
      end

      compiled_js_file.write contents
      compiled_js_file.close

      compiled_coffeescript_files[file] = compiled_js_file

      contents
    end
Compile the CoffeeScript file with the given filename to JavaScript. Returns the compiled
 code as a string. Returns failing test JavaScript if CoffeeScript support is not installed.
 Also adds a failing test on compilation failure.