xcop 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a6ccb74aba5266d9d28402c6315d36acd81cf0f
4
- data.tar.gz: c4609f91ded068883e836c3e39e09d04eb938b5a
3
+ metadata.gz: 224e5335c950bd78ecfdef602bfb503ca1c42b2d
4
+ data.tar.gz: f5f46f16fdc922a08c4676cd00e036e7925f8434
5
5
  SHA512:
6
- metadata.gz: a3015b554e7fde25f6a6787f6be649bd4d9d205053ad1943ff7c7f793503833bf18cac0b70bfeb5c62e43b6ae855c977d107f78ae7469d7529057ec0417b2ba9
7
- data.tar.gz: 86fc6a917eea6d37753bce99c8c2bc7a72e96d959717cff51f5c97cf69f1814f03d4b77b5bb0ff3fcc9e340d1b525ff2bbedb9c0b8967aeef4f504a117ceb3ff
6
+ metadata.gz: dda353bb1dd435d438304047cc7f904bad2dcd28a575ab5fb58a111a742b9067deb93fe3aa069f389d5c2e8b4cdd9afbc3c2ffd9092c6eba733fa3558b4e7a4c
7
+ data.tar.gz: dce36b9a1a547ebaafcb768ac0b0710d89441285c29fa7cc8592195f2ebf18ca6c90ca2d26055e88e74f370550692e693f0e3731fbbbb7a088e41108473f482f
data/.rubocop.yml CHANGED
@@ -3,3 +3,8 @@ AllCops:
3
3
  - 'bin/**/*'
4
4
  - 'assets/**/*'
5
5
  DisplayCopNames: true
6
+
7
+ Metrics/MethodLength:
8
+ Enabled: false
9
+ Style/MultilineMethodCallIndentation:
10
+ Enabled: false
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![We recommend RubyMine](http://img.teamed.io/rubymine-recommend.svg)](https://www.jetbrains.com/ruby/)
4
4
 
5
5
  [![Build Status](https://travis-ci.org/yegor256/xcop.svg)](https://travis-ci.org/yegor256/xcop)
6
- [![Build status](https://ci.appveyor.com/api/projects/status/b59sdhuu0gcku15b?svg=true)](https://ci.appveyor.com/project/yegor256/xcop)
6
+ [![Build status](https://ci.appveyor.com/api/projects/status/orvfo2qgmd1d7a2i?svg=true)](https://ci.appveyor.com/project/yegor256/xcop)
7
7
  [![PDD status](http://www.0pdd.com/svg?name=yegor256/xcop)](http://www.0pdd.com/p?name=yegor256/xcop)
8
8
  [![Gem Version](https://badge.fury.io/rb/xcop.svg)](http://badge.fury.io/rb/xcop)
9
9
  [![Dependency Status](https://gemnasium.com/yegor256/xcop.svg)](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
- diff = Xcop::Document.new(f).diff
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
- # unless now.start_with?(license)
47
- # print "License error\n"
48
- # puts Differ.diff_by_line(license, now).to_s
49
- # raise "License in the header is broken in #{f}"
50
- # end
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
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2017 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Xcop
28
- VERSION = '0.1'.freeze
28
+ VERSION = '0.2'.freeze
29
29
  end
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 'test' do |dir|
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcop
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko