Files
chromebrew/tests/commands/remove.rb
Satadru Pramanik, DO, MPH, MEng 386f42ff6e Fix for require issues with highline and glibc 2.37 refactor (#10363)
* Adjust highline requires.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Refactor glibc_build237.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust cmake logic for cmake_build_relative_dir.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Update buildsystems...

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Rebuild glibc 2.37 packages.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust fixup for case of loading from much older crew.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Try to handle loading fixup on older crew update.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Handle older crew setups.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Use rubocop exclusion for only const.rb and fixup.rb.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Remove attr_accessor from buildsystems.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Force update compatible if coming from an older crew.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* remove require_gem from package.rb

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add fallback for remove.rb

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* const tweaks...

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust const.rb & fixup.rb to remove error messages on load after require.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Make remove run crew update compatible if being run on a newer underlying chromebrew.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust fixup to be more resilient to being loaded in an older crew.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Switch from symbolized json import.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Revert most changes.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust essential deps handling in fixup.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Cleanup save_json in fixup.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* update highline

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* save json more.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* save json more.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* test remove changes

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add more remove debug code.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add more remove debug code.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add debug to fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add debug to fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* add debug to fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Refresh crew json when calling crew functions or exiting fixup.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Refresh crew json when calling crew functions or exiting fixup.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fix json string usage in remove

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* essential package debugging

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* fixup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust remove debugging...

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* more remove debugging

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Remove debugging code from commands/remove.rb

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Remove more debugging code from lib/fixup.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust remove test to test both remove with and without debug argument.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Update const.rb to not set x86 constants when not on x86.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Set x86 constants to nil when not on x86.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Bump crew version.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

---------

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2024-08-31 14:06:18 -05:00

80 lines
2.8 KiB
Ruby

require 'minitest/autorun'
require_relative '../../commands/remove'
require_relative '../../lib/const'
require_relative '../../lib/convenience_functions'
require_relative '../../lib/package_utils'
# Add lib to LOAD_PATH
$LOAD_PATH << File.join(CREW_LIB_PATH, 'lib')
# This is needed to force --no-color mode.
String.use_color = false
class RemoveCommandTest < Minitest::Test
def setup
essential_deps = ConvenienceFunctions.load_symbolized_json[:essential_deps]
@random_essential_package_name = essential_deps[rand(0...(essential_deps.length - 1))]
puts <<~ESSENTIAL_PACKAGE_REMOVAL_TEST_EOF
Testing the removal of essential package #{@random_essential_package_name}, which was picked at random from one the essential packages: #{essential_deps.join(', ')}
(This should fail.)
ESSENTIAL_PACKAGE_REMOVAL_TEST_EOF
@random_essential_pkg = Package.load_package("#{@random_essential_package_name}.rb")
@package_with_essential_file = 'gcc_build'
@essential_file = File.join(CREW_LIB_PREFIX, 'libstdc++.so.6')
puts <<~PACKAGE_WITH_ESSENTIAL_FILE_REMOVAL_TEST_EOF
Testing the removal of package #{@package_with_essential_file}.
(This should succeed, but essential file #{@essential_file}
should not be removed.)
PACKAGE_WITH_ESSENTIAL_FILE_REMOVAL_TEST_EOF
@normal_package_name = 'xxd_standalone'
puts <<~NORMAL_PACKAGE_REMOVAL_TEST_EOF
Testing the removal of normal package #{@normal_package_name}.
(This should succeed.)
NORMAL_PACKAGE_REMOVAL_TEST_EOF
@normal_pkg = Package.load_package("#{@normal_package_name}.rb")
end
def test_remove_essential_package
# expected_output = %( #{@random_essential_package_name.capitalize} is considered an essential package needed for
# Chromebrew to function and thus cannot be removed.
# )
# assert_output(expected_output, nil) do
# Command.remove(@random_essential_pkg, true)
# end
assert_raises(SystemExit) { Command.remove(@random_essential_pkg) }
end
def test_remove_package_with_essential_file
assert_output(true) do
until PackageUtils.installed?(@package_with_essential_file)
system "crew install -d #{@package_with_essential_file}", %i[out err] => File::NULL
sleep 2
end
system "crew remove -d #{@package_with_essential_file}", %i[out err] => File::NULL
return File.file?(@essential_file)
end
end
def test_remove_normal_package
expected_output = <<~EOT
#{@normal_package_name} removed
EOT
assert_output(/^#{Regexp.escape(expected_output.chomp)}!/, nil) do
until PackageUtils.installed?(@normal_package_name)
system "crew install -d #{@normal_package_name}", %i[out err] => File::NULL
sleep 2
end
Command.remove(@normal_pkg, true)
end
end
end