From f681458bfc8bcbf77023ecd703038553f46f0b1b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 6 Jul 2021 13:54:23 +0200 Subject: [PATCH] tests: provide global vars distinguishing platforms --- tests/run.rb | 8 ++++++-- tests/test.d/controller.rb | 4 ++-- tests/test.d/test.rb | 19 +++++++++---------- tests/test.d/util.rb | 3 +-- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/run.rb b/tests/run.rb index e66422c27..62d693a70 100755 --- a/tests/run.rb +++ b/tests/run.rb @@ -21,8 +21,12 @@ rescue end def setup - ENV[ /darwin/i.match(RUBY_PLATFORM) ? 'LANG' : 'LC_ALL' ] = 'en_US.UTF-8' - ENV['PATH'] = "../src:" + ENV['PATH'] + $is_windows = %r{win|mingw}i.match(RUBY_PLATFORM) + $is_macos = %r{darwin}i.match(RUBY_PLATFORM) + $is_linux = !$is_windows && !$is_macos + + ENV[ $is_macos ? 'LANG' : 'LC_ALL' ] = 'en_US.UTF-8' + ENV['PATH'] = "../src:" + ENV['PATH'] $config = read_build_config end diff --git a/tests/test.d/controller.rb b/tests/test.d/controller.rb index 192121b62..75f85dae8 100644 --- a/tests/test.d/controller.rb +++ b/tests/test.d/controller.rb @@ -19,8 +19,8 @@ class Controller def get_num_processors np = case RUBY_PLATFORM - when /darwin/ then `/usr/sbin/sysctl -n hw.availcpu`.to_i - else `nproc`.to_i + when $is_macos then `/usr/sbin/sysctl -n hw.availcpu`.to_i + else `nproc`.to_i end [ np, 0 ].max + 1 end diff --git a/tests/test.d/test.rb b/tests/test.d/test.rb index f2d738dab..fa7290b18 100644 --- a/tests/test.d/test.rb +++ b/tests/test.d/test.rb @@ -12,16 +12,15 @@ class Test @debug_commands = Array.new # install md5 handler - case RUBY_PLATFORM - when /darwin/ - @md5 = lambda do |name| - @debug_commands << "/sbin/md5 #{name}" - `/sbin/md5 #{name}`.chomp.gsub(/.*=\s*/, "") - end - else - @md5 = lambda do |name| - @debug_commands << "md5sum #{name}" - `md5sum #{name}`.chomp.gsub(/\s+.*/, "") + if $is_macos + @md5 = lambda do |name| + @debug_commands << "/sbin/md5 #{name}" + `/sbin/md5 #{name}`.chomp.gsub(/.*=\s*/, "") + end + else + @md5 = lambda do |name| + @debug_commands << "md5sum #{name}" + `md5sum #{name}`.chomp.gsub(/\s+.*/, "") end end end diff --git a/tests/test.d/util.rb b/tests/test.d/util.rb index 45964e55f..d227e5c49 100644 --- a/tests/test.d/util.rb +++ b/tests/test.d/util.rb @@ -42,8 +42,7 @@ class String end # install md5 handler -case RUBY_PLATFORM -when /darwin/ +if $is_macos def md5 name `/sbin/md5 #{name}`.chomp.gsub(/.*=\s*/, "") end