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 ServiceMenuDeinstallationTest
< 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')
40 def test_run_deinstall
41 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
42 archive_base
= "#{service_dir}/foo.zip"
43 archive_dir
= "#{archive_base}-dir/foo-1.1/"
44 FileUtils
.mkpath(archive_dir
)
45 File
.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH)
47 touch #{@tmpdir}/deinstall.sh-run
49 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
51 touch #{@tmpdir}/install.sh-run
54 assert(system('servicemenuinstaller', 'uninstall', archive_base
))
56 # deinstaller should be run
57 # installer should not be run
58 # archive_dir should have been correctly removed
60 assert_path_exist('deinstall.sh-run')
61 assert_path_not_exist('install.sh-run')
62 assert_path_not_exist(archive_dir
)
65 def test_run_install_with_arg
66 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
67 archive_base
= "#{service_dir}/foo.zip"
68 archive_dir
= "#{archive_base}-dir/foo-1.1/"
69 FileUtils
.mkpath(archive_dir
)
71 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
73 if [ "$@" = "--uninstall" ]; then
74 touch #{@tmpdir}/install.sh-run
80 assert(system('servicemenuinstaller', 'uninstall', archive_base
))
82 assert_path_not_exist('deinstall.sh-run')
83 assert_path_exist('install.sh-run')
84 assert_path_not_exist(archive_dir
)
89 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
90 archive_base
= "#{service_dir}/foo.zip"
91 archive_dir
= "#{archive_base}-dir/foo-1.1/"
92 FileUtils
.mkpath(archive_dir
)
94 refute(system('servicemenuinstaller', 'uninstall', archive_base
))
96 # I am unsure if deinstallation really should keep the files around. But
97 # that's how it behaved originally so it's supposedly intentional
99 assert_path_exist(archive_dir
)
102 # For desktop files things are a bit special. There is one in .local/share/servicemenu-download
103 # and another in the actual ServiceMenus dir. The latter gets removed by the
104 # script, the former by KNS.
106 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
107 downloaded_file
= "#{service_dir}/foo.desktop"
108 FileUtils
.mkpath(service_dir
)
109 FileUtils
.touch(downloaded_file
)
111 menu_dir
= "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/"
112 installed_file
= "#{menu_dir}/foo.desktop"
113 FileUtils
.mkpath(menu_dir
)
114 FileUtils
.touch(installed_file
)
116 assert(system('servicemenuinstaller', 'uninstall', downloaded_file
))
118 assert_path_exist(downloaded_file
)
119 assert_path_not_exist(installed_file
)