clash 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b7b82b5cd0a85820950dd5c99efd17b691ccf03
4
- data.tar.gz: 64531edccef8ecddf75f0e1213e21b9b5d707029
3
+ metadata.gz: 39d92dbce4ec886753820de001ead65ecc70c7ab
4
+ data.tar.gz: 5bf66afe83d476c95eb86698958e6433253b612c
5
5
  SHA512:
6
- metadata.gz: 9d92cafe484dca27c591d2baa9efd779b72e2d5acd77244fb7f7c23b8896a9dc5ca43b464cd949aa96fe01cac48333646afa694af6a38e7a2c5e92413e6cdc45
7
- data.tar.gz: 6a5db7204b32c9ad95c5fb2346063feaf1e9c8afbc5f3a446e59402c246425947a3b24c6d1e845b1d57c9a7fc3d728b520b0eb5cc13dc2e514fcd79c769208a4
6
+ metadata.gz: 7997bbf948e49ec53adf60f533f123f53aca55e337fcfa6025f653901ea7a62c99694a0a629b541d1642a3a3facd706e999a54662b40fc6d25ac390e4ea1186e
7
+ data.tar.gz: bc012514d2a41d416ee165f6eaea817ad0b624d8a89ff4eac74587b534f40ba62aa909b2c529e082568f6090af04969edf61c40951269a3046aca14c96a0d698
data/bin/clash CHANGED
@@ -11,16 +11,22 @@ banner = <<-BANNER
11
11
  clash #{Clash::VERSION} -- Clash is a diff based testing suite for static sites.
12
12
 
13
13
  Usage:
14
-
14
+ # Run tests
15
15
  clash [path] [tests] [options]
16
16
 
17
17
  To run only specific tests, pass test numbers separated by commas.
18
18
 
19
- $ clash test # Compare files in the 'test' directory
20
- $ clash 1 # Run only the first test
21
- $ clash 2,3 # Run the second and third tests
22
- $ clash 2-4 # Run the second, third, and fourth tests
23
- $ clash test 1 # Run the first test in the 'test' directory.
19
+ $ clash # Run all tests
20
+ $ clash 1 # Run only the first test
21
+ $ clash 2,3 # Run the second and third tests
22
+ $ clash 2-4 # Run the second, third, and fourth tests
23
+ $ clash :10 # Run the test on line 10
24
+ $ clash :10-:35 # Run all tests from line 10 to 35
25
+ $ clash test # Run all tests in the 'test' directory, reading test/_clash.yml.
26
+ $ clash test 1 # Run the first test in the 'test' directory.
27
+
28
+ # Add testing scaffold
29
+ clash init [path] [options]
24
30
 
25
31
  Options:
26
32
 
@@ -40,20 +46,32 @@ CONFIG
40
46
  OptionParser.new do |opts|
41
47
  opts.banner = banner
42
48
 
43
- opts.on("-f FILE", "--file FILE", "Use a specific test file (default: [PATH]/.clash.yml)") do |f|
44
- options[:file] = f
45
- end
49
+ if ARGV.first == 'init'
50
+ options[:init] = ARGV.shift
46
51
 
47
- opts.on("-c", "--context NUMBER", Integer, "On diff errors, show NUMBER of lines of surrounding context (default: 2)") do |context|
48
- options[:context] = context
49
- end
52
+ opts.on("-f", "--force", "Overwrite existing content") do |f|
53
+ options[:force] = f
54
+ end
55
+ else
56
+ opts.on("-b", "--build", "Build mode: Runs only 'before' and 'build' actions.") do |b|
57
+ options[:build_only] = b
58
+ end
50
59
 
51
- opts.on("-l", "--list", "Print a list of tests' numbers and titles") do |l|
52
- options[:list] = l
53
- end
60
+ opts.on("-f FILE", "--file FILE", "Use a specific test file (default: [PATH]/.clash.yml)") do |f|
61
+ options[:file] = f
62
+ end
63
+
64
+ opts.on("-c", "--context NUMBER", Integer, "On diff errors, show NUMBER of lines of surrounding context (default: 2)") do |context|
65
+ options[:context] = context
66
+ end
54
67
 
55
- opts.on("-d", "--debug", "Display output from system commands") do |d|
56
- options[:debug] = d
68
+ opts.on("-l", "--list", "Print a list of tests' numbers and titles") do |l|
69
+ options[:list] = l
70
+ end
71
+
72
+ opts.on("-d", "--debug", "Display output from system commands") do |d|
73
+ options[:debug] = d
74
+ end
57
75
  end
58
76
 
59
77
  opts.on("-h", "--help", "Show this message") do |h|
@@ -64,15 +82,19 @@ OptionParser.new do |opts|
64
82
 
65
83
  end.parse!
66
84
 
67
- unless ARGV.empty?
68
- # Parse input `clash 1 2 3` and `clash 1,2,3` and `clash 1-3` the same
69
- #
70
- options[:path] = ARGV.shift if ARGV.first =~ /\D+/
71
- options[:only] = Clash::Helpers.expand_list_of_numbers ARGV
72
- end
85
+ if options[:init]
86
+ Clash::Scaffold.new(ARGV, options)
87
+ elsif !options[:help]
88
+
89
+ unless ARGV.empty?
90
+ # Parse input `clash 1 2 3` and `clash 1,2,3` and `clash 1-3` the same
91
+ #
92
+ options[:path] = ARGV.shift if ARGV.first =~ /^[^\d:].+/
93
+ options[:only] = ARGV
94
+ end
73
95
 
74
- unless options[:help]
75
96
  tests = Clash::Tests.new(options)
97
+
76
98
  if options[:list]
77
99
  tests.list
78
100
  else
data/lib/clash.rb CHANGED
@@ -5,17 +5,18 @@ require 'safe_yaml'
5
5
  require 'diffy'
6
6
 
7
7
  module Clash
8
- autoload :Tests, 'clash/tests'
9
- autoload :Test, 'clash/test'
10
- autoload :Diff, 'clash/diff'
11
- autoload :Helpers, 'clash/helpers'
8
+ autoload :Tests, 'clash/tests'
9
+ autoload :Test, 'clash/test'
10
+ autoload :Diff, 'clash/diff'
11
+ autoload :Helpers, 'clash/helpers'
12
+ autoload :Scaffold, 'clash/scaffold'
12
13
  end
13
14
 
14
15
  if defined? Octopress::Docs
15
16
  Octopress::Docs.add({
16
17
  name: "Clash",
17
18
  gem: "clash",
18
- description: "A super simple testing framework for static sites.",
19
+ description: "Clash is an integration test framework designed for Jekyll developers",
19
20
  path: File.expand_path(File.join(File.dirname(__FILE__), "../")),
20
21
  source_url: "https://github.com/imathis/clash",
21
22
  version: Clash::VERSION
data/lib/clash/helpers.rb CHANGED
@@ -7,20 +7,62 @@ module Clash
7
7
  if only.is_a?(Array)
8
8
  only = only.join(',')
9
9
  end
10
- only.split(',').map do |n|
11
- if n.include?("-")
12
- expand_range(n)
10
+ only.split(',').map do |num|
11
+ if num.include?("-")
12
+ expand_range(num)
13
13
  else
14
- n.to_i
14
+ get_number(num)
15
15
  end
16
16
  end.flatten.sort.uniq
17
17
  end
18
18
 
19
19
  def expand_range(string_range)
20
- lower, upper = string_range.split("-").map(&:to_i).take(2).sort
20
+ lower, upper = string_range.split("-").map{|n| get_number(n)}.take(2).sort
21
21
  Array.new(upper+1 - lower).fill { |i| i + lower }
22
22
  end
23
23
 
24
+ def get_number(num)
25
+ if num.start_with?(':')
26
+ test_at_line_number(num)
27
+ else
28
+ num.to_i
29
+ end
30
+ end
31
+
32
+ def read_test_line_numbers(path)
33
+ @test_lines ||= []
34
+ count = 1
35
+ strip_tasks(File.read(path)).each_line do |line|
36
+ @test_lines << count if line =~ /^-/
37
+ count += 1
38
+ end
39
+ end
40
+
41
+ def strip_tasks(content)
42
+ content.gsub(/-\s+tasks:.+?^-/im) do |match|
43
+ match.gsub(/.+?\n/,"\n")
44
+ end
45
+ end
46
+
47
+ def test_at_line_number(line_number)
48
+ ln = line_number.sub(':', '').to_i
49
+ test_number = nil
50
+ lines = @test_lines
51
+ lines.each_with_index do |line, index|
52
+ last = index == lines.size - 1
53
+
54
+ if line <= ln && ( last || ln <= lines[index + 1] )
55
+ test_number = index + 1
56
+ end
57
+ end
58
+
59
+ if test_number
60
+ test_number
61
+ else
62
+ puts "No test found on line #{ln}"
63
+ end
64
+ end
65
+
24
66
  def default_array(option)
25
67
  o = option || []
26
68
  o = [o] unless o.is_a?(Array)
@@ -40,7 +82,7 @@ module Clash
40
82
  # Don't ouput to /dev/null if in debug mode
41
83
  # or if a command supplies its own ouput
42
84
  if !ENV['DEBUG'] && !(cmd =~ / > /)
43
- cmd += " > /dev/null"
85
+ cmd << " > /dev/null"
44
86
  end
45
87
 
46
88
  Kernel.system cmd
@@ -0,0 +1,33 @@
1
+ module Clash
2
+ class Scaffold
3
+ attr_accessor :options
4
+
5
+ def initialize(args, options = {})
6
+ raise 'You must specify a path.' if args.empty?
7
+
8
+ test_path = File.expand_path(args.join(" "), Dir.pwd)
9
+ FileUtils.mkdir_p test_path
10
+ if preserve_source_location?(test_path, options)
11
+ abort "Conflict: #{test_path} exists and is not empty."
12
+ end
13
+
14
+ add_test_scaffold test_path
15
+
16
+ puts "Clash test added to #{test_path}."
17
+ end
18
+
19
+ def add_test_scaffold(path)
20
+ FileUtils.cp_r test_template + '/.', path
21
+ end
22
+
23
+ def test_template
24
+ File.expand_path("../../scaffold", File.dirname(__FILE__))
25
+ end
26
+
27
+ private
28
+
29
+ def preserve_source_location?(path, options)
30
+ !options[:force] && !Dir["#{path}/**/*"].empty?
31
+ end
32
+ end
33
+ end
data/lib/clash/test.rb CHANGED
@@ -8,27 +8,30 @@ module Clash
8
8
  @test_failures = []
9
9
  @options = options
10
10
  @options['config'] ||= {}
11
+ @options['dir'] ||= '.'
11
12
  @cleanup = []
12
13
  end
13
14
 
14
15
  def run
15
- system_cmd(@options['before'])
16
- config
17
- build if @options['build']
18
- compare
19
- enforce_missing
20
- system_cmd(@options['after'])
21
- cleanup_config
16
+ Dir.chdir(@options['dir']) do
17
+ system_cmd(@options['before'])
18
+ config
19
+ build if @options['build']
20
+ unless @options['build_only']
21
+ compare
22
+ enforce_missing
23
+ system_cmd(@options['after'])
24
+ end
25
+ cleanup_config
26
+ end
22
27
  print_result
23
28
  results
24
29
  end
25
30
 
26
31
  def config
27
32
  @options['config'].each do |name, file|
28
- case name
29
- when 'jekyll' then next
30
- when 'octopress' then config_octopress(file)
31
- else config_plugin(name, file)
33
+ if name != 'jekyll'
34
+ config_plugin(name, file)
32
35
  end
33
36
  end
34
37
  end
@@ -70,12 +73,13 @@ module Clash
70
73
  end
71
74
 
72
75
  def build
76
+ options = "--trace"
77
+
73
78
  if jekyll_config = @options['config']['jekyll']
74
- configs = default_array(jekyll_config).join(',')
75
- system("jekyll build --trace --config #{configs}")
76
- else
77
- system("jekyll build --trace")
79
+ options << " --config #{default_array(jekyll_config).join(',')}"
78
80
  end
81
+
82
+ system "jekyll build #{options}"
79
83
  end
80
84
 
81
85
  def system_cmd(cmds)
data/lib/clash/tests.rb CHANGED
@@ -21,14 +21,15 @@ module Clash
21
21
  @options[:only] ||= []
22
22
  @options[:exit] ||= true
23
23
  @options[:path] ||= '.'
24
- @options[:file] ||= '.clash.yml'
24
+ @options[:file] ||= '_clash.yml'
25
25
 
26
+ @clashfile = read_config
26
27
  @tests = read_tests
27
28
  end
28
29
 
29
30
  def list
30
31
  @tests.each_with_index do |options, index|
31
- # If tests are limited, only run specified tests
32
+ # If tests are limited, only show specified tests
32
33
  #
33
34
  next if options.nil?
34
35
  list_test(options, index)
@@ -42,7 +43,6 @@ module Clash
42
43
  end
43
44
 
44
45
  def run
45
-
46
46
  Dir.chdir(@options[:path]) do
47
47
  @tests.each_with_index do |options, index|
48
48
  # If tests are limited, only run specified tests
@@ -60,6 +60,7 @@ module Clash
60
60
  options['index'] = index + 1
61
61
  options['context'] = @options[:context]
62
62
  options['tasks'] = @tasks
63
+ options['build_only'] = @options[:build_only]
63
64
 
64
65
  results = Test.new(options).run
65
66
 
@@ -72,12 +73,11 @@ module Clash
72
73
  end
73
74
 
74
75
  def read_tests
75
- return [] unless File.file?(@options[:file])
76
- tests = SafeYAML.load_file(@options[:file])
77
76
  index = 0
78
77
  delete_tests = []
78
+ @options[:only] = expand_list_of_numbers(@options[:only])
79
79
 
80
- tests = default_array(tests).map do |test|
80
+ tests = default_array(@clashfile).map do |test|
81
81
  if !test['tasks'].nil?
82
82
  @tasks.merge! test['tasks']
83
83
  delete_tests << test
@@ -100,6 +100,30 @@ module Clash
100
100
 
101
101
  end
102
102
 
103
+ def read_config
104
+ # Find the config file (fall back to legacy filename)
105
+ if path = config_path || config_path('.clash.yml')
106
+ read_test_line_numbers(path)
107
+ SafeYAML.load_file(path)
108
+ else
109
+ # If config file still not found, complain
110
+ raise "Config file #{@options[:file]} not found."
111
+ end
112
+ end
113
+
114
+ def config_path(file=nil)
115
+ file ||= @options[:file]
116
+ path = File.join('./', @options[:path])
117
+ paths = []
118
+
119
+ (path.count('/') + 1).times do
120
+ paths << File.join(path, file)
121
+ path.sub!(/\/[^\/]+$/, '')
122
+ end
123
+
124
+ paths.find {|p| File.file?(p) }
125
+ end
126
+
103
127
  def print_results
104
128
 
105
129
 
data/lib/clash/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Clash
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -0,0 +1,5 @@
1
+ -
2
+ title: Test Build
3
+ dir: site
4
+ build: true
5
+ compare: _expected _site
@@ -0,0 +1,4 @@
1
+ name: Test site
2
+ gems: []
3
+ timezone: UTC
4
+ markdown: redcarpet
@@ -0,0 +1 @@
1
+ Test content
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+
4
+ Test content
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clash
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-10 00:00:00.000000000 Z
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -120,9 +120,14 @@ files:
120
120
  - lib/clash.rb
121
121
  - lib/clash/diff.rb
122
122
  - lib/clash/helpers.rb
123
+ - lib/clash/scaffold.rb
123
124
  - lib/clash/test.rb
124
125
  - lib/clash/tests.rb
125
126
  - lib/clash/version.rb
127
+ - scaffold/_clash.yml
128
+ - scaffold/site/_config.yml
129
+ - scaffold/site/_expected/index.html
130
+ - scaffold/site/index.html
126
131
  homepage: https://github.com/imathis/clash
127
132
  licenses:
128
133
  - MIT