Finish of moving the unit tests over to Minitest
This commit is contained in:
parent
4b59eb4175
commit
52c4ce2a5a
1
Gemfile
1
Gemfile
|
@ -26,6 +26,7 @@ gem 'jekyll_test_plugin'
|
|||
gem 'jekyll_test_plugin_malicious'
|
||||
gem 'liquid-c', '~> 0.0.3'
|
||||
gem 'minitest'
|
||||
gem 'minitest-reporters'
|
||||
gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2")
|
||||
|
||||
if ENV['BENCHMARK']
|
||||
|
|
|
@ -1,103 +1,101 @@
|
|||
require 'set'
|
||||
|
||||
module Jekyll
|
||||
class Site
|
||||
# Handles the cleanup of a site's destination before it is built.
|
||||
class Cleaner
|
||||
attr_reader :site
|
||||
# Handles the cleanup of a site's destination before it is built.
|
||||
class Cleaner
|
||||
attr_reader :site
|
||||
|
||||
def initialize(site)
|
||||
@site = site
|
||||
def initialize(site)
|
||||
@site = site
|
||||
end
|
||||
|
||||
# Cleans up the site's destination directory
|
||||
def cleanup!
|
||||
FileUtils.rm_rf(obsolete_files)
|
||||
FileUtils.rm_rf(metadata_file) if @site.full_rebuild?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Private: The list of files and directories to be deleted during cleanup process
|
||||
#
|
||||
# Returns an Array of the file and directory paths
|
||||
def obsolete_files
|
||||
(existing_files - new_files - new_dirs + replaced_files).to_a
|
||||
end
|
||||
|
||||
# Private: The metadata file storing dependency tree and build history
|
||||
#
|
||||
# Returns an Array with the metdata file as the only item
|
||||
def metadata_file
|
||||
[site.regenerator.metadata_file]
|
||||
end
|
||||
|
||||
# Private: The list of existing files, apart from those included in keep_files and hidden files.
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def existing_files
|
||||
files = Set.new
|
||||
Dir.glob(site.in_dest_dir("**", "*"), File::FNM_DOTMATCH) do |file|
|
||||
files << file unless file =~ /\/\.{1,2}$/ || file =~ keep_file_regex || keep_dirs.include?(file)
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
# Cleans up the site's destination directory
|
||||
def cleanup!
|
||||
FileUtils.rm_rf(obsolete_files)
|
||||
FileUtils.rm_rf(metadata_file) if @site.full_rebuild?
|
||||
# Private: The list of files to be created when site is built.
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def new_files
|
||||
files = Set.new
|
||||
site.each_site_file { |item| files << item.destination(site.dest) }
|
||||
files
|
||||
end
|
||||
|
||||
# Private: The list of directories to be created when site is built.
|
||||
# These are the parent directories of the files in #new_files.
|
||||
#
|
||||
# Returns a Set with the directory paths
|
||||
def new_dirs
|
||||
new_files.map { |file| parent_dirs(file) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: The list of parent directories of a given file
|
||||
#
|
||||
# Returns an Array with the directory paths
|
||||
def parent_dirs(file)
|
||||
parent_dir = File.dirname(file)
|
||||
if parent_dir == site.dest
|
||||
[]
|
||||
else
|
||||
[parent_dir] + parent_dirs(parent_dir)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Private: The list of existing files that will be replaced by a directory during build
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def replaced_files
|
||||
new_dirs.select { |dir| File.file?(dir) }.to_set
|
||||
end
|
||||
|
||||
# Private: The list of files and directories to be deleted during cleanup process
|
||||
#
|
||||
# Returns an Array of the file and directory paths
|
||||
def obsolete_files
|
||||
(existing_files - new_files - new_dirs + replaced_files).to_a
|
||||
end
|
||||
# Private: The list of directories that need to be kept because they are parent directories
|
||||
# of files specified in keep_files
|
||||
#
|
||||
# Returns a Set with the directory paths
|
||||
def keep_dirs
|
||||
site.keep_files.map { |file| parent_dirs(site.in_dest_dir(file)) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: The metadata file storing dependency tree and build history
|
||||
#
|
||||
# Returns an Array with the metdata file as the only item
|
||||
def metadata_file
|
||||
[site.regenerator.metadata_file]
|
||||
end
|
||||
|
||||
# Private: The list of existing files, apart from those included in keep_files and hidden files.
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def existing_files
|
||||
files = Set.new
|
||||
Dir.glob(site.in_dest_dir("**", "*"), File::FNM_DOTMATCH) do |file|
|
||||
files << file unless file =~ /\/\.{1,2}$/ || file =~ keep_file_regex || keep_dirs.include?(file)
|
||||
end
|
||||
files
|
||||
end
|
||||
|
||||
# Private: The list of files to be created when site is built.
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def new_files
|
||||
files = Set.new
|
||||
site.each_site_file { |item| files << item.destination(site.dest) }
|
||||
files
|
||||
end
|
||||
|
||||
# Private: The list of directories to be created when site is built.
|
||||
# These are the parent directories of the files in #new_files.
|
||||
#
|
||||
# Returns a Set with the directory paths
|
||||
def new_dirs
|
||||
new_files.map { |file| parent_dirs(file) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: The list of parent directories of a given file
|
||||
#
|
||||
# Returns an Array with the directory paths
|
||||
def parent_dirs(file)
|
||||
parent_dir = File.dirname(file)
|
||||
if parent_dir == site.dest
|
||||
[]
|
||||
else
|
||||
[parent_dir] + parent_dirs(parent_dir)
|
||||
end
|
||||
end
|
||||
|
||||
# Private: The list of existing files that will be replaced by a directory during build
|
||||
#
|
||||
# Returns a Set with the file paths
|
||||
def replaced_files
|
||||
new_dirs.select { |dir| File.file?(dir) }.to_set
|
||||
end
|
||||
|
||||
# Private: The list of directories that need to be kept because they are parent directories
|
||||
# of files specified in keep_files
|
||||
#
|
||||
# Returns a Set with the directory paths
|
||||
def keep_dirs
|
||||
site.keep_files.map { |file| parent_dirs(site.in_dest_dir(file)) }.flatten.to_set
|
||||
end
|
||||
|
||||
# Private: Creates a regular expression from the config's keep_files array
|
||||
#
|
||||
# Examples
|
||||
# ['.git','.svn'] creates the following regex: /\/(\.git|\/.svn)/
|
||||
#
|
||||
# Returns the regular expression
|
||||
def keep_file_regex
|
||||
or_list = site.keep_files.join("|")
|
||||
pattern = "\/(#{or_list.gsub(".", "\.")})"
|
||||
Regexp.new pattern
|
||||
end
|
||||
# Private: Creates a regular expression from the config's keep_files array
|
||||
#
|
||||
# Examples
|
||||
# ['.git','.svn'] creates the following regex: /\/(\.git|\/.svn)/
|
||||
#
|
||||
# Returns the regular expression
|
||||
def keep_file_regex
|
||||
or_list = site.keep_files.join("|")
|
||||
pattern = "\/(#{or_list.gsub(".", "\.")})"
|
||||
Regexp.new pattern
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,10 @@ if [ ! -d tmp ]; then
|
|||
mkdir tmp
|
||||
fi
|
||||
|
||||
if [ -d test/dest ]; then
|
||||
rm -r test/dest
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
TEST_FILES=$(ruby -e "puts Dir.glob('test/test_*.rb')")
|
||||
else
|
||||
|
|
|
@ -8,6 +8,7 @@ end
|
|||
require 'rubygems'
|
||||
require 'ostruct'
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/reporters'
|
||||
|
||||
require 'jekyll'
|
||||
|
||||
|
@ -23,6 +24,9 @@ include Jekyll
|
|||
# Send STDERR into the void to suppress program output messages
|
||||
STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
|
||||
|
||||
# Report with color.
|
||||
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)]
|
||||
|
||||
class Minitest::Test
|
||||
def fixture_site(overrides = {})
|
||||
Jekyll::Site.new(site_configuration(overrides))
|
||||
|
@ -33,7 +37,10 @@ class Minitest::Test
|
|||
end
|
||||
|
||||
def site_configuration(overrides = {})
|
||||
full_overrides = build_configs(overrides, build_configs({"destination" => dest_dir}))
|
||||
full_overrides = build_configs(overrides, build_configs({
|
||||
"destination" => dest_dir,
|
||||
"full_rebuild" => true
|
||||
}))
|
||||
build_configs({
|
||||
"source" => source_dir
|
||||
}, full_overrides)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
require 'rubygems'
|
||||
gem 'test-unit'
|
||||
require 'test/unit'
|
||||
|
||||
# for some reason these tests fail when run via TextMate
|
||||
# but succeed when run on the command line.
|
||||
|
||||
tests = Dir[File.expand_path("#{File.dirname(__FILE__)}/test_*.rb")]
|
||||
tests.each do |file|
|
||||
require file
|
||||
end
|
|
@ -12,7 +12,7 @@ class TestCleaner < Minitest::Test
|
|||
@site = fixture_site
|
||||
@site.keep_files = ['to_keep/child_dir']
|
||||
|
||||
@cleaner = Site::Cleaner.new(@site)
|
||||
@cleaner = Cleaner.new(@site)
|
||||
@cleaner.cleanup!
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,7 @@ class TestCleaner < Minitest::Test
|
|||
@site = fixture_site
|
||||
@site.process
|
||||
|
||||
@cleaner = Site::Cleaner.new(@site)
|
||||
@cleaner = Cleaner.new(@site)
|
||||
@cleaner.cleanup!
|
||||
end
|
||||
|
||||
|
|
|
@ -19,16 +19,16 @@ class TestCoffeeScript < Minitest::Test
|
|||
return square(x) * x;
|
||||
};
|
||||
cubes = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||
num = list[_i];
|
||||
_results.push(math.cube(num));
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
num = list[i];
|
||||
results.push(math.cube(num));
|
||||
}
|
||||
return _results;
|
||||
return results;
|
||||
})();
|
||||
if (typeof elvis !== \"undefined\" && elvis !== null) {
|
||||
return alert(\"I knew it!\");
|
||||
if (typeof elvis !== "undefined" && elvis !== null) {
|
||||
return alert("I knew it!");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ class TestCollections < Minitest::Test
|
|||
assert @site.collections["methods"].docs.is_a? Array
|
||||
@site.collections["methods"].docs.each do |doc|
|
||||
assert doc.is_a? Jekyll::Document
|
||||
assert_include %w[
|
||||
assert_includes %w[
|
||||
_methods/configuration.md
|
||||
_methods/sanitized_path.md
|
||||
_methods/site/generate.md
|
||||
|
@ -135,16 +135,16 @@ class TestCollections < Minitest::Test
|
|||
end
|
||||
|
||||
should "not include files which start with an underscore in the base collection directory" do
|
||||
refute_include @collection.filtered_entries, "_do_not_read_me.md"
|
||||
refute_includes @collection.filtered_entries, "_do_not_read_me.md"
|
||||
end
|
||||
|
||||
should "not include files which start with an underscore in a subdirectory" do
|
||||
refute_include @collection.filtered_entries, "site/_dont_include_me_either.md"
|
||||
refute_includes @collection.filtered_entries, "site/_dont_include_me_either.md"
|
||||
end
|
||||
|
||||
should "not include the underscored files in the list of docs" do
|
||||
refute_include @collection.docs.map(&:relative_path), "_methods/_do_not_read_me.md"
|
||||
refute_include @collection.docs.map(&:relative_path), "_methods/site/_dont_include_me_either.md"
|
||||
refute_includes @collection.docs.map(&:relative_path), "_methods/_do_not_read_me.md"
|
||||
refute_includes @collection.docs.map(&:relative_path), "_methods/site/_dont_include_me_either.md"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -178,12 +178,12 @@ class TestCollections < Minitest::Test
|
|||
end
|
||||
|
||||
should "not allow symlinks" do
|
||||
refute_include @collection.filtered_entries, "um_hi.md"
|
||||
refute_include @collection.filtered_entries, "/um_hi.md"
|
||||
refute_includes @collection.filtered_entries, "um_hi.md"
|
||||
refute_includes @collection.filtered_entries, "/um_hi.md"
|
||||
end
|
||||
|
||||
should "not include the symlinked file in the list of docs" do
|
||||
refute_include @collection.docs.map(&:relative_path), "_methods/um_hi.md"
|
||||
refute_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -84,14 +84,12 @@ OUTPUT
|
|||
end
|
||||
|
||||
should "acceptable limit post is 0" do
|
||||
refute_raises ArgumentError do
|
||||
clear_dest
|
||||
stub(Jekyll).configuration do
|
||||
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
|
||||
end
|
||||
|
||||
@site = Site.new(Jekyll.configuration)
|
||||
clear_dest
|
||||
stub(Jekyll).configuration do
|
||||
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
|
||||
end
|
||||
|
||||
assert Site.new(Jekyll.configuration), "Couldn't create a site with the given limit_posts."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,9 +79,8 @@ class TestNewCommand < Minitest::Test
|
|||
|
||||
should 'force created folder' do
|
||||
capture_stdout { Jekyll::Commands::New.process(@args) }
|
||||
refute_raises(SystemExit) do
|
||||
capture_stdout {Jekyll::Commands::New.process(@args, '--force') }
|
||||
end
|
||||
output = capture_stdout { Jekyll::Commands::New.process(@args, '--force') }
|
||||
assert_match /New jekyll site installed in/, output
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ class TestRegenerator < Minitest::Test
|
|||
"methods" => {
|
||||
"output" => true
|
||||
}
|
||||
}
|
||||
},
|
||||
"full_rebuild" => false
|
||||
})
|
||||
|
||||
@site.read
|
||||
|
|
|
@ -309,9 +309,7 @@ class TestSite < Minitest::Test
|
|||
|
||||
custom_processor = "CustomMarkdown"
|
||||
s = Site.new(site_configuration('markdown' => custom_processor))
|
||||
refute_raises do
|
||||
s.process
|
||||
end
|
||||
assert !!s.process
|
||||
|
||||
# Do some cleanup, we don't like straggling stuff's.
|
||||
Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown)
|
||||
|
@ -344,9 +342,7 @@ class TestSite < Minitest::Test
|
|||
context 'with an invalid markdown processor in the configuration' do
|
||||
should 'not throw an error at initialization time' do
|
||||
bad_processor = 'not a processor name'
|
||||
refute_raises do
|
||||
Site.new(site_configuration('markdown' => bad_processor))
|
||||
end
|
||||
assert Site.new(site_configuration('markdown' => bad_processor))
|
||||
end
|
||||
|
||||
should 'throw FatalException at process time' do
|
||||
|
|
Loading…
Reference in New Issue