From 2767ec7a44c020dd0c0e3b725a81d97aa14e929e Mon Sep 17 00:00:00 2001 From: Stefan Hundhammer Date: Wed, 4 May 2022 14:29:14 +0200 Subject: [PATCH] Fixed unit tests in autobuild --- library/packages/test/slide_show_test.rb | 20 ++++++++++++++++++ library/packages/test/test_helper.rb | 26 ++++++++++++++++++++++++ package/yast2.spec | 10 +++++++++ 3 files changed, 56 insertions(+) diff --git a/library/packages/test/slide_show_test.rb b/library/packages/test/slide_show_test.rb index e970ae6a8..8a49c2754 100755 --- a/library/packages/test/slide_show_test.rb +++ b/library/packages/test/slide_show_test.rb @@ -6,6 +6,26 @@ Yast.import "Slides" Yast.import "UI" +# Avoid testing product_name() and the methods that are using it: +# This will break because we needed to suppress +# +# require "y2packager/product_spec" +# +# by overloading Kernel::require in ./test_helper.rb to avoid a cyclic +# dependency between this package and yast2-packager. +# +# It will work when running the unit tests locally, but it will break in an +# autobuild environment ("rake osc:build", "rake osc:sr") which is called in +# Jenkins because unlike any real-life system using YaST, an AutoBuild +# environment will NOT install yast2-packager anyway to satisfy other +# requirements. So this problem is hard to spot. +# +# It might be possible to force it to work with some heavy monkey-patching and +# instance_double, but for the extent of useful testing that it might bring, +# this is simply not worthwhile. +# +# 2022-05-04 shundhammer +# describe "Yast::SlideShow" do before(:each) do Yast.y2milestone "--------- Running test ---------" diff --git a/library/packages/test/test_helper.rb b/library/packages/test/test_helper.rb index 180ca4377..90df4058c 100644 --- a/library/packages/test/test_helper.rb +++ b/library/packages/test/test_helper.rb @@ -2,3 +2,29 @@ require "pathname" PACKAGES_FIXTURES_PATH = Pathname.new(File.dirname(__FILE__)).join("data") + +LIBS_TO_SKIP = [ + "y2packager/product_spec" # used in SlideShow.rb +].freeze + +# Hack to avoid to require some files. Stolen from +# https://github.com/yast/yast-storage-ng/blob/master/test/spec_helper.rb#L32-L50 +# +# This is here to avoid a cyclic dependency with yast2-packager at build time. +# yast2.spec does build-require yast2-packager, so the (Ruby) require for files +# defined by that package must be avoided. +# +# Of course that means that tests might need to use instance() or +# instance_double() to make the missing classes and methods from those +# libraries available. +# +# Notice that the problem might be hidden for locally running the unit tests, +# but not when calling them in an Autobuild environment (e.g. "rake osc:build" +# or "rake osc:sr"). +module Kernel + alias_method :old_require, :require + + def require(path) + old_require(path) unless LIBS_TO_SKIP.include?(path) + end +end diff --git a/package/yast2.spec b/package/yast2.spec index 72895e761..eb7fc3853 100644 --- a/package/yast2.spec +++ b/package/yast2.spec @@ -64,6 +64,16 @@ BuildRequires: yast2-ycp-ui-bindings >= 4.3.3 BuildRequires: cpio BuildRequires: rpm +# Intentionally NOT requiring or build-requiring yast2-packager +# to avoid a cyclic dependency. +# +# For the BuildRequires, see test_helper.rb and slide_show_test.rb +# in library/packages/test/ . +# +# For the runtime Requires, it can safely be assumed that every system that +# does any package installation has yast2-packager from the dependencies of the +# client module that does that. + # for ag_tty (/bin/stty) # for /usr/bin/md5sum Requires: coreutils