xcop 0.1 → 0.2
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 +4 -4
- data/.rubocop.yml +5 -0
- data/README.md +1 -1
- data/bin/xcop +14 -2
- data/features/cli.feature +43 -3
- data/lib/xcop.rb +13 -5
- data/lib/xcop/version.rb +1 -1
- data/test/test_xcop.rb +21 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 224e5335c950bd78ecfdef602bfb503ca1c42b2d
|
4
|
+
data.tar.gz: f5f46f16fdc922a08c4676cd00e036e7925f8434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dda353bb1dd435d438304047cc7f904bad2dcd28a575ab5fb58a111a742b9067deb93fe3aa069f389d5c2e8b4cdd9afbc3c2ffd9092c6eba733fa3558b4e7a4c
|
7
|
+
data.tar.gz: dce36b9a1a547ebaafcb768ac0b0710d89441285c29fa7cc8592195f2ebf18ca6c90ca2d26055e88e74f370550692e693f0e3731fbbbb7a088e41108473f482f
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](https://www.jetbrains.com/ruby/)
|
4
4
|
|
5
5
|
[](https://travis-ci.org/yegor256/xcop)
|
6
|
-
[](https://ci.appveyor.com/project/yegor256/xcop)
|
7
7
|
[](http://www.0pdd.com/p?name=yegor256/xcop)
|
8
8
|
[](http://badge.fury.io/rb/xcop)
|
9
9
|
[](https://gemnasium.com/yegor256/xcop)
|
data/bin/xcop
CHANGED
@@ -32,6 +32,7 @@ opts = Slop.parse(ARGV, strict: true, help: true) do |o|
|
|
32
32
|
o.banner = "Usage (#{Xcop::VERSION}): xcop [options] [files...]"
|
33
33
|
o.bool '-h', '--help', 'Show these instructions'
|
34
34
|
o.bool '--version', 'Show current version'
|
35
|
+
o.string '--license', 'File name of the boilerplate head license'
|
35
36
|
end
|
36
37
|
|
37
38
|
if opts.help?
|
@@ -46,14 +47,25 @@ end
|
|
46
47
|
|
47
48
|
Encoding.default_external = Encoding::UTF_8
|
48
49
|
Encoding.default_internal = Encoding::UTF_8
|
50
|
+
|
51
|
+
license = opts.license? ? File.read(opts[:license]) : ''
|
52
|
+
|
49
53
|
opts.arguments.each do |f|
|
50
54
|
print "Validating #{f}... "
|
51
|
-
|
55
|
+
doc = Xcop::Document.new(f)
|
56
|
+
diff = doc.diff
|
52
57
|
unless diff.empty?
|
53
58
|
print "Error\n"
|
54
59
|
puts diff
|
55
|
-
puts "XML formatting is broken in #{f}"
|
56
60
|
exit -1
|
57
61
|
end
|
62
|
+
unless license.empty?
|
63
|
+
ldiff = doc.ldiff(license)
|
64
|
+
unless ldiff.empty?
|
65
|
+
print "Broken license\n"
|
66
|
+
puts ldiff
|
67
|
+
exit -1
|
68
|
+
end
|
69
|
+
end
|
58
70
|
print "OK\n"
|
59
71
|
end
|
data/features/cli.feature
CHANGED
@@ -14,15 +14,36 @@ Feature: Command Line Processing
|
|
14
14
|
Scenario: Validating correct XML file
|
15
15
|
Given I have a "test.xml" file with content:
|
16
16
|
"""
|
17
|
-
<?xml version="1.0"?>
|
18
|
-
<hello>Hello, world!</hello>
|
17
|
+
<?xml version="1.0"?>
|
18
|
+
<hello>Hello, world!</hello>
|
19
19
|
|
20
|
-
"""
|
20
|
+
"""
|
21
21
|
When I run bin/xcop with "test.xml"
|
22
22
|
Then Stdout contains "OK"
|
23
23
|
And Exit code is zero
|
24
24
|
And Stdout contains "Validating test.xml..."
|
25
25
|
|
26
|
+
Scenario: Validating correct XML file with license
|
27
|
+
Given I have a "licensed.xml" file with content:
|
28
|
+
"""
|
29
|
+
<?xml version="1.0"?>
|
30
|
+
<!--
|
31
|
+
This is the license,
|
32
|
+
which is very very strict!
|
33
|
+
-->
|
34
|
+
<hello>Hello, world!</hello>
|
35
|
+
|
36
|
+
"""
|
37
|
+
And I have a "LICENSE" file with content:
|
38
|
+
"""
|
39
|
+
This is the license,
|
40
|
+
which is very very strict!
|
41
|
+
"""
|
42
|
+
When I run bin/xcop with "--license LICENSE licensed.xml"
|
43
|
+
Then Stdout contains "OK"
|
44
|
+
And Exit code is zero
|
45
|
+
And Stdout contains "Validating licensed.xml..."
|
46
|
+
|
26
47
|
Scenario: Validating incorrect XML file
|
27
48
|
Given I have a "abc.xml" file with content:
|
28
49
|
"""
|
@@ -31,3 +52,22 @@ Feature: Command Line Processing
|
|
31
52
|
"""
|
32
53
|
When I run bin/xcop with "abc.xml"
|
33
54
|
Then Exit code is not zero
|
55
|
+
|
56
|
+
Scenario: Validating correct XML file with broken license
|
57
|
+
Given I have a "licensed.xml" file with content:
|
58
|
+
"""
|
59
|
+
<?xml version="1.0"?>
|
60
|
+
<!--
|
61
|
+
This is the wrong license!
|
62
|
+
-->
|
63
|
+
<hello>Hello, world!</hello>
|
64
|
+
|
65
|
+
"""
|
66
|
+
And I have a "LICENSE" file with content:
|
67
|
+
"""
|
68
|
+
This is the right license.
|
69
|
+
"""
|
70
|
+
When I run bin/xcop with "--license LICENSE licensed.xml"
|
71
|
+
And Stdout contains "Broken license"
|
72
|
+
And Exit code is not zero
|
73
|
+
|
data/lib/xcop.rb
CHANGED
@@ -43,11 +43,19 @@ module Xcop
|
|
43
43
|
ideal = xml.to_xml(indent: 2)
|
44
44
|
now = File.read(@path)
|
45
45
|
return Differ.diff_by_line(ideal, now).to_s unless now == ideal
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
''
|
47
|
+
end
|
48
|
+
|
49
|
+
# Return the difference for the license.
|
50
|
+
def ldiff(license)
|
51
|
+
xml = Nokogiri::XML(File.open(@path), &:noblanks)
|
52
|
+
now = xml.xpath('/comment()')[0].to_s
|
53
|
+
ideal = [
|
54
|
+
'<!--',
|
55
|
+
*license.strip.split(/\n/).map(&:strip),
|
56
|
+
'-->'
|
57
|
+
].join("\n")
|
58
|
+
return Differ.diff_by_line(ideal, now).to_s unless now == ideal
|
51
59
|
''
|
52
60
|
end
|
53
61
|
end
|
data/lib/xcop/version.rb
CHANGED
data/test/test_xcop.rb
CHANGED
@@ -32,10 +32,30 @@ require_relative '../lib/xcop'
|
|
32
32
|
# License:: MIT
|
33
33
|
class TestXcop < Minitest::Test
|
34
34
|
def test_basic
|
35
|
-
Dir.mktmpdir '
|
35
|
+
Dir.mktmpdir 'test1' do |dir|
|
36
36
|
f = File.join(dir, 'a.xml')
|
37
37
|
File.write(f, "<?xml version=\"1.0\"?>\n<hello>Dude!</hello>\n")
|
38
38
|
assert_equal(Xcop::Document.new(f).diff, '')
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
def test_license_presence
|
43
|
+
Dir.mktmpdir 'test2' do |dir|
|
44
|
+
f = File.join(dir, 'a.xml')
|
45
|
+
license = "Copyright (c) All Good People\nDon't touch it!\n\n"
|
46
|
+
File.write(
|
47
|
+
f,
|
48
|
+
[
|
49
|
+
'<?xml version="1.0"?>',
|
50
|
+
'<!--',
|
51
|
+
'Copyright (c) All Good People',
|
52
|
+
'Don\'t touch it!',
|
53
|
+
'-->',
|
54
|
+
'<hello>Dude!</hello>',
|
55
|
+
''
|
56
|
+
].join("\n")
|
57
|
+
)
|
58
|
+
assert_equal(Xcop::Document.new(f).ldiff(license), '')
|
59
|
+
end
|
60
|
+
end
|
41
61
|
end
|