diff --git a/test/documentation_test.rb b/test/documentation_test.rb index 83be063..805cccd 100644 --- a/test/documentation_test.rb +++ b/test/documentation_test.rb @@ -1,214 +1,214 @@ #-- # Copyright (C) 2014-2017 Harald Sitter # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #++ require 'fileutils' require_relative 'lib/testme' require_relative '../lib/releaseme/documentation.rb' # FIXME: test stable branch class TestDocumentation < Testme def setup # FIXME: code copy with l10n @repo_data_dir = data('l10nrepo/') @i18n_path = 'extragear-multimedia' @trunk_url = 'trunk/l10n-kf5/' @stable_url = 'branches/stable/l10n-kf5' @dir = 'tmp_l10n_' + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join @svn_template_dir = 'tmp_l10n_repo_' + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join @svn_checkout_dir = 'tmp_l10n_check_' + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join system("svnadmin create #{@svn_template_dir}", [:out] => File::NULL) assert_path_exist(@svn_template_dir) - system("svn co file://#{Dir.pwd}/#{@svn_template_dir} #{@svn_checkout_dir}", + system("svn co file:///#{Dir.pwd}/#{@svn_template_dir} #{@svn_checkout_dir}", [:out] => File::NULL) FileUtils.cp_r("#{@repo_data_dir}/trunk", @svn_checkout_dir) FileUtils.cp_r("#{@repo_data_dir}/branches", @svn_checkout_dir) system('svn add *', chdir: @svn_checkout_dir, [:out] => File::NULL) system("svn ci -m 'yolo'", chdir: @svn_checkout_dir, [:out] => File::NULL) ReleaseMe::DocumentationL10n.languages = nil end def teardown FileUtils.rm_rf(@svn_template_dir) FileUtils.rm_rf(@svn_checkout_dir) FileUtils.rm_rf(@dir) end # TODO: attributes of documentation are not tested.... def create_doc ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, 'amarok', @i18n_path) end def create_doc_without_translation ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, 'frenchfries', 'frenchfries') end def test_no_doc # no doc present d = ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, 'frenchfries', @i18n_path) - d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + d.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('variable-pot'), @dir) d.get(@dir) assert_path_exist("#{@dir}/Messages.sh") refute_path_exist("#{@dir}/doc") assert_equal([], Dir.glob("#{@dir}/po/*/docs")) refute_path_exist('CMakeLists.txt') end def test_get_doc # en & de d = create_doc - d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + d.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) d.get(@dir) Dir.chdir(@dir) do assert_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') docs = Dir.glob('po/*/docs/*') assert_includes(docs, 'po/fr/docs/amarok') assert_includes(docs, 'po/de/docs/amarok') assert_equal(2, docs.size) # en tree is ok assert_path_exist('doc/index.docbook') # FIXME: should we require a cmakelists? end end def test_get_doc_without_l10n # en only (everything works if only doc/ is present in git but not # translated) d = create_doc_without_translation - d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + d.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) d.get(@dir) Dir.chdir(@dir) do refute_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') assert_empty(Dir.glob('po/*/docs/*')) assert_path_exist('doc/CMakeLists.txt') assert_path_exist('doc/index.docbook') end end def test_get_doc_multi_doc d = ReleaseMe::DocumentationL10n.new(ReleaseMe::DocumentationL10n::TRUNK, 'plasma-desktop', 'kde-workspace') - d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + d.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-doc'), @dir) d.get(@dir) # fr mustn't appear, it's empty expected_files = %w[ CMakeLists.txt doc doc/CMakeLists.txt doc/doc-valid2 doc/doc-valid2/CMakeLists.txt doc/doc-valid2/index.docbook doc/doc-valid2/doc-valid2.1 doc/doc-valid2/doc-valid2.1/CMakeLists.txt doc/doc-valid2/doc-valid2.1/index.docbook doc/doc-valid2/doc-valid2.1/doc-valid2.1.1 doc/doc-valid2/doc-valid2.1/doc-valid2.1.1/CMakeLists.txt doc/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook doc/doc-invalid1 doc/doc-valid1 doc/doc-valid1/CMakeLists.txt doc/doc-valid1/index.docbook po po/de po/de/docs po/de/docs/doc-valid2 po/de/docs/doc-valid2/index.docbook po/de/docs/doc-valid2/doc-valid2.1 po/de/docs/doc-valid2/doc-valid2.1/index.docbook po/de/docs/doc-valid2/doc-valid2.1/doc-valid2.1.1 po/de/docs/doc-valid2/doc-valid2.1/doc-valid2.1.1/index.docbook po/de/docs/doc-valid1 po/de/docs/doc-valid1/index.docbook ] present_files = Dir.chdir(@dir) { Dir.glob('**/**') } missing_files = [] expected_files.each do |f| missing_files << f unless present_files.include?(f) present_files.delete(f) end assert(missing_files.empty?, "missing file(s): #{missing_files}") assert(present_files.empty?, "unexpected file(s): #{present_files}") Dir.chdir(@dir) do assert_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') end end def test_man d = create_doc - d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + d.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('source-with-manpage'), @dir) d.get(@dir) Dir.chdir(@dir) do assert_includes(File.read('CMakeLists.txt'), 'kdoctools_install(po)') # NOTE: Our manpage line up is different from applications releases. # We pack them into their original subdir whereas the other script # packs them into the main dir. The reason is that we use the same code # paths as for documentation which makes it cheaper for us to preserver # the dir. docs = Dir.glob('po/*/docs/**/*.docbook') assert_includes(docs, 'po/de/docs/amarok/man-amarok.1.docbook') assert_includes(docs, 'po/de/docs/amarok/unicorn/man-unicorn.1.docbook') assert_equal(2, docs.size) end end def test_doc_excess_spacing # CMakeLists contains lots of excess spacing, regex should handle this and # be able to retrieve the l10n. d = create_doc - d.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + d.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('excess-spacing-doc'), @dir) d.get(@dir) Dir.chdir(@dir) do docs = Dir.glob('po/*/docs/*') assert_includes(docs, 'po/fr/docs/amarok') assert_includes(docs, 'po/de/docs/amarok') assert_equal(2, docs.size) end end end diff --git a/test/l10n_test.rb b/test/l10n_test.rb index 87a1357..efe8ff1 100644 --- a/test/l10n_test.rb +++ b/test/l10n_test.rb @@ -1,382 +1,382 @@ #-- # Copyright (C) 2015-2017 Harald Sitter # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #++ require 'fileutils' require_relative 'lib/testme' require_relative '../lib/releaseme/l10n.rb' require_relative '../lib/releaseme/l10nstatistics.rb' require_relative '../lib/releaseme/documentation.rb' # FIXME: test stable class TestL10n < Testme def setup @repo_data_dir = data('l10nrepo/') @i18n_path = 'extragear-multimedia' @trunk_url = 'trunk/l10n-kf5/' @stable_url = 'branches/stable/l10n-kf5' @dir = 'tmp_l10n' @svn_template_dir = 'tmp_l10n_repo' @svn_checkout_dir = 'tmp_l10n_check' `svnadmin create #{@svn_template_dir}` assert_path_exist(@svn_template_dir) - `svn co file://#{Dir.pwd}/#{@svn_template_dir} #{@svn_checkout_dir}` + `svn co file:///#{Dir.pwd}/#{@svn_template_dir} #{@svn_checkout_dir}` FileUtils.cp_r("#{@repo_data_dir}/trunk", @svn_checkout_dir) FileUtils.cp_r("#{@repo_data_dir}/branches", @svn_checkout_dir) Dir.chdir(@svn_checkout_dir) do `svn add *` `svn ci -m 'yolo'` end ReleaseMe::L10n.languages = nil end def teardown FileUtils.rm_rf(@svn_template_dir) FileUtils.rm_rf(@svn_checkout_dir) FileUtils.rm_rf(@dir) end def create_l10n(name = 'amarok', i18n_path = @i18n_path, origin: ReleaseMe::L10n::TRUNK) l = ReleaseMe::L10n.new(origin, name, i18n_path) l.target = "#{@dir}/l10n" l end def test_find_templates l = create_l10n templates = l.send(:find_templates, data('multi-pot'), skip_dir: nil) assert_equal(templates.count, 2) templates = l.send(:find_templates, data('single-pot'), skip_dir: nil) assert_equal(templates.count, 1) end def test_get_po # For visual string consinstency we actually interpolate pointlessly below. # rubocop:disable Style/UnneededInterpolation l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) l.get(@dir) assert_path_exist("#{@dir}") assert_path_exist("#{@dir}/CMakeLists.txt") refute_path_exist("#{@dir}/l10n") # temp dir must not be there assert_path_exist("#{@dir}/po") assert_path_exist("#{@dir}/po/de/amarok.po") refute_path_exist("#{@dir}/poqm") # qt translation dir must not be there FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot'), @dir) l.get(@dir) assert_path_exist("#{@dir}") assert_path_exist("#{@dir}/CMakeLists.txt") refute_path_exist("#{@dir}/l10n") # temp dir must not be there assert_path_exist("#{@dir}/po") assert_path_exist("#{@dir}/po/de/amarok.po") assert_path_exist("#{@dir}/po/de/amarokcollectionscanner.po") end def test_get_po_elsewhere l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") @elsewhere = "#{Dir.pwd}/elsewhere_tmp_l10n" FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) l.get(@dir, @elsewhere, edit_cmake: false) assert_path_exist("#{@elsewhere}/de/amarok.po") end def test_get_po_absolute_srcdir # Make sure we can pass an absolute dir as srcdir param. l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) l.get(File.absolute_path(@dir)) assert_path_exist("#{@dir}/po/de/amarok.po") end def test_get_po_edit_cmake l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) l.get(@dir, edit_cmake: true) assert_path_exist("#{@dir}/CMakeLists.txt") assert_includes(File.read("#{@dir}/CMakeLists.txt"), 'ki18n_install(po)') end def test_get_po_no_edit_cmake l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('single-pot'), @dir) l.get(@dir, edit_cmake: false) assert_path_exist("#{@dir}/CMakeLists.txt") refute_includes(File.read("#{@dir}/CMakeLists.txt"), 'ki18n_install(po)') end def test_statistics l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot'), @dir) l.get(@dir) statistics = ReleaseMe::L10nStatistics.new statistics.gather!("#{@dir}/po") assert_equal({"de"=>{:all=>4, :shown=>3, :notshown=>1, :percentage=>75.0}, "fr"=>{:all=>4, :shown=>4, :notshown=>0, :percentage=>100.0}}, statistics.stats) end def test_variable_potname l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('variable-pot'), @dir) assert_raises RuntimeError do l.get(@dir) end end def test_space_and_declared_multi_pot l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('space-and-declared-multi-pot'), @dir) l.get(@dir) assert_path_exist("#{@dir}/po/de/amarok.po") assert_path_exist("#{@dir}/po/de/amarokcollectionscanner.po") end def test_find_templates_bogus l = create_l10n templates = l.send(:find_templates, data('bogus-pot'), skip_dir: nil) assert_equal(templates, []) end def test_diff_output_some_not_found_all_not_found # When no translations were found we expect different output versus when # only some were not found. l = create_l10n - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot'), @dir) l.get(@dir) ENV.delete('RELEASEME_SHUTUP') # Reset by testme setup some_missing_stdout = StringIO.open do |io| $stdout = io l.instance_variable_set(:@__logger, nil) # Reset l.send(:print_missing_languages, [l.languages.pop]) io.string.strip end all_missing_stdout = StringIO.open do |io| $stdout = io l.instance_variable_set(:@__logger, nil) # Reset l.send(:print_missing_languages, l.languages) io.string.strip end $stdout = STDOUT refute_empty(some_missing_stdout) refute_empty(all_missing_stdout) refute_equal(some_missing_stdout, all_missing_stdout) ensure $stdout = STDOUT end def test_script # https://techbase.kde.org/Localization/Concepts/Transcript l = create_l10n('ki18n', 'frameworks') - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot-script'), @dir) l.get(@dir) assert_path_exist("#{@dir}/po/sr/scripts") assert_path_exist("#{@dir}/po/sr/scripts/ki18n5") assert_path_exist("#{@dir}/po/sr/scripts/libplasma5") refute_path_exist("#{@dir}/po/sr/scripts/proto") assert_path_exist("#{@dir}/po/sr/scripts/ki18n5/ki18n5.js") assert_path_exist("#{@dir}/po/sr/scripts/ki18n5/trapnakron.pmap") assert_path_exist("#{@dir}/po/sr/scripts/libplasma5/libplasma5.js") assert_path_exist("#{@dir}/po/sr/scripts/libplasma5/plasmoid.js") end def test_pot_detection_without_releaseme # Do not find templates in the releaseme directory itself. # If releaseme was cloned into a source directory (or submoduled') # we'd otherwise trip over test fixtures. # One such fixture is: assert_path_exist("#{__dir__}/data/variable-pot/Messages.sh") l = ReleaseMe::L10n.new(ReleaseMe::L10n::TRUNK, 'ki18n', 'frameworks') # Make sure this doesn't raise anything. pos = l.send(:find_templates, __dir__) assert_empty(pos) end def test_releaseme_dir # This is a bit of a silly test. It is meant as an additional safeguard # against breaking relative path resolution. RELEASEME_DIR is meant # to be resolved to the main releaseme directory. The idea here is that # it's less likely both the test AND the lib get moved, so we'd get a # failing teset if any of the two move. # If you have come here because you moved the lib and get a failure: # Make sure RELEASEME_DIR still resolves to the main releasme dir! # If you have come here because you moved the test and get a failure: # Simply adjust the assertion to match reality. assert_equal(File.absolute_path(__dir__), ReleaseMe::L10n::RELEASEME_TEST_DIR) end def test_data # https://techbase.kde.org/Localization/Concepts/Non_Text_Resources # Data assets actually have no identifying quality, translators are expected # to manually pick them out of the source VCS and put them into their l10n # tree without breaking anything. As such we need no source tree for the # test at all. l = create_l10n('ktuberling', 'kdegames') - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") Dir.mkdir(@dir) File.write("#{@dir}/CMakeLists.txt", '') l.get(@dir) assert_path_exist("#{@dir}/po") assert_path_exist("#{@dir}/po/CMakeLists.txt") assert_path_exist("#{@dir}/po/de/data/ktuberling/CMakeLists.txt") assert_path_exist("#{@dir}/po/de/data/ktuberling/foo.fake.ogg") assert_path_exist("#{@dir}/po/de/data/ktuberling/bar.fake.ogg") assert_path_exist("#{@dir}/po/sr/data/ktuberling/CMakeLists.txt") assert_path_exist("#{@dir}/po/sr/data/ktuberling/foo.fake.ogg") assert_path_exist("#{@dir}/po/sr/data/ktuberling/bar.fake.ogg") # SR is a special snow flake, it needs cmake modules, the other 100 # languages magically don't. # For testing reasons there's also one in our de directory to make sure # things wouldn't break with >1. assert_path_exist("#{@dir}/po/cmake_modules/deDataMacros.cmake") assert_path_exist("#{@dir}/po/cmake_modules/srDataMacros.cmake") # Make sure the CMakeLists properly adds our asset dir. assert(File.read("#{@dir}/po/CMakeLists.txt").include?('add_subdirectory(de/data/ktuberling)')) assert(File.read("#{@dir}/CMakeLists.txt").include?('ecm_optional_add_subdirectory(po)')) end def test_multi_pot_kde4 # In KDE4 you could have foo_qt.po to mean anything. In KF5 based code this # explicitly means that this is a qt translation compiled to qm. # We'll assert that KDE4 origins are treated as previously expected, the new # behavior is checked elsewhere. l = create_l10n(origin: ReleaseMe::Origin::TRUNK_KDE4) - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot-kde4'), @dir) l.get(@dir) assert_path_exist("#{@dir}") assert_path_exist("#{@dir}/CMakeLists.txt") refute_path_exist("#{@dir}/l10n") # temp dir must not be there assert_path_exist("#{@dir}/po") assert_path_exist("#{@dir}/po/de/amarok.po") assert(File.exist?("#{@dir}/po/de/amarokcollectionscanner_qt.po")) refute(File.read("#{@dir}/CMakeLists.txt").include?('ecm_install_po_files_as_qm')) end def test_poqm # Qt strings get put into a foo_qt.po, they are meant to get installed via # ecm_install_po_files_as_qm from ECM. l = create_l10n('step', 'kdeedu') - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot-qt'), @dir) l.get(@dir) assert_path_exist("#{@dir}/poqm") assert_path_exist("#{@dir}/po/de/step.po") assert_path_exist("#{@dir}/poqm/de/step_qt.po") assert(File.read("#{@dir}/CMakeLists.txt").include?('ki18n_install(po)')) assert(File.read("#{@dir}/CMakeLists.txt").include?('ecm_install_po_files_as_qm(poqm)')) end def test_poqm_frameworks_movery # In frameworks po/ is used in place of poqm/ when a source uses Qt # translations exclusively. I couldn't actually find an example of # frameworks using both, but I'd like to think that it would be consistent # with how applications handle it: po/ and poqm/. l = create_l10n('solid', 'frameworks') - l.init_repo_url("file://#{Dir.pwd}/#{@svn_template_dir}") + l.init_repo_url("file:///#{Dir.pwd}/#{@svn_template_dir}") FileUtils.rm_rf(@dir) FileUtils.cp_r(data('multi-pot-qt-frameworks'), @dir) l.get(@dir) assert_path_exist("#{@dir}/po") assert_path_exist("#{@dir}/po/de/solid_qt.po") refute_path_exist("#{@dir}/poqm") assert(File.read("#{@dir}/CMakeLists.txt").include?('ecm_install_po_files_as_qm(po)')) assert(!File.read("#{@dir}/CMakeLists.txt").include?('ecm_install_po_files_as_qm(poqm)')) end end diff --git a/test/svn_test.rb b/test/svn_test.rb index 3f966cd..e303816 100644 --- a/test/svn_test.rb +++ b/test/svn_test.rb @@ -1,164 +1,164 @@ #-- # Copyright (C) 2014-2015 Harald Sitter # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License or (at your option) version 3 or any later version # accepted by the membership of KDE e.V. (or its successor approved # by the membership of KDE e.V.), which shall act as a proxy # defined in Section 14 of version 3 of the license. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . #++ require 'fileutils' require_relative 'lib/testme' require_relative '../lib/releaseme/svn' class TestSvn < Testme def setup @svn_checkout_dir = "#{Dir.pwd}/tmp_check_" + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join @svn_repo_dir = "#{Dir.pwd}/tmp_repo_" + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join system("svnadmin create #{@svn_repo_dir}", [:out] => File::NULL) || raise assert_path_exist(@svn_repo_dir) end def teardown FileUtils.rm_rf(@svn_repo_dir) FileUtils.rm_rf(@svn_checkout_dir) end def populate_repo - `svn co file://#{@svn_repo_dir} #{@svn_checkout_dir}` + `svn co file:///#{@svn_repo_dir} #{@svn_checkout_dir}` `echo "yolo" > #{@svn_checkout_dir}/foo` Dir.mkdir("#{@svn_checkout_dir}/dir") `echo "oloy" > #{@svn_checkout_dir}/dir/file` Dir.chdir(@svn_checkout_dir) `svn add *` `svn ci -m 'I am a troll'` Dir.chdir('..') end def new_valid_repo s = ReleaseMe::Svn.new - s.repository = "file://#{@svn_repo_dir}" + s.repository = "file:///#{@svn_repo_dir}" s end def test_cat populate_repo s = new_valid_repo # Valid file. ret = s.cat('/foo') assert_equal(0, $?.to_i) assert_equal("yolo\n", ret) # Invalid file. ret = s.cat('/bar') refute_equal(0, $?.to_i) assert_equal('', ret) end def test_exists populate_repo s = new_valid_repo # Valid file. ret = s.exist?('/foo') assert_equal(ret, true) # Invalid file. ret = s.exist?('/bar') assert_equal(ret, false) end def test_list populate_repo s = new_valid_repo # Valid path. ret = s.list assert_equal(ret, "dir/\nfoo\n") # Invalid path. ret = s.list('/invalid') assert_equal(ret, '') # Valid path other than / ret = s.list('/dir') assert_equal(ret, "file\n") end def test_export tmpDir = Dir.pwd + "/tmp_svn_export_" + (0...16).map{ ('a'..'z').to_a[rand(26)] }.join Dir.mkdir(tmpDir) populate_repo s = new_valid_repo # Valid target and path ret = s.export("#{tmpDir}/file", '/dir/file') assert_equal(ret, true) assert_path_exist("#{tmpDir}/file") # Target dir does not exist ret = s.export("#{tmpDir}123/file", '/dir/file') assert_equal(ret, false) refute_path_exist("#{tmpDir}123/file") # Invalid path ret = s.export("#{tmpDir}/file", '/dir/otherfile') assert_equal(ret, false) refute_path_exist("#{tmpDir}/otherfile") ensure FileUtils.rm_rf(tmpDir) end def test_get_repo_valid s = ReleaseMe::Svn.new - s.repository = "file://#{@svn_repo_dir}" + s.repository = "file:///#{@svn_repo_dir}" ret = s.get(@svn_checkout_dir) assert_equal(true, ret) assert_path_exist(@svn_checkout_dir) FileUtils.rm_rf(@svn_checkout_dir) end def test_get_repo_invalid s = ReleaseMe::Svn.new s.repository = 'file://foofooofoo' s.get(@svn_checkout_dir) refute_path_exist(@svn_checkout_dir) FileUtils.rm_rf(@svn_checkout_dir) end def test_clean populate_repo s = new_valid_repo s.get(@svn_checkout_dir) s.clean!(@svn_checkout_dir) refute_path_exist("#{@svn_checkout_dir}/.svn") refute_path_exist("#{@svn_checkout_dir}/dir/.svn") end def test_from_hash s = ReleaseMe::Svn.from_hash(repository: 'kitten') refute_nil(s) assert_equal('kitten', s.repository) end def test_to_s s = ReleaseMe::Svn.from_hash(repository: 'kitten') assert_equal('(svn - kitten)', s.to_s) end end