junit_merge 0.0.1 → 0.1.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: 169f38c3ea35ae927f10d041fbad8900d4f4a6f2
4
- data.tar.gz: 4a030a4641249fb436e1743f9d94af9c531e3a30
3
+ metadata.gz: 7c5988839b9f2e70c06f6c8537422507866f45f9
4
+ data.tar.gz: 433480317edd29129dfeea288ae73e66780e9e2c
5
5
  SHA512:
6
- metadata.gz: ba9ad5426d4470db02143255d8417e3b78d870be9b31b3334fbb89e77e0a19967c8fdfe7c03f853d1bee02cd083f4a4a86a07cc9cbc967c6f074998bfcd2235d
7
- data.tar.gz: 8ed014fb7239a6964fa45804ac453062613d7af00c7ddbd1679b6ca1dad872164c2a9fca2d5fcc6f9fc4809c642ce984185d594b319739b8c3e793b2b59effa8
6
+ metadata.gz: 4976b5600a486350cd924e8dce075a69a15d1ac6b17ca18a58a28c455687aebf14079c8f50eee1c48a47dde9b9b6753b8a823ac2e27ce67c88c657be0120c969
7
+ data.tar.gz: 7f8430c30a18fb3d1f145f064199e96cc617c5a9f99ba002a67dfdbc28397553249963564b5d829ee8865f08996c5bce139701cacacec72924210449577c1ec6
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1.0 2014-04-18
2
+
3
+ * Allow passing any number of source files.
4
+ * Add --update-only option, to not append new tests in the source.
5
+
1
6
  == 0.0.1 2014-04-15
2
7
 
3
8
  * Hi.
@@ -1,3 +1,4 @@
1
+ require 'optparse'
1
2
  require 'find'
2
3
  require 'fileutils'
3
4
  require 'nokogiri'
@@ -10,35 +11,41 @@ module JunitMerge
10
11
  @stdin = options[:stdin ] || STDIN
11
12
  @stdout = options[:stdout] || STDOUT
12
13
  @stderr = options[:stderr] || STDERR
14
+ @update_only = false
13
15
  end
14
16
 
15
17
  attr_reader :stdin, :stdout, :stderr
16
18
 
17
19
  def run(*args)
18
- source_path, target_path = parse_args(args)
20
+ *source_paths, target_path = parse_args(args)
21
+ all_paths = [*source_paths, target_path]
19
22
 
20
- not_found = [source_path, target_path].select { |path| !File.exist?(path) }
23
+ not_found = all_paths.select { |path| !File.exist?(path) }
21
24
  not_found.empty? or
22
- raise Error, "no such file: #{not_found.join(', ')}"
23
-
24
- if File.directory?(source_path)
25
- Find.find(source_path) do |source_file_path|
26
- next if !File.file?(source_file_path)
27
- target_file_path = source_file_path.sub(source_path, target_path)
28
- if File.exist?(target_file_path)
29
- merge_file(source_file_path, target_file_path)
30
- else
31
- FileUtils.mkdir_p(File.dirname(target_file_path))
32
- FileUtils.cp(source_file_path, target_file_path)
25
+ raise Error, "no such file(s): #{not_found.join(', ')}"
26
+
27
+ if source_paths.empty?
28
+ stderr.puts "warning: no source files given"
29
+ else
30
+ source_paths.each do |source_path|
31
+ if File.directory?(source_path)
32
+ Find.find(source_path) do |source_file_path|
33
+ next if !File.file?(source_file_path)
34
+ target_file_path = source_file_path.sub(source_path, target_path)
35
+ if File.exist?(target_file_path)
36
+ merge_file(source_file_path, target_file_path)
37
+ else
38
+ FileUtils.mkdir_p(File.dirname(target_file_path))
39
+ FileUtils.cp(source_file_path, target_file_path)
40
+ end
41
+ end
42
+ else File.exist?(source_path)
43
+ merge_file(source_path, target_path)
33
44
  end
34
45
  end
35
- elsif File.exist?(source_path)
36
- merge_file(source_path, target_path)
37
- else
38
- raise Error, "no such file: #{source_path}"
39
46
  end
40
47
  0
41
- rescue Error => error
48
+ rescue Error, OptionParser::ParseError => error
42
49
  stderr.puts error.message
43
50
  1
44
51
  end
@@ -63,7 +70,6 @@ module JunitMerge
63
70
 
64
71
  source.xpath("//testsuite/testcase").each do |node|
65
72
  summary_diff = SummaryDiff.new
66
- summary_diff.add(node, 1)
67
73
 
68
74
  predicates = [
69
75
  attribute_predicate('classname', node['classname']),
@@ -72,9 +78,11 @@ module JunitMerge
72
78
  original = target.xpath("testsuite/testcase[#{predicates}]").first
73
79
 
74
80
  if original
81
+ summary_diff.add(node, 1)
75
82
  summary_diff.add(original, -1)
76
83
  original.replace(node)
77
- else
84
+ elsif !@update_only
85
+ summary_diff.add(node, 1)
78
86
  testsuite = target.xpath("testsuite").first
79
87
  testsuite.add_child(node)
80
88
  end
@@ -121,13 +129,19 @@ module JunitMerge
121
129
  end
122
130
 
123
131
  def parse_args(args)
124
- args.size == 2 or
125
- raise Error, usage
126
- args
127
- end
132
+ parser = OptionParser.new do |parser|
133
+ parser.banner = "USAGE: #$0 [options] SOURCES ... TARGET"
134
+ parser.on '-u', '--update-only', "Only update nodes, don't append new nodes in the source." do
135
+ @update_only = true
136
+ end
137
+ end
138
+
139
+ parser.parse!(args)
128
140
 
129
- def usage
130
- "USAGE: #$0 SOURCE TARGET"
141
+ args.size >= 1 or
142
+ raise Error, parser.banner
143
+
144
+ args
131
145
  end
132
146
  end
133
147
  end
@@ -1,5 +1,5 @@
1
1
  module JunitMerge
2
- VERSION = [0, 0, 1]
2
+ VERSION = [0, 1, 0]
3
3
 
4
4
  class << VERSION
5
5
  include Comparable
@@ -95,7 +95,7 @@ describe JunitMerge::App do
95
95
  stderr.string.must_equal('')
96
96
  end
97
97
 
98
- it "appends nodes only in the source" do
98
+ it "appends nodes only in the source by default" do
99
99
  create_file("#{tmp}/source.xml", 'a.a' => :fail, 'a.b' => :error)
100
100
  create_file("#{tmp}/target.xml", 'a.a' => :pass)
101
101
  app.run("#{tmp}/source.xml", "#{tmp}/target.xml").must_equal 0
@@ -106,6 +106,17 @@ describe JunitMerge::App do
106
106
  stderr.string.must_equal('')
107
107
  end
108
108
 
109
+ it "skips nodes only in the source if --update is given" do
110
+ create_file("#{tmp}/source.xml", 'a.a' => :fail, 'a.b' => :error)
111
+ create_file("#{tmp}/target.xml", 'a.a' => :pass)
112
+ app.run('--update-only', "#{tmp}/source.xml", "#{tmp}/target.xml").must_equal 0
113
+ document = parse_file("#{tmp}/target.xml")
114
+ results(document).must_equal([['a.a', :fail]])
115
+ summaries(document).must_equal([{tests: 1, failures: 1, errors: 0, skipped: 0}])
116
+ stdout.string.must_equal('')
117
+ stderr.string.must_equal('')
118
+ end
119
+
109
120
  it "correctly merges tests with metacharacters in the name" do
110
121
  create_file("#{tmp}/source.xml", 'a\'"a.b"\'b' => :pass)
111
122
  create_file("#{tmp}/target.xml", 'a\'"a.b"\'b' => :fail)
@@ -184,9 +195,29 @@ describe JunitMerge::App do
184
195
  stderr.string.must_match /no such file/
185
196
  end
186
197
 
187
- it "errors with a usage message if 2 args aren't given" do
198
+ it "exits with a warning if no source files are given" do
199
+ create_file("#{tmp}/target.xml", 'a.a' => :pass, 'a.b' => :fail)
200
+ app.run("#{tmp}/target.xml").must_equal 0
201
+ document = parse_file("#{tmp}/target.xml")
202
+ results(document).must_equal([['a.a', :pass], ['a.b', :fail]])
203
+ stdout.string.must_equal('')
204
+ stderr.string.must_equal("warning: no source files given\n")
205
+ end
206
+
207
+ it "can merge multiple source files into the target in order" do
208
+ create_file("#{tmp}/source1.xml", 'a.a' => :fail, 'a.b' => :fail)
209
+ create_file("#{tmp}/source2.xml", 'a.a' => :pass)
210
+ create_file("#{tmp}/target.xml", 'a.a' => :error, 'a.b' => :error, 'a.c' => :error)
211
+ app.run("#{tmp}/source1.xml", "#{tmp}/source2.xml", "#{tmp}/target.xml").must_equal 0
212
+ document = parse_file("#{tmp}/target.xml")
213
+ results(document).must_equal([['a.a', :pass], ['a.b', :fail], ['a.c', :error]])
214
+ stdout.string.must_equal('')
215
+ stderr.string.must_equal('')
216
+ end
217
+
218
+ it "errors with a usage message if no args aren't given" do
188
219
  FileUtils.touch "#{tmp}/source.xml"
189
- app.run("#{tmp}/source.xml").must_equal 1
220
+ app.run.must_equal 1
190
221
  File.read("#{tmp}/source.xml").must_equal('')
191
222
  stdout.string.must_equal('')
192
223
  stderr.string.must_match /USAGE/
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junit_merge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Ogata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri