Hello community, here is the log from the commit of package yast2-ruby-bindings for openSUSE:Factory checked in at 2017-04-12 17:10:28 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/yast2-ruby-bindings (Old) and /work/SRC/openSUSE:Factory/.yast2-ruby-bindings.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "yast2-ruby-bindings" Wed Apr 12 17:10:28 2017 rev:79 rq:487041 version:3.2.11 Changes: -------- --- /work/SRC/openSUSE:Factory/yast2-ruby-bindings/yast2-ruby-bindings.changes 2017-03-29 13:22:32.465681052 +0200 +++ /work/SRC/openSUSE:Factory/.yast2-ruby-bindings.new/yast2-ruby-bindings.changes 2017-04-12 17:10:29.755847410 +0200 @@ -1,0 +2,24 @@ +Mon Apr 10 11:50:04 UTC 2017 - jreidin...@suse.com + +- Set proper title for YaST2 application (bsc#1033161) +- 3.2.11 + +------------------------------------------------------------------- +Wed Mar 22 15:45:50 UTC 2017 - jreidin...@suse.com + +- Add new y2start as ruby script which have several advantages + (bsc#1027181): +-- Ruby is no longer embedded into YaST (instead we only use binary + extensions), so there is less chance of things breaking with + a new Ruby version +-- show popup when signal is received and also allow YaST modules + to handle more gracefully when signal is raised +-- better argument passing to y2start itself e.g. + y2base foo -S '(bar)' qt ----> y2start foo --arg bar qt +-- ruby infrastructure can be used directly on y2start like debugger + or profiler +-- majority of y2start functionality is covered by unit tests + allowing easier and less error-prone future changes +- 3.2.10 + +------------------------------------------------------------------- Old: ---- yast2-ruby-bindings-3.2.9.tar.bz2 New: ---- yast2-ruby-bindings-3.2.11.tar.bz2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ yast2-ruby-bindings.spec ++++++ --- /var/tmp/diff_new_pack.tAsI7T/_old 2017-04-12 17:10:30.583730215 +0200 +++ /var/tmp/diff_new_pack.tAsI7T/_new 2017-04-12 17:10:30.587729648 +0200 @@ -17,7 +17,7 @@ Name: yast2-ruby-bindings -Version: 3.2.9 +Version: 3.2.11 Release: 0 Url: https://github.com/yast/yast-ruby-bindings BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -38,11 +38,11 @@ Requires: rubygem(%{rb_default_ruby_abi}:fast_gettext) %endif BuildRequires: ruby-devel -# new ErrorNamespace needed -Requires: yast2-core >= 3.2.1 -BuildRequires: yast2-core-devel >= 3.2.1 -Requires: yast2-ycp-ui-bindings >= 2.21.9 -BuildRequires: yast2-ycp-ui-bindings-devel >= 2.21.9 +Requires: yast2-core >= 3.2.2 +BuildRequires: yast2-core-devel >= 3.2.2 +# UI.SetApplicationTitle +Requires: yast2-ycp-ui-bindings >= 3.2.0 +BuildRequires: yast2-ycp-ui-bindings-devel >= 3.2.0 # The test suite includes a regression test (std_streams_spec.rb) for a # libyui-ncurses bug fixed in 2.47.3 BuildRequires: libyui-ncurses >= 2.47.3 @@ -100,6 +100,7 @@ %files %defattr (-, root, root) +%{yast_ybindir}/y2start %{_libdir}/YaST2/plugin/libpy2lang_ruby.so %{_libdir}/ruby/vendor_ruby/%{rb_ver}/*.rb %{_libdir}/ruby/vendor_ruby/%{rb_ver}/yast ++++++ yast2-ruby-bindings-3.2.9.tar.bz2 -> yast2-ruby-bindings-3.2.11.tar.bz2 ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/package/yast2-ruby-bindings.changes new/yast2-ruby-bindings-3.2.11/package/yast2-ruby-bindings.changes --- old/yast2-ruby-bindings-3.2.9/package/yast2-ruby-bindings.changes 2017-03-23 15:46:15.160272844 +0100 +++ new/yast2-ruby-bindings-3.2.11/package/yast2-ruby-bindings.changes 2017-04-10 14:13:08.608990458 +0200 @@ -1,4 +1,28 @@ ------------------------------------------------------------------- +Mon Apr 10 11:50:04 UTC 2017 - jreidin...@suse.com + +- Set proper title for YaST2 application (bsc#1033161) +- 3.2.11 + +------------------------------------------------------------------- +Wed Mar 22 15:45:50 UTC 2017 - jreidin...@suse.com + +- Add new y2start as ruby script which have several advantages + (bsc#1027181): +-- Ruby is no longer embedded into YaST (instead we only use binary + extensions), so there is less chance of things breaking with + a new Ruby version +-- show popup when signal is received and also allow YaST modules + to handle more gracefully when signal is raised +-- better argument passing to y2start itself e.g. + y2base foo -S '(bar)' qt ----> y2start foo --arg bar qt +-- ruby infrastructure can be used directly on y2start like debugger + or profiler +-- majority of y2start functionality is covered by unit tests + allowing easier and less error-prone future changes +- 3.2.10 + +------------------------------------------------------------------- Wed Mar 22 14:45:50 UTC 2017 - jreidin...@suse.com - Use more friendly exception when an invalid Yast::Path is diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/package/yast2-ruby-bindings.spec new/yast2-ruby-bindings-3.2.11/package/yast2-ruby-bindings.spec --- old/yast2-ruby-bindings-3.2.9/package/yast2-ruby-bindings.spec 2017-03-23 15:46:15.160272844 +0100 +++ new/yast2-ruby-bindings-3.2.11/package/yast2-ruby-bindings.spec 2017-04-10 14:13:08.608990458 +0200 @@ -17,7 +17,7 @@ Name: yast2-ruby-bindings -Version: 3.2.9 +Version: 3.2.11 Url: https://github.com/yast/yast-ruby-bindings Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build @@ -38,11 +38,11 @@ Requires: rubygem(%{rb_default_ruby_abi}:fast_gettext) %endif BuildRequires: ruby-devel -# new ErrorNamespace needed -Requires: yast2-core >= 3.2.1 -BuildRequires: yast2-core-devel >= 3.2.1 -Requires: yast2-ycp-ui-bindings >= 2.21.9 -BuildRequires: yast2-ycp-ui-bindings-devel >= 2.21.9 +Requires: yast2-core >= 3.2.2 +BuildRequires: yast2-core-devel >= 3.2.2 +# UI.SetApplicationTitle +Requires: yast2-ycp-ui-bindings >= 3.2.0 +BuildRequires: yast2-ycp-ui-bindings-devel >= 3.2.0 # The test suite includes a regression test (std_streams_spec.rb) for a # libyui-ncurses bug fixed in 2.47.3 BuildRequires: libyui-ncurses >= 2.47.3 @@ -100,6 +100,7 @@ %files %defattr (-, root, root) +%{yast_ybindir}/y2start %{_libdir}/YaST2/plugin/libpy2lang_ruby.so %{_libdir}/ruby/vendor_ruby/%{rb_ver}/*.rb %{_libdir}/ruby/vendor_ruby/%{rb_ver}/yast diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/src/CMakeLists.txt new/yast2-ruby-bindings-3.2.11/src/CMakeLists.txt --- old/yast2-ruby-bindings-3.2.9/src/CMakeLists.txt 2017-03-23 15:46:15.164272844 +0100 +++ new/yast2-ruby-bindings-3.2.11/src/CMakeLists.txt 2017-04-10 14:13:08.608990458 +0200 @@ -1,2 +1,6 @@ add_subdirectory(ruby) add_subdirectory(binary) + + + +install(PROGRAMS y2start/y2start DESTINATION lib/YaST2/bin) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/src/binary/Yast.cc new/yast2-ruby-bindings-3.2.11/src/binary/Yast.cc --- old/yast2-ruby-bindings-3.2.9/src/binary/Yast.cc 2017-03-23 15:46:15.164272844 +0100 +++ new/yast2-ruby-bindings-3.2.11/src/binary/Yast.cc 2017-04-10 14:13:08.612990458 +0200 @@ -521,6 +521,12 @@ static void init_ui() { + // init_ui is needed only for running tests. YaST itself setup UI in y2base + // respective its ruby version when this env variable is specified. + // So skip initialization here to avoid conflicts. + if (getenv("YAST_IS_RUNNING") != NULL) + return; + const char *ui_name = "UI"; Y2Component *c = YUIComponent::uiComponent(); @@ -543,6 +549,27 @@ } } +static VALUE ui_create(VALUE self, VALUE name, VALUE args) +{ + Y2ComponentBroker::getNamespaceComponent("UI"); + + string name_s = StringValuePtr(name); + y2debug("creating UI %s", name_s.c_str()); + Y2Component *server = Y2ComponentBroker::createServer(name_s.c_str()); + int argc = RARRAY_LENINT(args); + char **argv = new char *[argc+1]; + for (long i = 0; i < argc; ++i) + { + VALUE a = rb_ary_entry(args, i); + argv[i] = strdup(StringValuePtr(a)); + } + argv[argc] = NULL; + + server->setServerOptions(argc, argv); + + return Qnil; +} + static VALUE ui_finalizer() { YUIComponent *c = YUIComponent::uiComponent(); @@ -586,9 +613,10 @@ rb_define_singleton_method( rb_mYast, "y2_logger", RUBY_METHOD_FUNC(yast_y2_logger), -1); // UI initialization + rb_define_singleton_method( rb_mYast, "ui_create", RUBY_METHOD_FUNC(ui_create), 2); rb_define_singleton_method( rb_mYast, "ui_component", RUBY_METHOD_FUNC(ui_get_component), 0); rb_define_singleton_method( rb_mYast, "ui_component=", RUBY_METHOD_FUNC(ui_set_component), 1); - rb_define_singleton_method( rb_mYast, "ui_finalizer", RUBY_METHOD_FUNC(ui_finalizer), 0); + rb_define_singleton_method( rb_mYast, "ui_finalizer", RUBY_METHOD_FUNC(ui_finalizer), 0); // Y2 references rb_cYReference = rb_define_class_under(rb_mYast, "YReference", rb_cObject); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/src/ruby/yast/wfm.rb new/yast2-ruby-bindings-3.2.11/src/ruby/yast/wfm.rb --- old/yast2-ruby-bindings-3.2.9/src/ruby/yast/wfm.rb 2017-03-23 15:46:15.172272844 +0100 +++ new/yast2-ruby-bindings-3.2.11/src/ruby/yast/wfm.rb 2017-04-10 14:13:08.616990458 +0200 @@ -215,7 +215,8 @@ # @param [Exception] e the caught exception # @return [String] human readable exception description private_class_method def self.internal_error_msg(e) - msg = "Internal error. Please report a bug report with logs.\n" + msg = "Internal error. Please report a bug report with logs.\n" \ + "Run save_y2logs to get complete logs.\n" if e.is_a?(ArgumentError) && e.message =~ /invalid byte sequence in UTF-8/ msg += "A string was encountered that is not valid in UTF-8.\n" \ @@ -227,6 +228,68 @@ "Caller: #{e.backtrace.first}" end + # Handles a SignalExpection + private_class_method def self.handle_signal_exception(e) + signame = Signal.signame(e.signo) + msg = "YaST received a signal %s and will exit.\n" % signame + # sigterm are often sent by user + if e.signo == 15 + msg += "If termination is not sent by user then please report a bug report with logs.\n" + else + msg += "Please report a bug report with logs.\n" + end + msg += "Run save_y2logs to get complete logs." + + Yast.import "Report" + Report.Error(msg) + rescue Exception => e + Builtins.y2internal("Error reporting failed with '%1' and backtrace %2", + e.message, + e.backtrace) + end + + # Handles a generic Exception + private_class_method def self.handle_exception(e, client) + Builtins.y2error("Client call failed with '%1' (%2) and backtrace %3", + e.message, + e.class, + e.backtrace) + + msg = internal_error_msg(e) + + if ask_to_run_debugger? + Yast.import "Popup" + Yast.import "Label" + msg += "\n\nStart the Ruby debugger now and debug the issue?" \ + " (Experts only!)" + + if Popup.YesNoHeadline(Label.ErrorMsg, msg) + Debugger.start + # Now you can restart the client and watch it step-by-step with + # "next"/"step" commands or you can add some breakpoints into + # the code and use "continue". + run_client(client) + end + else + Yast.import "Report" + Report.Error(msg) + end + rescue Exception => e + Builtins.y2internal("Error reporting failed with '%1' and backtrace %2", + e.message, + e.backtrace) + end + + private_class_method def self.check_client_result_type!(result) + allowed_types = Ops::TYPES_MAP.values.flatten + allowed_types.delete(::Object) # remove generic type for any + + # check if response is allowed + allowed = allowed_types.any? { |t| result.is_a? t } + + raise "Invalid type #{result.class} from client #{client}" unless allowed + end + # @private wrapper to run client in ruby def self.run_client(client) Builtins.y2milestone "Call client %1", client @@ -235,47 +298,19 @@ Debugger.start_from_env Profiler.start_from_env result = eval(code, GLOBAL_WFM_CONTEXT.binding, client) - - allowed_types = Ops::TYPES_MAP.values.flatten - allowed_types.delete(::Object) # remove generic type for any - - # check if response is allowed - allowed = allowed_types.any? { |t| result.is_a? t } - - raise "Invalid type #{result.class} from client #{client}" unless allowed + check_client_result_type!(result) return result + # SystemExit < Exception, raised by Kernel#exit + rescue SystemExit + raise # something call system exit so do not block it + # SignalException < Exception + rescue SignalException => e + handle_signal_exception(e) + exit(16) rescue Exception => e - begin - Builtins.y2error("Client call failed with '%1' and backtrace %2", - e.message, - e.backtrace) - - msg = internal_error_msg(e) - - if ask_to_run_debugger? - Yast.import "Popup" - Yast.import "Label" - msg += "\n\nStart the Ruby debugger now and debug the issue?" \ - " (Experts only!)" - - if Popup.YesNoHeadline(Label.ErrorMsg, msg) - Debugger.start - # Now you can restart the client and watch it step-by-step with - # "next"/"step" commands or you can add some breakpoints into - # the code and use "continue". - retry - end - else - Yast.import "Report" - Report.Error(msg) - end - rescue Exception => e - Builtins.y2internal("Error reporting failed with '%1' and backtrace %2", - e.message, - e.backtrace) - end - return false + handle_exception(e, client) + false end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/src/ruby/yast/y2start_helpers.rb new/yast2-ruby-bindings-3.2.11/src/ruby/yast/y2start_helpers.rb --- old/yast2-ruby-bindings-3.2.9/src/ruby/yast/y2start_helpers.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-ruby-bindings-3.2.11/src/ruby/yast/y2start_helpers.rb 2017-04-10 14:13:08.616990458 +0200 @@ -0,0 +1,134 @@ +module Yast + module Y2StartHelpers + + # Parses ARGV of y2start. it returns map with keys: + # + # - :generic_options [Hash] + # - :client_name [String] + # - :client_options [Hash] always contains `params:` with Array of client arguments + # - :server_name [String] + # - :server_options [Array] ( of unparsed options as server parse it on its own) + # @raise RuntimeError when unknown option appear or used wrongly + def self.parse_arguments(args) + ret = {} + + ret[:generic_options] = parse_generic_options(args) + # for --help early quit as other argument are ignored + return ret if ret[:generic_options][:help] + ret[:client_name] = args.shift or raise "Missing client name." + ret[:client_options] = parse_client_options(args) + ret[:server_name] = args.shift or raise "Missing server name." + ret[:server_options] = args + + ret + end + + def self.help + "Usage: y2start [GenericOpts] Client [ClientOpts] Server " \ + "[Specific ServerOpts]\n" \ + "\n" \ + "GenericOptions are:\n" \ + " -h --help : Sprint this help\n" \ + "\n" \ + "ClientOptions are:\n" \ + " -a --arg : add argument for client. Can be used multiple times.\n" \ + "\n" \ + "Specific ServerOptions are any options passed on unevaluated.\n" \ + "\n" \ + "Examples:\n" \ + "y2start installation qt\n" \ + " Start binary y2start with intallation.ycp as client and qt as server\n" \ + "y2start installation -a initial qt\n" \ + " Provide parameter initial for client installation\n" \ + "y2start installation qt -geometry 800x600\n" \ + " Provide geometry information as specific server options\n" + end + + # so how works signals in ruby version? + # It logs what we know about signal and then continue with standard ruby + # handler, which raises {SignalException} that can be processed. If it is + # not catched, it show popup asking for report bug. + def self.setup_signals + Signal.trap("PIPE", "IGNORE") + + # SEGV, ILL and FPE is reserved, so cannot be set + ["HUP", "INT", "QUIT", "ABRT", "TERM"].each do |name| + Signal.trap(name) { signal_handler(name) } + end + end + + private_class_method def self.signal_handler(name) + Signal.trap(name, "IGNORE") + + $stderr.puts "YaST got signal #{name}." + + signal_log_open do |f| + f.puts "=== #{Time.now} ===" + f.puts "YaST got signal #{name}." + # TODO: print stored debug logs + f.puts "Backtrace (only ruby one):" + caller.each { |l| f.puts(l) } + end + + system("/usr/lib/YaST2/bin/signal-postmortem") + + Signal.trap(name, "DEFAULT") + Process.kill(name, Process.pid) + end + + LOG_LOCATIONS = ["/var/log/YaST2/signal", "y2signal.log"] + private_class_method def self.signal_log_open(&block) + index = 0 + begin + path = LOG_LOCATIONS[index] + return unless path + File.open(path, "a") { |f| block.call(f) } + rescue IOError, SystemCallError + index +=1 + retry + end + end + + private_class_method def self.parse_generic_options(args) + res = {} + loop do + return res unless option?(args.first) + + + arg = args.shift + case arg + when "-h", "--help" + res[:help] = true + else + raise "Unknown option #{args.first}" + end + end + end + + private_class_method def self.parse_client_options(args) + res = {} + res[:params] = [] + loop do + return res unless option?(args.first) + + arg = args.shift + case arg + when "-a", "--arg" + param = args.shift + raise "Missing argument for --arg" unless param + + res[:params] << param + else + raise "Unknown option #{arg}" + end + end + end + + private_class_method def self.option?(arg) + return false unless arg + return true if arg[0] == "-" + + return false + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/src/y2start/y2start new/yast2-ruby-bindings-3.2.11/src/y2start/y2start --- old/yast2-ruby-bindings-3.2.9/src/y2start/y2start 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-ruby-bindings-3.2.11/src/y2start/y2start 2017-04-10 14:13:08.616990458 +0200 @@ -0,0 +1,55 @@ +#! /usr/bin/ruby + +# set env as first part, otherwise dummy UI will be created. +# for insts-sys it will be overwritten later +ENV["YAST_IS_RUNNING"] = "yes" + +require "socket" + +require "yast" +require "yast/y2start_helpers" + +Yast::Y2StartHelpers.setup_signals + +File.umask(0022) + +Yast.y2milestone("y2base called with #{ARGV.inspect}") + +begin + args = Yast::Y2StartHelpers.parse_arguments(ARGV.dup) +rescue RuntimeError => e + $stderr.puts e + $stderr.puts Yast::Y2StartHelpers.help + exit 1 +end + +if args[:generic_options][:help] + $stdout.puts Yast::Y2StartHelpers.help + exit 0 +end + +if (args[:client_name] == "installation" && + args[:client_options][:params].include?("initial")) + ENV["YAST_IS_RUNNING"] = "instsys" +end + +if !Yast::WFM.ClientExists(args[:client_name]) + $stderr.puts "No such client module #{args[:client_name]}" + exit 1 +end + + +Yast.ui_create(args[:server_name], args[:server_options]) +# set application title bsc#1033161 +Yast.import "UI" +# do not fail if gethostname failed +hostname = Socket.gethostname rescue "" +hostname = "" if hostname == "(none)" +hostname = " @ #{hostname}" unless hostname.empty? + +title = "YaST2 - #{args[:client_name]}#{hostname}" +Yast::UI.SetApplicationTitle(title) + +Yast::WFM.CallFunction(args[:client_name], args[:client_options][:params]) + +0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/tests/test_helper.rb new/yast2-ruby-bindings-3.2.11/tests/test_helper.rb --- old/yast2-ruby-bindings-3.2.9/tests/test_helper.rb 2017-03-23 15:46:15.180272844 +0100 +++ new/yast2-ruby-bindings-3.2.11/tests/test_helper.rb 2017-04-10 14:13:08.616990458 +0200 @@ -1,13 +1,14 @@ ROOT_DIR = File.expand_path("../..", __FILE__) -binary_path = "#{ROOT_DIR}/build/src/binary" +BINARY_PATH = "#{ROOT_DIR}/build/src/binary" +RUBY_INC_PATH = "#{ROOT_DIR}/src/ruby" require "fileutils" -if !File.exist? "#{binary_path}/yast" - FileUtils.ln_s binary_path, "#{binary_path}/yast" # to load builtinx.so +if !File.exist? "#{BINARY_PATH}/yast" + FileUtils.ln_s BINARY_PATH, "#{BINARY_PATH}/yast" # to load builtinx.so end -if !File.exist? "#{binary_path}/plugin" +if !File.exist? "#{BINARY_PATH}/plugin" # to load py2lang_ruby.so for calling testing ruby clients - FileUtils.ln_s binary_path, "#{binary_path}/plugin" + FileUtils.ln_s BINARY_PATH, "#{BINARY_PATH}/plugin" end -$LOAD_PATH.unshift binary_path # yastx.so -$LOAD_PATH.unshift "#{ROOT_DIR}/src/ruby" # yast.rb -ENV["Y2DIR"] = binary_path + ":" + File.dirname(__FILE__) + "/test_module" +$LOAD_PATH.unshift BINARY_PATH # yastx.so +$LOAD_PATH.unshift RUBY_INC_PATH # yast.rb +ENV["Y2DIR"] = BINARY_PATH + ":" + File.dirname(__FILE__) + "/test_module" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/tests/y2start_helpers_spec.rb new/yast2-ruby-bindings-3.2.11/tests/y2start_helpers_spec.rb --- old/yast2-ruby-bindings-3.2.9/tests/y2start_helpers_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-ruby-bindings-3.2.11/tests/y2start_helpers_spec.rb 2017-04-10 14:13:08.620990458 +0200 @@ -0,0 +1,50 @@ +#!/usr/bin/env rspec +# encoding: utf-8 + +require_relative "test_helper" +require "yast/y2start_helpers" + +describe Yast::Y2StartHelpers do + subject { described_class } + + describe ".help" do + it "returns multiline help text" do + expect(subject.help).to be_a ::String + end + end + + describe ".setup_signals" do + it "setups signal trap" do + expect(::Signal).to receive(:trap).at_least(:once) + + subject.setup_signals + end + end + + describe ".parse_arguments" do + it "parses passed arguments and returns it as hash" do + expected_output = { + generic_options: {}, + client_name: "test", + client_options: {params: ["abc"]}, + server_name: "UI", + server_options: ["--geometry", "800x600"] + } + + arguments = ["test", "--arg", "abc", "UI", "--geometry", "800x600"] + expect(subject.parse_arguments(arguments)).to eq expected_output + end + + INVALID_ARGUMENTS = [ + [], + ["test"], + ["--bla", "test", "UI"], + ["test", "--bla", "UI"] + ] + it "raises exception if wrong arguments are passed" do + INVALID_ARGUMENTS.each do |arg| + expect{subject.parse_arguments(arg)}.to raise_error(RuntimeError) + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yast2-ruby-bindings-3.2.9/tests/y2start_spec.rb new/yast2-ruby-bindings-3.2.11/tests/y2start_spec.rb --- old/yast2-ruby-bindings-3.2.9/tests/y2start_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/yast2-ruby-bindings-3.2.11/tests/y2start_spec.rb 2017-04-10 14:13:08.620990458 +0200 @@ -0,0 +1,29 @@ +#!/usr/bin/env rspec +# encoding: utf-8 + +require_relative "test_helper" + +describe "y2start" do + let(:script_path) do + cmd = "ruby" + cmd << " -I #{BINARY_PATH}" + cmd << " -I #{RUBY_INC_PATH}" + cmd << " --" + cmd << " #{ROOT_DIR}/src/y2start/y2start" + end + + it "prints helps and exit 0 if run with --help" do + expect(`#{script_path} --help 2>&1`).to match(/Usage/) + expect($?.exitstatus).to eq 0 + end + + it "prints help and exit 1 if invalid argument passed" do + expect(`#{script_path} --invalid 2>&1`).to match(/Usage/) + expect($?.exitstatus).to eq 1 + end + + it "prints that client not found and exit 1 if client not found" do + expect(`#{script_path} invalid UI 2>&1`).to match(/No such client/) + expect($?.exitstatus).to eq 1 + end +end