| @@ -1,18 +1,28 @@ | |||
| require 'rake' | |||
| require 'rake/clean' | |||
| task :default => 'test:integration' | |||
| task :default => :test | |||
| namespace :test do | |||
| desc "Run all integration tests" | |||
| task :integration do | |||
| require File.expand_path('../test/integration', __FILE__) | |||
| end | |||
| ROOT = File.expand_path('..', __FILE__) | |||
| MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js')) | |||
| desc "Run all unit tests" | |||
| task :unit do | |||
| require File.expand_path('../test/unit', __FILE__) | |||
| end | |||
| def mustache_version | |||
| match = MUSTACHE_JS.match(/exports\.version = "([^"]+)";/) | |||
| match[1] | |||
| end | |||
| def minified_file | |||
| ENV['FILE'] || 'mustache.min.js' | |||
| end | |||
| desc "Run all tests, requires vows (see http://vowsjs.org)" | |||
| task :test do | |||
| sh "vows test/*_test.js" | |||
| end | |||
| desc "Minify to #{minified_file}, requires UglifyJS (see http://marijnhaverbeke.nl/uglifyjs)" | |||
| task :minify do | |||
| sh "uglifyjs mustache.js > #{minified_file}" | |||
| end | |||
| # Creates a task that uses the various template wrappers to make a wrapped | |||
| @@ -52,11 +62,3 @@ templated_build "Dojo", :location => "dojox/string" | |||
| templated_build "YUI3", :location => "yui3/mustache" | |||
| templated_build "RequireJS" | |||
| templated_build "qooxdoo" | |||
| task :minify do | |||
| # npm install uglify-js | |||
| mmjs = "mustache.min.js" | |||
| `echo "/*! Version: 0.5.1-dev */" > #{mmjs}` | |||
| `uglifyjs mustache.js >> #{mmjs}` | |||
| puts "Created #{mmjs}" | |||
| end | |||
| @@ -1,48 +0,0 @@ | |||
| require 'test/unit' | |||
| module Mustache | |||
| extend self | |||
| ROOT = File.expand_path('../..', __FILE__) | |||
| TEST = File.join(ROOT, 'test') | |||
| TEST_FILES = File.join(TEST, '_files') | |||
| MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js')) | |||
| TESTS = Dir.glob(File.join(TEST_FILES, '*.js')).map do |name| | |||
| File.basename name, '.js' | |||
| end | |||
| NODE_PATH = `which node`.strip | |||
| JS_PATH = `which js`.strip | |||
| JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" | |||
| RHINO_JAR = "org.mozilla.javascript.tools.shell.Main" | |||
| def javascript_engines | |||
| %w[v8 spidermonkey javascriptcore rhino] | |||
| end | |||
| def available_javascript_engines | |||
| javascript_engines.select {|engine| send("has_#{engine}?") } | |||
| end | |||
| def has_any_engines? | |||
| available_javascript_engines.any? | |||
| end | |||
| def has_v8? | |||
| File.exist?(NODE_PATH) | |||
| end | |||
| def has_spidermonkey? | |||
| File.exist?(JS_PATH) | |||
| end | |||
| def has_javascriptcore? | |||
| File.exist?(JSC_PATH) | |||
| end | |||
| def has_rhino? | |||
| `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/ | |||
| end | |||
| end | |||
| @@ -1,76 +0,0 @@ | |||
| require File.expand_path('../helper', __FILE__) | |||
| require 'fileutils' | |||
| require 'json' | |||
| module Mustache | |||
| class Test < Test::Unit::TestCase | |||
| def self.run_tests_for(engine) | |||
| TESTS.each do |test| | |||
| define_method("test_#{engine}_#{test}") do | |||
| template, view, partial, expect = load_test(test) | |||
| assert_equal expect, run_js(engine, <<-JS).chomp | |||
| try { | |||
| #{boilerplate_for(engine)} | |||
| var template = #{template.to_json}; | |||
| var view = #{view}; | |||
| var partials = {partial: #{partial.to_json}}; | |||
| print(Mustache.render(template, view, partials)); | |||
| } catch(e) { | |||
| print('ERROR: ' + e.message); | |||
| } | |||
| JS | |||
| end | |||
| end | |||
| end | |||
| unless Mustache.has_any_engines? | |||
| abort "ERROR: Please install node, SpiderMonkey, JavaScriptCore or Rhino" | |||
| end | |||
| run_tests_for :v8 if Mustache.has_v8? | |||
| run_tests_for :spidermonkey if Mustache.has_spidermonkey? | |||
| run_tests_for :javascriptcore if Mustache.has_javascriptcore? | |||
| run_tests_for :rhino if Mustache.has_rhino? | |||
| private | |||
| def load_test(name) | |||
| template_file = File.join(TEST_FILES, "#{name}.mustache") | |||
| view_file = File.join(TEST_FILES, "#{name}.js") | |||
| partial_file = File.join(TEST_FILES, "#{name}.partial") | |||
| expect_file = File.join(TEST_FILES, "#{name}.txt") | |||
| [template_file, view_file, partial_file, expect_file].map do |file| | |||
| File.exist?(file) ? File.read(file) : "" | |||
| end | |||
| end | |||
| def runner_file | |||
| "runner.js" | |||
| end | |||
| def run_js(engine, js) | |||
| cmd = case engine | |||
| when :v8 then NODE_PATH | |||
| when :spidermonkey then JS_PATH | |||
| when :javascriptcore then JSC_PATH | |||
| when :rhino then "java #{RHINO_JAR}" | |||
| end | |||
| File.open(runner_file, 'w') {|file| file.write(js) } | |||
| `#{cmd} #{runner_file}` | |||
| ensure | |||
| FileUtils.rm_r(runner_file) | |||
| end | |||
| def boilerplate_for(engine) | |||
| boilerplate = MUSTACHE_JS | |||
| boilerplate += "\nvar print = console.log;" if engine == :v8 | |||
| boilerplate | |||
| end | |||
| end | |||
| end | |||
| @@ -1,7 +0,0 @@ | |||
| require File.expand_path('../helper', __FILE__) | |||
| if Mustache.has_v8? | |||
| exec "vows #{Mustache::TEST}/*_test.js" | |||
| else | |||
| abort "ERROR: Please install node" | |||
| end | |||