[SCM] ci-tooling packaging branch, master, updated. 5c7d8677795e94cc09523692d41a7a7bb442f044
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Wed Apr 8 15:36:48 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=1d5bcbd
The following commit has been merged in the master branch:
commit 1d5bcbd1303189e4f6a7e8dad4a035c8b5e693c9
Author: Harald Sitter <sitter at kde.org>
Date: Wed Apr 8 17:35:38 2015 +0200
fancy new classes for linting
this ought to become a lintin framework we can use to verify all sorts of
nonesense and replace the pile of hackish code that makes up half the
builder.rb in kci
- lint::result
a result collection of errors, warnings and informations. presently these
are string primitives but they might eventually become a Problem object
instead where each type of issues derives from Problem and supplies
additional information (akin to lintian's verbosity information etc.)
- lint::resultlogger
very very very dumb thing to print results to stdout, this is nothing
more than a glorified puts but is eventually going to act as a transition
bridge for builder
- lint::control
actual first linter checking control file to make sure it has vcs entries
this currently doesn't make attempts to check if the entries actually
look correct considering the origins we use
---
lib/lint/control.rb | 38 ++++++++++++++++++++++++++++++++++++++
lib/lint/result.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++
test/test_lint_control.rb | 42 ++++++++++++++++++++++++++++++++++++++++++
test/test_lint_result.rb | 25 +++++++++++++++++++++++++
4 files changed, 150 insertions(+)
diff --git a/lib/lint/control.rb b/lib/lint/control.rb
new file mode 100644
index 0000000..fbfd73a
--- /dev/null
+++ b/lib/lint/control.rb
@@ -0,0 +1,38 @@
+require_relative '../debian/control'
+require_relative 'result'
+
+module Lint
+ # Lints a debian control file
+ class Control
+ attr_reader :package_directory
+
+ def initialize(package_directory = Dir.pwd)
+ @package_directory = package_directory
+ end
+
+ # @return [Result]
+ def lint
+ result = Result.new
+ Dir.chdir(@package_directory) do
+ control = DebianControl.new
+ control.parse!
+ result.valid = !control.source.nil?
+ return result unless result.valid
+ result = lint_vcs(result, control)
+ end
+ result
+ end
+
+ private
+
+ def lint_vcs(result, control)
+ unless control.source['Vcs-Browser']
+ result.warnings << 'No Vcs-Browser field in control.'
+ end
+ unless control.source['Vcs-Git'] || control.source['Vcs-Bzr']
+ result.warnings << 'No Vcs-Git or Vcs-Bzr field in contorl.'
+ end
+ result
+ end
+ end
+end
diff --git a/lib/lint/result.rb b/lib/lint/result.rb
new file mode 100644
index 0000000..703e9b5
--- /dev/null
+++ b/lib/lint/result.rb
@@ -0,0 +1,45 @@
+module Lint
+ # A lint result expressing its
+ class Result
+ attr_accessor :valid
+ attr_accessor :errors
+ attr_accessor :warnings
+ attr_accessor :informations
+
+ def initialize
+ @valid = false
+ @errors = []
+ @warnings = []
+ @informations = []
+ end
+ end
+
+ # Logs arary of results to stdout
+ class ResultLogger
+ attr_accessor :results
+
+ # @param results [Result, Array<Result>] results to log
+ def initialize(results)
+ @results = ([*results] || [])
+ end
+
+ def log
+ @results.each do |result|
+ next unless result.valid
+ result.errors.each { |s| puts_kci('E', s) }
+ result.warnings.each { |s| puts_kci('W', s) }
+ result.informations.each { |s| puts_kci('I', s) }
+ end
+ end
+
+ private
+
+ def puts_kci(type, str)
+ self.class.puts_kci(type, str)
+ end
+
+ def self.puts_kci(type, str)
+ puts "KCI-#{type} :: #{str}"
+ end
+ end
+end
diff --git a/test/test_lint_control.rb b/test/test_lint_control.rb
new file mode 100644
index 0000000..04505f4
--- /dev/null
+++ b/test/test_lint_control.rb
@@ -0,0 +1,42 @@
+require_relative '../lib/lint/control'
+require_relative 'lib/testcase'
+
+# Test lint control
+class LintControlTest < TestCase
+ def test_init
+ c = Lint::Control.new
+ assert_equal(Dir.pwd, c.package_directory)
+ c = Lint::Control.new('/tmp')
+ assert_equal('/tmp', c.package_directory)
+ end
+
+ def test_invalid
+ r = Lint::Control.new(data).lint
+ assert(!r.valid)
+ end
+
+ def test_vcs
+ r = Lint::Control.new(data).lint
+ assert(r.valid)
+ assert(r.errors.empty?)
+ assert(r.warnings.empty?)
+ assert(r.informations.empty?)
+ end
+
+ def test_vcs_missing
+ r = Lint::Control.new(data).lint
+ assert(r.valid)
+ assert(r.errors.empty?)
+ # vcs-browser missing
+ # vcs-git missing
+ assert_equal(2, r.warnings.size)
+ assert(r.informations.empty?)
+ end
+
+ def test_vcs_partially_missing
+ r = Lint::Control.new(data).lint
+ assert(r.valid)
+ # only vcs-git missing
+ assert_equal(1, r.warnings.size)
+ end
+end
diff --git a/test/test_lint_result.rb b/test/test_lint_result.rb
new file mode 100644
index 0000000..b6f3989
--- /dev/null
+++ b/test/test_lint_result.rb
@@ -0,0 +1,25 @@
+require_relative '../lib/lint/result'
+require_relative 'lib/testcase'
+
+# Test lint result
+class LintResultTest < TestCase
+ # Things other than logger are tested implicitly through higher level test.
+ def test_logger_init
+ r = Lint::ResultLogger.new(nil)
+ assert(r.results.empty?)
+ end
+
+ def test_logger
+ r = Lint::Result.new
+ r.valid = true
+ r.errors << 'error'
+ r.warnings << 'warning'
+ r.informations << 'info'
+
+ l = Lint::ResultLogger.new(r)
+ assert(l.results.is_a?(Array))
+ assert_equal(1, l.results.size)
+ assert_equal(r, l.results.first)
+ l.log
+ end
+end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list