3 # Copyright (C) 2019 Harald Sitter <sitter@kde.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the
17 # Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 require_relative
'test_helper'
24 class ServiceMenuInstallationTest
< Test
::Unit::TestCase
26 @tmpdir = Dir
.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}")
30 ENV['XDG_DATA_HOME'] = File
.join(@tmpdir, 'data')
35 FileUtils
.rm_rf(@tmpdir)
37 ENV.delete('XDG_DATA_HOME')
41 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
42 FileUtils
.mkpath(service_dir
)
43 archive
= "#{service_dir}/foo.tar"
45 archive_dir
= 'foo' # relative so tar cf is relative without fuzz
46 FileUtils
.mkpath(archive_dir
)
47 File
.write("#{archive_dir}/install-it.sh", <<-INSTALL_IT_SH)
49 touch #{@tmpdir}/install-it.sh-run
51 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
53 touch #{@tmpdir}/install.sh-run
55 assert(system('tar', '-cf', archive
, archive_dir
))
57 assert(covered_system('servicemenuinstallation', archive
))
59 tar_dir
= "#{service_dir}/foo.tar-dir"
60 tar_extract_dir
= "#{service_dir}/foo.tar-dir/foo"
61 assert_path_exist(tar_dir
)
62 assert_path_exist(tar_extract_dir
)
63 assert_path_exist("#{tar_extract_dir}/install-it.sh")
64 assert_path_exist("#{tar_extract_dir}/install.sh")
67 def test_run_install_with_arg
68 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
69 FileUtils
.mkpath(service_dir
)
70 archive
= "#{service_dir}/foo.tar"
72 archive_dir
= 'foo' # relative so tar cf is relative without fuzz
73 FileUtils
.mkpath(archive_dir
)
74 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
76 if [ "$@" = "--install" ]; then
77 touch #{@tmpdir}/install.sh-run
82 assert(system('tar', '-cf', archive
, archive_dir
))
84 assert(covered_system('servicemenuinstallation', archive
))
86 tar_dir
= "#{service_dir}/foo.tar-dir"
87 tar_extract_dir
= "#{service_dir}/foo.tar-dir/foo"
88 assert_path_exist(tar_dir
)
89 assert_path_exist(tar_extract_dir
)
90 assert_path_not_exist("#{tar_extract_dir}/install-it.sh")
91 assert_path_exist("#{tar_extract_dir}/install.sh")
95 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
96 FileUtils
.mkpath(service_dir
)
97 archive
= "#{service_dir}/foo.tar"
99 archive_dir
= 'foo' # relative so tar cf is relative without fuzz
100 FileUtils
.mkpath(archive_dir
)
101 assert(system('tar', '-cf', archive
, archive_dir
))
103 refute(covered_system('servicemenuinstallation', archive
))
107 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
108 downloaded_file
= "#{service_dir}/foo.desktop"
109 FileUtils
.mkpath(service_dir
)
110 FileUtils
.touch(downloaded_file
)
112 menu_dir
= "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/"
113 installed_file
= "#{menu_dir}/foo.desktop"
114 FileUtils
.mkpath(menu_dir
)
115 FileUtils
.touch(installed_file
)
117 assert(covered_system('servicemenuinstallation', downloaded_file
))
119 assert_path_exist(downloaded_file
)
120 assert_path_exist(installed_file
)