3 # SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org>
5 # SPDX-License-Identifier: GPL-2.0-or-later
7 require_relative
'test_helper'
11 class ServiceMenuDeinstallationTest
< Test
::Unit::TestCase
13 @tmpdir = Dir
.mktmpdir("dolphintest-#{self.class.to_s.tr(':', '_')}")
17 ENV['XDG_DATA_HOME'] = File
.join(@tmpdir, 'data')
22 FileUtils
.rm_rf(@tmpdir)
24 ENV.delete('XDG_DATA_HOME')
27 def test_run_deinstall
28 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
29 archive_base
= "#{service_dir}/foo.zip"
30 archive_dir
= "#{archive_base}-dir/foo-1.1/"
31 FileUtils
.mkpath(archive_dir
)
32 File
.write("#{archive_dir}/deinstall.sh", <<-DEINSTALL_SH)
36 touch #{@tmpdir}/deinstall.sh-run
38 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
42 touch #{@tmpdir}/install.sh-run
45 assert(system('servicemenuinstaller', 'uninstall', archive_base
))
47 # deinstaller should be run
48 # installer should not be run
49 # archive_dir should have been correctly removed
51 assert_path_exist('deinstall.sh-run')
52 assert_path_not_exist('install.sh-run')
53 assert_path_not_exist(archive_dir
)
56 def test_run_install_with_arg
57 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
58 archive_base
= "#{service_dir}/foo.zip"
59 archive_dir
= "#{archive_base}-dir/foo-1.1/"
60 FileUtils
.mkpath(archive_dir
)
62 File
.write("#{archive_dir}/install.sh", <<-INSTALL_SH)
64 if [ "$@" = "--uninstall" ]; then
65 touch #{@tmpdir}/install.sh-run
71 assert(system('servicemenuinstaller', 'uninstall', archive_base
))
73 assert_path_not_exist('deinstall.sh-run')
74 assert_path_exist('install.sh-run')
75 assert_path_not_exist(archive_dir
)
80 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
81 archive_base
= "#{service_dir}/foo.zip"
82 archive_dir
= "#{archive_base}-dir/foo-1.1/"
83 FileUtils
.mkpath(archive_dir
)
85 refute(system('servicemenuinstaller', 'uninstall', archive_base
))
87 # I am unsure if deinstallation really should keep the files around. But
88 # that's how it behaved originally so it's supposedly intentional
90 assert_path_exist(archive_dir
)
93 # For desktop files things are a bit special. There is one in .local/share/servicemenu-download
94 # and another in the actual ServiceMenus dir. The latter gets removed by the
95 # script, the former by KNS.
97 service_dir
= File
.join(Dir
.pwd
, 'share/servicemenu-download')
98 downloaded_file
= "#{service_dir}/foo.desktop"
99 FileUtils
.mkpath(service_dir
)
100 FileUtils
.touch(downloaded_file
)
102 menu_dir
= "#{ENV['XDG_DATA_HOME']}/kservices5/ServiceMenus/"
103 installed_file
= "#{menu_dir}/foo.desktop"
104 FileUtils
.mkpath(menu_dir
)
105 FileUtils
.touch(installed_file
)
107 assert(system('servicemenuinstaller', 'uninstall', downloaded_file
))
109 assert_path_exist(downloaded_file
)
110 assert_path_not_exist(installed_file
)