xcop 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a6ccb74aba5266d9d28402c6315d36acd81cf0f
4
+ data.tar.gz: c4609f91ded068883e836c3e39e09d04eb938b5a
5
+ SHA512:
6
+ metadata.gz: a3015b554e7fde25f6a6787f6be649bd4d9d205053ad1943ff7c7f793503833bf18cac0b70bfeb5c62e43b6ae855c977d107f78ae7469d7529057ec0417b2ba9
7
+ data.tar.gz: 86fc6a917eea6d37753bce99c8c2bc7a72e96d959717cff51f5c97cf69f1814f03d4b77b5bb0ff3fcc9e340d1b525ff2bbedb9c0b8967aeef4f504a117ceb3ff
data/.0pdd.yml ADDED
@@ -0,0 +1,5 @@
1
+ errors:
2
+ - yegor256@gmail.com
3
+ # alerts:
4
+ # github:
5
+ # - yegor256
data/.gitattributes ADDED
@@ -0,0 +1,7 @@
1
+ # Check out all text files in UNIX format, with LF as end of line
2
+ # Don't change this file. If you have any ideas about it, please
3
+ # submit a separate issue about it and we'll discuss.
4
+
5
+ * text=auto eol=lf
6
+ *.java ident
7
+ *.xml ident
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ coverage/
2
+ Gemfile.lock
3
+ .idea/
4
+ *.gem
5
+ .bundle/
6
+ .DS_Store
7
+ rdoc/
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude coverage/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'assets/**/*'
5
+ DisplayCopNames: true
data/.rultor.yml ADDED
@@ -0,0 +1,30 @@
1
+ assets:
2
+ rubygems.yml: zerocracy/home#assets/rubygems.yml
3
+ s3cfg: zerocracy/home#assets/s3cfg
4
+ install: |
5
+ sudo apt-get -y update
6
+ sudo gem install pdd
7
+ release:
8
+ script: |-
9
+ bundle install
10
+ rake
11
+ rm -rf *.gem
12
+ sed -i "s/1\.0\.snapshot/${tag}/g" lib/xcop/version.rb
13
+ git add lib/xcop/version.rb
14
+ git commit -m "version set to ${tag}"
15
+ gem build xcop.gemspec
16
+ chmod 0600 ../rubygems.yml
17
+ gem push *.gem --config-file ../rubygems.yml
18
+ commanders:
19
+ - yegor256
20
+ architect:
21
+ - yegor256
22
+ merge:
23
+ script: |-
24
+ bundle install
25
+ rake
26
+ pdd
27
+ deploy:
28
+ script: |-
29
+ echo "There is nothing to deploy"
30
+ exit -1
data/.simplecov ADDED
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ if Gem.win_platform? then
24
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
25
+ SimpleCov::Formatter::HTMLFormatter
26
+ ]
27
+ SimpleCov.start do
28
+ add_filter "/test/"
29
+ add_filter "/features/"
30
+ end
31
+ else
32
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
33
+ SimpleCov::Formatter::HTMLFormatter,
34
+ ]
35
+ SimpleCov.start do
36
+ add_filter "/test/"
37
+ add_filter "/features/"
38
+ minimum_coverage 90
39
+ end
40
+ end
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ cache: bundler
5
+ branches:
6
+ only:
7
+ - master
8
+ install:
9
+ - travis_retry bundle update
10
+ script:
11
+ - rake
12
+ after_success:
13
+ - "bash <(curl -s https://codecov.io/bash)"
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ source 'https://rubygems.org'
24
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ [![Managed by Zerocracy](http://www.zerocracy.com/badge.svg)](http://www.zerocracy.com)
2
+ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/xcop)](http://www.rultor.com/p/yegor256/xcop)
3
+ [![We recommend RubyMine](http://img.teamed.io/rubymine-recommend.svg)](https://www.jetbrains.com/ruby/)
4
+
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)
7
+ [![PDD status](http://www.0pdd.com/svg?name=yegor256/xcop)](http://www.0pdd.com/p?name=yegor256/xcop)
8
+ [![Gem Version](https://badge.fury.io/rb/xcop.svg)](http://badge.fury.io/rb/xcop)
9
+ [![Dependency Status](https://gemnasium.com/yegor256/xcop.svg)](https://gemnasium.com/yegor256/xcop)
10
+ [![Code Climate](http://img.shields.io/codeclimate/github/yegor256/xcop.svg)](https://codeclimate.com/github/yegor256/xcop)
11
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/xcop.svg)](https://codecov.io/github/yegor256/xcop?branch=master)
12
+
13
+ ## What This is for?
14
+
15
+ This command line tool validates your XML files for proper formatting.
16
+ If they are not formatted correctly, it prints the difference and
17
+ returns with an error. You can use it two ways: 1) to fail your build
18
+ if any X-like files (XML, XSD, XSL, XHTML) are not formatted correctly,
19
+ and 2) to format them correctly.
20
+
21
+ ## How to Install?
22
+
23
+ Install it first:
24
+
25
+ ```bash
26
+ $ gem install xcop
27
+ ```
28
+
29
+ ## How to Run?
30
+
31
+ Run it locally and read its output:
32
+
33
+ ```bash
34
+ $ xcop --help
35
+ ```
36
+
37
+ ## How to contribute?
38
+
39
+ Just submit a pull request. Make sure `rake` passes.
40
+
41
+ ## License
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2017 Yegor Bugayenko
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining a copy
48
+ of this software and associated documentation files (the 'Software'), to deal
49
+ in the Software without restriction, including without limitation the rights
50
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
51
+ copies of the Software, and to permit persons to whom the Software is
52
+ furnished to do so, subject to the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be included in all
55
+ copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
60
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
61
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
62
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
63
+ SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'rake'
25
+ require 'rdoc'
26
+ require 'rake/clean'
27
+
28
+ def name
29
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
30
+ end
31
+
32
+ def version
33
+ Gem::Specification.load(Dir['*.gemspec'].first).version
34
+ end
35
+
36
+ task default: [:clean, :test, :features, :rubocop, :copyright]
37
+
38
+ require 'rake/testtask'
39
+ desc 'Run all unit tests'
40
+ Rake::TestTask.new(:test) do |test|
41
+ Rake::Cleaner.cleanup_files(['coverage'])
42
+ test.libs << 'lib' << 'test'
43
+ test.pattern = 'test/**/test_*.rb'
44
+ test.verbose = false
45
+ end
46
+
47
+ require 'rdoc/task'
48
+ desc 'Build RDoc documentation'
49
+ Rake::RDocTask.new do |rdoc|
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "#{name} #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
55
+
56
+ require 'rubocop/rake_task'
57
+ desc 'Run RuboCop on all directories'
58
+ RuboCop::RakeTask.new(:rubocop) do |task|
59
+ task.fail_on_error = true
60
+ task.requires << 'rubocop-rspec'
61
+ end
62
+
63
+ require 'cucumber/rake/task'
64
+ Cucumber::Rake::Task.new(:features) do
65
+ Rake::Cleaner.cleanup_files(['coverage'])
66
+ end
67
+ Cucumber::Rake::Task.new(:'features:html') do |t|
68
+ t.profile = 'html_report'
69
+ end
70
+
71
+ task :copyright do
72
+ sh "grep -q -r '#{Date.today.strftime('%Y')}' \
73
+ --include '*.rb' \
74
+ --include '*.txt' \
75
+ --include 'Rakefile' \
76
+ ."
77
+ end
data/appveyor.yml ADDED
@@ -0,0 +1,21 @@
1
+ version: '{build}'
2
+ skip_tags: true
3
+ clone_depth: 10
4
+ branches:
5
+ only:
6
+ - master
7
+ except:
8
+ - gh-pages
9
+ os: Windows Server 2012
10
+ install:
11
+ - cmd: SET PATH=C:\Ruby23-x64\bin;%PATH%
12
+ - cmd: ruby --version
13
+ - cmd: git --version
14
+ build_script:
15
+ - bundle update
16
+ - bundle install
17
+ test_script:
18
+ - rake
19
+ cache:
20
+ - C:\Ruby200\bin -> xcop.gemspec
21
+ - C:\Ruby200\lib\ruby\gems\2.0.0 -> xcop.gemspec
data/bin/xcop ADDED
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # Copyright (c) 2017 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ STDOUT.sync = true
25
+
26
+ require 'slop'
27
+ require 'nokogiri'
28
+ require_relative '../lib/xcop'
29
+ require_relative '../lib/xcop/version'
30
+
31
+ opts = Slop.parse(ARGV, strict: true, help: true) do |o|
32
+ o.banner = "Usage (#{Xcop::VERSION}): xcop [options] [files...]"
33
+ o.bool '-h', '--help', 'Show these instructions'
34
+ o.bool '--version', 'Show current version'
35
+ end
36
+
37
+ if opts.help?
38
+ puts opts
39
+ exit
40
+ end
41
+
42
+ if opts.version?
43
+ puts Xcop::VERSION
44
+ exit
45
+ end
46
+
47
+ Encoding.default_external = Encoding::UTF_8
48
+ Encoding.default_internal = Encoding::UTF_8
49
+ opts.arguments.each do |f|
50
+ print "Validating #{f}... "
51
+ diff = Xcop::Document.new(f).diff
52
+ unless diff.empty?
53
+ print "Error\n"
54
+ puts diff
55
+ puts "XML formatting is broken in #{f}"
56
+ exit -1
57
+ end
58
+ print "OK\n"
59
+ end
data/cucumber.yml ADDED
@@ -0,0 +1,3 @@
1
+ default: --format pretty
2
+ travis: --format progress
3
+ html_report: --format progress --format html --out=features_report.html
@@ -0,0 +1,33 @@
1
+ Feature: Command Line Processing
2
+ As an author of XML I want to be able to
3
+ call XCOP as a command line tool
4
+
5
+ Scenario: Help can be printed
6
+ When I run bin/xcop with "-h"
7
+ Then Exit code is zero
8
+ And Stdout contains "--help"
9
+
10
+ Scenario: Version can be printed
11
+ When I run bin/xcop with "--version"
12
+ Then Exit code is zero
13
+
14
+ Scenario: Validating correct XML file
15
+ Given I have a "test.xml" file with content:
16
+ """
17
+ <?xml version="1.0"?>
18
+ <hello>Hello, world!</hello>
19
+
20
+ """
21
+ When I run bin/xcop with "test.xml"
22
+ Then Stdout contains "OK"
23
+ And Exit code is zero
24
+ And Stdout contains "Validating test.xml..."
25
+
26
+ Scenario: Validating incorrect XML file
27
+ Given I have a "abc.xml" file with content:
28
+ """
29
+ <a><b>something</b>
30
+ </a>
31
+ """
32
+ When I run bin/xcop with "abc.xml"
33
+ Then Exit code is not zero
@@ -0,0 +1,24 @@
1
+ Feature: Gem Package
2
+ As a source code writer I want to be able to
3
+ package the Gem into .gem file
4
+
5
+ Scenario: Gem can be packaged
6
+ Given It is Unix
7
+ Given I have a "execs.rb" file with content:
8
+ """
9
+ #!/usr/bin/env ruby
10
+ require 'rubygems'
11
+ spec = Gem::Specification::load('./spec.rb')
12
+ if spec.executables.empty?
13
+ fail 'no executables: ' + File.read('./spec.rb')
14
+ end
15
+ """
16
+ When I run bash with
17
+ """
18
+ cd xcop
19
+ gem build xcop.gemspec
20
+ gem specification --ruby xcop-*.gem > ../spec.rb
21
+ cd ..
22
+ ruby execs.rb
23
+ """
24
+ Then Exit code is zero
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'nokogiri'
24
+ require 'tmpdir'
25
+ require 'slop'
26
+ require 'English'
27
+ require_relative '../../lib/xcop'
28
+
29
+ Before do
30
+ @cwd = Dir.pwd
31
+ @dir = Dir.mktmpdir('test')
32
+ FileUtils.mkdir_p(@dir) unless File.exist?(@dir)
33
+ Dir.chdir(@dir)
34
+ @opts = Slop.parse ['-v', '-s', @dir] do |o|
35
+ o.bool '-v', '--verbose'
36
+ o.string '-s', '--source'
37
+ end
38
+ end
39
+
40
+ After do
41
+ Dir.chdir(@cwd)
42
+ FileUtils.rm_rf(@dir) if File.exist?(@dir)
43
+ end
44
+
45
+ Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
46
+ FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
47
+ File.open(file, 'w') do |f|
48
+ f.write(text.gsub(/\\xFF/, 0xFF.chr))
49
+ end
50
+ end
51
+
52
+ When(%r{^I run bin/xcop with "([^"]*)"$}) do |arg|
53
+ home = File.join(File.dirname(__FILE__), '../..')
54
+ @stdout = `ruby -I#{home}/lib #{home}/bin/xcop #{arg}`
55
+ @exitstatus = $CHILD_STATUS.exitstatus
56
+ end
57
+
58
+ Then(/^Stdout contains "([^"]*)"$/) do |txt|
59
+ unless @stdout.include?(txt)
60
+ raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}"
61
+ end
62
+ end
63
+
64
+ Then(/^Stdout is empty$/) do
65
+ raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
66
+ end
67
+
68
+ Then(/^Exit code is zero$/) do
69
+ raise "Non-zero exit code #{@exitstatus}" unless @exitstatus == 0
70
+ end
71
+
72
+ Then(/^Exit code is not zero$/) do
73
+ raise 'Zero exit code' if @exitstatus == 0
74
+ end
75
+
76
+ When(/^I run bash with$/) do |text|
77
+ FileUtils.copy_entry(@cwd, File.join(@dir, 'xcop'))
78
+ @stdout = `#{text}`
79
+ @exitstatus = $CHILD_STATUS.exitstatus
80
+ end
81
+
82
+ Given(/^It is Unix$/) do
83
+ pending if Gem.win_platform?
84
+ end
85
+
86
+ Given(/^It is Windows$/) do
87
+ pending unless Gem.win_platform?
88
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'simplecov'
24
+ require_relative '../../lib/xcop'
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ # Xcop main module.
24
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
25
+ # Copyright:: Copyright (c) 2017 Yegor Bugayenko
26
+ # License:: MIT
27
+ module Xcop
28
+ VERSION = '0.1'.freeze
29
+ end
data/lib/xcop.rb ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'nokogiri'
24
+ require 'differ'
25
+ require_relative 'xcop/version'
26
+
27
+ # Xcop main module.
28
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
+ # Copyright:: Copyright (c) 2017 Yegor Bugayenko
30
+ # License:: MIT
31
+ module Xcop
32
+ # One document.
33
+ class Document
34
+ # Ctor.
35
+ # +path+:: Path of it
36
+ def initialize(path)
37
+ @path = path
38
+ end
39
+
40
+ # Return the difference, if any (empty string if everything is clean).
41
+ def diff
42
+ xml = Nokogiri::XML(File.open(@path), &:noblanks)
43
+ ideal = xml.to_xml(indent: 2)
44
+ now = File.read(@path)
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
51
+ ''
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ STDOUT.sync = true
24
+
25
+ require 'simplecov'
26
+ SimpleCov.start
27
+ if ENV['CI'] == 'true'
28
+ require 'codecov'
29
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
30
+ end
31
+
32
+ require 'minitest/autorun'
33
+ require_relative '../lib/xcop'
data/test/test_xcop.rb ADDED
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require 'nokogiri'
25
+ require 'tmpdir'
26
+ require 'slop'
27
+ require_relative '../lib/xcop'
28
+
29
+ # Xcop main module test.
30
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
+ # Copyright:: Copyright (c) 2017 Yegor Bugayenko
32
+ # License:: MIT
33
+ class TestXcop < Minitest::Test
34
+ def test_basic
35
+ Dir.mktmpdir 'test' do |dir|
36
+ f = File.join(dir, 'a.xml')
37
+ File.write(f, "<?xml version=\"1.0\"?>\n<hello>Dude!</hello>\n")
38
+ assert_equal(Xcop::Document.new(f).diff, '')
39
+ end
40
+ end
41
+ end
data/xcop.gemspec ADDED
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Copyright (c) 2017 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'English'
24
+
25
+ lib = File.expand_path('../lib', __FILE__)
26
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
27
+ require_relative 'lib/xcop/version'
28
+
29
+ Gem::Specification.new do |s|
30
+ s.specification_version = 2 if s.respond_to? :specification_version=
31
+ if s.respond_to? :required_rubygems_version=
32
+ s.required_rubygems_version = Gem::Requirement.new('>= 0')
33
+ end
34
+ s.rubygems_version = '2.2.2'
35
+ s.required_ruby_version = '>= 1.9.3'
36
+ s.name = 'xcop'
37
+ s.version = Xcop::VERSION
38
+ s.license = 'MIT'
39
+ s.summary = 'XML Formatting Static Validator'
40
+ s.description = 'Validates XML-like documents for proper formatting'
41
+ s.authors = ['Yegor Bugayenko']
42
+ s.email = 'yegor256@gmail.com'
43
+ s.homepage = 'http://github.com/yegor256/xcop'
44
+ s.files = `git ls-files`.split($RS)
45
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
46
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
47
+ s.rdoc_options = ['--charset=UTF-8']
48
+ s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
49
+ s.add_runtime_dependency 'nokogiri', '~>1.7'
50
+ s.add_runtime_dependency 'differ', '~>0.1.2'
51
+ s.add_runtime_dependency 'slop', '~>4.4'
52
+ s.add_development_dependency 'rake', '12.0.0'
53
+ s.add_development_dependency 'codecov', '0.1.10'
54
+ s.add_development_dependency 'rdoc', '4.2.0'
55
+ s.add_development_dependency 'cucumber', '1.3.17'
56
+ s.add_development_dependency 'minitest', '5.5.0'
57
+ s.add_development_dependency 'rubocop', '0.41.2'
58
+ s.add_development_dependency 'rubocop-rspec', '1.5.1'
59
+ s.add_development_dependency 'rspec-rails', '3.1.0'
60
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcop
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Yegor Bugayenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: differ
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: slop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 12.0.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 12.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: codecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.10
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.10
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 4.2.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 4.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: cucumber
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.17
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.17
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 5.5.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 5.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.41.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.41.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.5.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.5.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-rails
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 3.1.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 3.1.0
167
+ description: Validates XML-like documents for proper formatting
168
+ email: yegor256@gmail.com
169
+ executables:
170
+ - xcop
171
+ extensions: []
172
+ extra_rdoc_files:
173
+ - README.md
174
+ - LICENSE.txt
175
+ files:
176
+ - ".0pdd.yml"
177
+ - ".gitattributes"
178
+ - ".gitignore"
179
+ - ".pdd"
180
+ - ".rubocop.yml"
181
+ - ".rultor.yml"
182
+ - ".simplecov"
183
+ - ".travis.yml"
184
+ - Gemfile
185
+ - LICENSE.txt
186
+ - README.md
187
+ - Rakefile
188
+ - appveyor.yml
189
+ - bin/xcop
190
+ - cucumber.yml
191
+ - features/cli.feature
192
+ - features/gem_package.feature
193
+ - features/step_definitions/steps.rb
194
+ - features/support/env.rb
195
+ - lib/xcop.rb
196
+ - lib/xcop/version.rb
197
+ - test/test__helper.rb
198
+ - test/test_xcop.rb
199
+ - xcop.gemspec
200
+ homepage: http://github.com/yegor256/xcop
201
+ licenses:
202
+ - MIT
203
+ metadata: {}
204
+ post_install_message:
205
+ rdoc_options:
206
+ - "--charset=UTF-8"
207
+ require_paths:
208
+ - lib
209
+ required_ruby_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: 1.9.3
214
+ required_rubygems_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ requirements: []
220
+ rubyforge_project:
221
+ rubygems_version: 2.6.8
222
+ signing_key:
223
+ specification_version: 2
224
+ summary: XML Formatting Static Validator
225
+ test_files:
226
+ - features/cli.feature
227
+ - features/gem_package.feature
228
+ - features/step_definitions/steps.rb
229
+ - features/support/env.rb
230
+ - test/test__helper.rb
231
+ - test/test_xcop.rb