From 1ba99751afd9a7f0023de3ed5453d579324d8271 Mon Sep 17 00:00:00 2001 From: "Maxim [maxirmx] Samsonov" Date: Fri, 10 Jan 2025 16:17:00 +0300 Subject: [PATCH] test: refactor gem packaging tests to address #215 --- lib/tebako/deploy_helper.rb | 9 +++-- spec/deploy_helper_spec.rb | 6 ++-- tests/scripts/functional-tests.sh | 8 +++++ tests/test-01/tebako-test-run.rb | 2 +- tests/test-09/tebako-test-0.0.1.gem | Bin 4608 -> 0 bytes tests/test-09/tebako-test-0.0.2.gem | Bin 0 -> 5120 bytes tests/test-11/{bin => exe}/tebako-test-run.rb | 6 ++-- tests/test-11/lib/tebako-test.rb | 32 +++++++++++------- tests/test-11/lib/version.rb | 5 +++ tests/test-11/tebako-test.gemspec | 7 ++-- tests/test-20/tebako-test-run.rb | 1 - 11 files changed, 50 insertions(+), 26 deletions(-) delete mode 100644 tests/test-09/tebako-test-0.0.1.gem create mode 100644 tests/test-09/tebako-test-0.0.2.gem rename tests/test-11/{bin => exe}/tebako-test-run.rb (71%) create mode 100644 tests/test-11/lib/version.rb diff --git a/lib/tebako/deploy_helper.rb b/lib/tebako/deploy_helper.rb index 39b197fb..88e4daa7 100644 --- a/lib/tebako/deploy_helper.rb +++ b/lib/tebako/deploy_helper.rb @@ -25,6 +25,7 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +# require "bundler" require "fileutils" require "find" @@ -92,7 +93,7 @@ def install_gem(name, ver = nil) params = [@gem_command, "install", name.to_s] params.push("-v", ver.to_s) if ver - ["--no-document", "--install-dir", @tgd].each do |param| + ["--no-document", "--install-dir", @tgd, "--bindir", @tbd].each do |param| params.push(param) end BuildHelpers.run_with_capture_v(params) @@ -141,11 +142,15 @@ def check_cwd end def collect_and_deploy_gem(gemspec) - puts " ... Collecting gem from gemspec #{gemspec}" + puts " ... collecting gem from gemspec #{gemspec}" copy_files(@pre_dir) Dir.chdir(@pre_dir) do + # spec = Bundler.load_gemspec(gemspec) + # puts spec.executables.first unless spec.executables.empty? + # puts spec.bindir + BuildHelpers.run_with_capture_v([@gem_command, "build", gemspec]) install_all_gems_or_fail end diff --git a/spec/deploy_helper_spec.rb b/spec/deploy_helper_spec.rb index 841efbf1..c2e6a46c 100644 --- a/spec/deploy_helper_spec.rb +++ b/spec/deploy_helper_spec.rb @@ -354,6 +354,7 @@ before do deploy_helper.instance_variable_set(:@tgd, "/path/to/tgd") + deploy_helper.instance_variable_set(:@tbd, "/path/to/tbd") deploy_helper.instance_variable_set(:@gem_command, gem_command) deploy_helper.instance_variable_set(:@bundler_command, bundler_command) allow(Open3).to receive(:capture2e).and_return(["", double("status", signaled?: false, exitstatus: 0)]) @@ -363,7 +364,7 @@ it "installs the gem with the specified version" do expect(Open3).to receive(:capture2e) .with(gem_command, "install", gem_name, "-v", gem_version, "--no-document", - "--install-dir", "/path/to/tgd") + "--install-dir", "/path/to/tgd", "--bindir", "/path/to/tbd") deploy_helper.install_gem(gem_name, gem_version) end end @@ -371,7 +372,8 @@ context "when gem version is not provided" do it "installs the gem without specifying the version" do expect(Open3).to receive(:capture2e) - .with(gem_command, "install", gem_name, "--no-document", "--install-dir", "/path/to/tgd") + .with(gem_command, "install", gem_name, "--no-document", + "--install-dir", "/path/to/tgd", "--bindir", "/path/to/tbd") deploy_helper.install_gem(gem_name) end end diff --git a/tests/scripts/functional-tests.sh b/tests/scripts/functional-tests.sh index c3a2948b..cea9daf1 100755 --- a/tests/scripts/functional-tests.sh +++ b/tests/scripts/functional-tests.sh @@ -250,6 +250,12 @@ test_tebako_press_04() { # 09. Ruby gem (xxx.gem, no gemspec, no gemfile) test_tebako_press_09() { echo "==> Ruby gem (xxx.gem, no gemspec, no gemfile)" + +# Use test-11 gemspec to build a test gem + pushd "${DIR_TESTS}/test-11" > /dev/null || fail "pushd ${DIR_TESTS}/test-11 failed" + gem build tebako-test.gemspec -o "${DIR_TESTS}/test-09/tebako-test-0.0.2.gem" + popd > /dev/null || fail "popd failed" + press_runner_"${MODE}" "${DIR_TESTS}/test-09" "tebako-test-run.rb" "test-09-package" package_runner_"${MODE}" "./test-09-package" "| a1 | b1 |" } @@ -263,6 +269,8 @@ test_tebako_press_10() { else rc=106 fi + +# Use gem built for test-09 press_runner_with_error_"${MODE}" "${DIR_TESTS}/test-09" \ "test-does-not-exist.rb" \ "test-10-package" \ diff --git a/tests/test-01/tebako-test-run.rb b/tests/test-01/tebako-test-run.rb index 01a7385b..c2b5051d 100755 --- a/tests/test-01/tebako-test-run.rb +++ b/tests/test-01/tebako-test-run.rb @@ -3,7 +3,7 @@ puts "Hello! This is test-01 talking from inside DwarFS" puts "Gem path: #{Gem.path}" -puts "Rubygems version: #{Gem::rubygems_version}" +puts "Rubygems version: #{Gem.rubygems_version}" if defined?(TebakoRuntime::VERSION) puts "Using tebako-runtime v#{TebakoRuntime::VERSION}" else diff --git a/tests/test-09/tebako-test-0.0.1.gem b/tests/test-09/tebako-test-0.0.1.gem deleted file mode 100644 index efce686c805cdd61ff06eac9d919d32b8a59a72f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4608 zcmc~zElEsCEJ@T$uVSDTFaQD*6B7my4Fu@4p@E?}gQ1C`p_z%1xv{A+gMp#3iHR|T zf&r}@glukUaY8f@({lvJcp)zuyWukw3^$_}uYjZ@B&a0&~)q zDI~0|TB-T+yZoA|9v!7y<3z7US5<~~{+V{Q?nC|>R{m|Qt4*HVofq_PgZrC~um3hg z>jaoFPsmhDKJaL%aJ}6w&KkDmypxwMNdNdeZK8PQ&pA1lEjqSqU4Lpiv+#N6bdJTY zxkB3V3I`aBCRHl8bGV;;ZOo+3I;T<5YXl$3H(xG}~4*{#b)C#<&kU6r1@Xj0*?MHN}op0>)c%9j+s@;G)+^1~)& z(P|g@qeV9}-yC12(&RnG&A-Ad!lGp-*5o|4qB+x@K#yM*BiDfn>ka zM&8q>&Zsz7bUiL<{%66pdpE9~eBrBc{f)|x|8!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210^vS4u0zJ1UR;;wB+@iNxO4&ui zLA~jEl}EvpU6zYK%-1NN;IlyU-dym#-8DCV*N`KChv!PAmEUW#GyB(GezH?WK{{J|+S1~cU*2$Kqw|R78_5M#* z?MiwsJ6E*Y>3P(>Q@>`Z?*4c!e-`_VNta%JVX;1TZ-a^Da^==N4^QqYWbnIbA?vgI z-s7FN8vLiyr|BcNJM$3QN#5k&{ zi1Po~dn@x4?(#Y%lJ$3)@qW_&y{8pJ}(cc}^pKV(F z>Br{VO`WIqE$G=27~`jWkXK8MEg__D-R}=?PkwOyQfFbMwDXGQe2I#qtU@v8X8J6$ zG=8bvKcVlz#_uePG#+Yo$?fK{e;T7$v31(#nCafX1)oSflCt0US>}Jr7n8@Rre=x#e?c2P{_V+!vbsJdJ4K80U;tlv0Y{@t6 zsD;M7Q=S3Eo?SW{71_H#E86V8u_(Ne>WZkGd`&H*elv%gSJner26H`O9^54YF$Z)j$r$ey{tk;Pc z@G$(gJsOuVasS4@R#sJh0>}A8d2e-HPLAV@U1Bj=a(~?VC{xJdHsz%J}HcDVMIVlU|T|^VP%JP4|9ZS6@GO z>E42SODaDl$}w5)C~!VD=ennT!I4=OH?Jh7DQ%TZ`1>_v$$uNw%w=mnro7YOS|RFu z{+@Em?k9J4^u4SKYWlfol}yjn%ZD5VcK1)cs&=QMQS0rBrkxh)jsAZg7R_|n&V1wW zQlCcFU4QSN>lHPPFY(l!cdsOQ`XWC0_Nm{Gbup}MX1#E1qhYCO+^03WN^;jNvYN~G zWZlHl^;(zrnN*9dk31)vKK1tN7apG3%Qx+^`^WHOGNZ{AMtVfWs2!srFd71*Awbs< F003<(`P2Xa literal 0 HcmV?d00001 diff --git a/tests/test-11/bin/tebako-test-run.rb b/tests/test-11/exe/tebako-test-run.rb similarity index 71% rename from tests/test-11/bin/tebako-test-run.rb rename to tests/test-11/exe/tebako-test-run.rb index 6d61c934..5482a254 100755 --- a/tests/test-11/bin/tebako-test-run.rb +++ b/tests/test-11/exe/tebako-test-run.rb @@ -4,7 +4,5 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "tebako-test" -begin - instance = TebakoTest.new - instance.run! -end +instance = Test::TebakoTest.new +instance.run diff --git a/tests/test-11/lib/tebako-test.rb b/tests/test-11/lib/tebako-test.rb index 501f567a..31a03d52 100644 --- a/tests/test-11/lib/tebako-test.rb +++ b/tests/test-11/lib/tebako-test.rb @@ -1,20 +1,26 @@ # frozen_string_literal: true require "text-table" +require_relative "version" -# Tebako test class -class TebakoTest - def msg - table = Text::Table.new - table.head = %w[A B] - table.rows = [%w[a1 b1]] - table.rows << %w[a2 b2] - puts table - end +module Test + # Tebako test class + class TebakoTest + def msg + table = Text::Table.new + table.head = %w[A B] + table.rows = [%w[a1 b1]] + table.rows << %w[a2 b2] + table + end + + def run + puts <<~MSG + Running packaged tebako-test gem version #{VERSION}. + You shall see a nice text table below. - def run! - puts "Hello! This is test-11 talking from inside DwarFS" - puts "You will now see a nice table that will be drawn for you by text-table gem." - msg + #{msg} + MSG + end end end diff --git a/tests/test-11/lib/version.rb b/tests/test-11/lib/version.rb new file mode 100644 index 00000000..3e8b0a2c --- /dev/null +++ b/tests/test-11/lib/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Test + VERSION = "0.0.2" +end diff --git a/tests/test-11/tebako-test.gemspec b/tests/test-11/tebako-test.gemspec index 89b60f1f..4519b444 100644 --- a/tests/test-11/tebako-test.gemspec +++ b/tests/test-11/tebako-test.gemspec @@ -1,15 +1,16 @@ # frozen_string_literal: true +require_relative "lib/version" Gem::Specification.new do |s| s.name = "tebako-test" - s.version = "0.0.1" + s.version = Test::VERSION s.summary = "A simple gem for tebako testing" s.authors = ["Ribose"] s.email = ["open.source@ribose.com"] - s.files = ["bin/tebako-test-run.rb", "lib/tebako-test.rb"] + s.files = Dir.glob("lib/**/*") + Dir.glob("exe/**/*") s.homepage = "https://github.com/tamitebako" s.license = "Unlicense" - s.bindir = "bin" + s.bindir = "exe" s.required_ruby_version = Gem::Requirement.new(">= 2.7.0") s.add_dependency "text-table", "~> 1.2.4" s.executables << "tebako-test-run.rb" diff --git a/tests/test-20/tebako-test-run.rb b/tests/test-20/tebako-test-run.rb index 68ab6969..12cac792 100644 --- a/tests/test-20/tebako-test-run.rb +++ b/tests/test-20/tebako-test-run.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true - puts "Hello! This is test-20 talking from inside DwarFS" require "net/http"