[SCM] ci-tooling packaging branch, master, updated. 1b9740bbc8e898a9a05e305293fea2159d6a982e
Harald Sitter
apachelogger-guest at moszumanska.debian.org
Fri Mar 13 15:19:39 UTC 2015
Gitweb-URL: http://git.debian.org/?p=pkg-kde/ci-tooling.git;a=commitdiff;h=1b9740b
The following commit has been merged in the master branch:
commit 1b9740bbc8e898a9a05e305293fea2159d6a982e
Author: Harald Sitter <sitter at kde.org>
Date: Fri Mar 13 12:19:11 2015 +0100
introduce an initial source parser
this starts putting things into a Debian module for structure reasons
currently only parses format
---
lib/debian/source.rb | 44 ++++++++++++++++++++
test/test_debian_source.rb | 101 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+)
diff --git a/lib/debian/source.rb b/lib/debian/source.rb
new file mode 100644
index 0000000..2720aa0
--- /dev/null
+++ b/lib/debian/source.rb
@@ -0,0 +1,44 @@
+module Debian
+ class Source
+ class Format
+ attr_reader :version
+ attr_reader :type
+
+ def initialize(str)
+ @version = '1'
+ @type = nil
+ parse(str) if str
+ end
+
+ def to_s
+ return @version unless type
+ "#{version} (#{type})"
+ end
+
+ private
+
+ def parse(str)
+ str = str.read if str.respond_to?(:read)
+ str = File.read(str) if File.exist?(str)
+ data = str.strip
+ match = data.match(/(?<version>[^\s]+)(\s+\((?<type>.*)\))?/)
+ @version = match[:version]
+ @type = match[:type]
+ end
+ end
+
+ attr_reader :format
+
+ def initialize(package_path)
+ @package_path = package_path
+ fail 'not a package path' unless Dir.exist?("#{package_path}/debian")
+ parse
+ end
+
+ private
+
+ def parse
+ @format = Format.new("#{@package_path}/debian/source/format")
+ end
+ end
+end
diff --git a/test/test_debian_source.rb b/test/test_debian_source.rb
new file mode 100644
index 0000000..2ef0cc0
--- /dev/null
+++ b/test/test_debian_source.rb
@@ -0,0 +1,101 @@
+require 'fileutils'
+require 'test/unit'
+require 'tmpdir'
+
+require_relative '../lib/debian/source'
+
+# Test debian/source/format
+class DebianSourceFormatTest < Test::Unit::TestCase
+ self.test_order = :defined
+
+ def test_init_str
+ assert_nothing_raised do
+ Debian::Source::Format.new('1.0')
+ end
+ end
+
+ def test_init_file
+ Dir.mktmpdir(self.class.to_s) do |t|
+ Dir.chdir(t) do
+ file = 'debian/source/format'
+ FileUtils.mkpath('debian/source')
+ File.write(file, "1.0
")
+
+ # Read from a file path
+ format = nil
+ assert_nothing_raised do
+ format = Debian::Source::Format.new(file)
+ end
+ assert_equal('1.0', format.version)
+
+ # Read from a file object.
+ format = nil
+ assert_nothing_raised do
+ format = Debian::Source::Format.new(File.open(file))
+ end
+ assert_equal('1.0', format.version)
+ end
+ end
+ end
+
+ def test_1
+ format = Debian::Source::Format.new('1.0')
+ assert_equal('1.0', format.version)
+ assert_equal(nil, format.type)
+ end
+
+ def test_1_to_s
+ str = '1.0'
+ format = Debian::Source::Format.new(str)
+ assert_equal(str, format.to_s)
+ end
+
+ def test_3_native
+ format = Debian::Source::Format.new('3.0 (native)')
+ assert_equal('3.0', format.version)
+ assert_equal('native', format.type)
+ end
+
+ def test_3_quilt
+ format = Debian::Source::Format.new('3.0 (quilt)')
+ assert_equal('3.0', format.version)
+ assert_equal('quilt', format.type)
+ end
+
+ def test_3_to_s
+ str = '3.0 (quilt)'
+ format = Debian::Source::Format.new(str)
+ assert_equal(str, format.to_s)
+ end
+
+ def test_nil_init
+ format = Debian::Source::Format.new(nil)
+ assert_equal('1', format.version)
+ assert_equal(nil, format.type)
+ end
+end
+
+# Test debian/source
+class DebianSourceTest < Test::Unit::TestCase
+ def setup
+ @tmpdir = Dir.mktmpdir(self.class.to_s)
+ Dir.chdir(@tmpdir)
+ end
+
+ def teardown
+ Dir.chdir('/')
+ FileUtils.rm_rf(@tmpdir)
+ end
+
+ def test_init
+ file = 'debian/source/format'
+ FileUtils.mkpath('debian/source')
+ File.write(file, "1.0
")
+
+ source = nil
+ assert_nothing_raised do
+ source = Debian::Source.new(Dir.pwd)
+ end
+ assert_not_nil(source.format)
+ end
+end
--
ci-tooling packaging
More information about the pkg-kde-commits
mailing list