Skip to content

Commit

Permalink
Merge pull request #331 from yast/fix_killing
Browse files Browse the repository at this point in the history
Fix killing
  • Loading branch information
jreidinger committed Jan 27, 2015
2 parents 4d82e76 + af68a65 commit c6c8dc8
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 64 deletions.
2 changes: 1 addition & 1 deletion library/general/test/agents_test/netd_agent_test.rb
Expand Up @@ -13,7 +13,7 @@ module Yast
end

describe ".Read" do
let(:content) { SCR.Read(Path.new(".etc.xinetd_conf.services")) }
let(:content) { SCR.Read(path(".etc.xinetd_conf.services")) }

it "reads content of /etc/xinetd.d and returns array" do
expect(content).to be_a(Array)
Expand Down
6 changes: 3 additions & 3 deletions library/general/test/agents_test/proc_meminfo_agent_test.rb
Expand Up @@ -6,15 +6,15 @@
describe ".proc.meminfo" do
before :each do
root = File.join(File.dirname(__FILE__), "test_root")
assign_root_path(root)
change_scr_root(root)
end

after :each do
reset_root_path
reset_scr_root
end

describe ".Read" do
let(:content) { Yast::SCR.Read(Yast::Path.new(".proc.meminfo")) }
let(:content) { Yast::SCR.Read(path(".proc.meminfo")) }

it "read content of /proc/meminfo return hash" do
expect(content).to be_a(Hash)
Expand Down
81 changes: 81 additions & 0 deletions library/general/test/scr_stub.rb
@@ -0,0 +1,81 @@
require "rspec"

# Helpers for stubbing several agent operations.
#
# Requiring the 'scr_stub' file will automatically register SCRStub as a
# RSpec extension.
#
# @example usage
#
# require 'scr_stub'
#
# describe YaST::SCR do
# before do
# chroot = File.join(File.dirname(__FILE__), "test_chroot")
# change_scr_root(chroot)
# end
#
# after do
# reset_scr_root
# end
#
# describe "#Read" do
# it "works with the .proc.meminfo path"
# # This uses the #path helper from SCRStub and
# # reads from ./test_chroot/proc/meminfo
# values = Yast::SCR.Read(path(".proc.meminfo"))
# expect(values).to include("key" => "value")
# end
# end
# end
module SCRStub
# Shortcut for generating Yast::Path objects
#
# @param route [String] textual representation of the path
# @return [Yast::Path] the corresponding Path object
def path(route)
Yast::Path.new(route)
end

# Encapsulates subsequent SCR calls into a chroot.
#
# Raises an exception if something goes wrong.
#
# @param [#to_s] directory to use as '/' for SCR calls
def change_scr_root(directory)
# On first call, store the default handler in the stack
@scr_handles ||= [Yast::WFM.SCRGetDefault]

check_version = false
handle = Yast::WFM.SCROpen("chroot=#{directory}:scr", check_version)
raise "Error creating the chrooted scr instance" if handle < 0

@scr_handles << handle
Yast::WFM.SCRSetDefault(handle)
end

# Resets the SCR calls to prior behaviour, closing the SCR instance open by
# the last call to #change_scr_root.
#
# Raises an exception if #change_scr_root has not been called before or if the
# corresponding instance has already been closed.
#
# @see #change_scr_root
def reset_scr_root
if @scr_handles.nil? || @scr_handles.size < 2
raise "The SCR instance cannot be closed, it's the last remaining one"
end

default_handle = Yast::WFM.SCRGetDefault
if default_handle != @scr_handles.pop
raise "Error closing the chrooted SCR instance, it's not the current default one"
end

Yast::WFM.SCRClose(default_handle)
Yast::WFM.SCRSetDefault(@scr_handles.last)
end
end

RSpec.configure do |c|
c.include SCRStub
end
11 changes: 1 addition & 10 deletions library/general/test/test_helper.rb
Expand Up @@ -3,13 +3,4 @@
ENV["Y2DIR"] = inc_dirs.join(":")

require "yast"

def assign_root_path(directory)
check_version = false
handle = Yast::WFM.SCROpen("chroot=#{directory}:scr", check_version)
Yast::WFM.SCRSetDefault(handle)
end

def reset_root_path
Yast::WFM.SCRClose(Yast::WFM.SCRGetDefault)
end
require_relative "scr_stub"
2 changes: 1 addition & 1 deletion library/packages/src/modules/PackageCallbacks.rb
Expand Up @@ -79,7 +79,7 @@ def main
@provide_aborted = false
@source_aborted = false

@back_string = ""
@back_string = "\b\b\b\b\b\b\b\b\b\b"
@clear_string = Ops.add(Ops.add(@back_string, " "), @back_string)

# max. length of the text in the repository popup window
Expand Down
2 changes: 1 addition & 1 deletion library/runlevel/test/service_test.rb
Expand Up @@ -35,7 +35,7 @@ def stub_service_with(method, result)
end

it "returns the result of the original result of the command call" do
expect(Service.call("status", "sshd")).to be_kind_of(String)
expect(Service.call("status", "sshd")).to be_kind_of(::String)

stub_service_with(:"try_restart", false)
expect(Service.call("try-restart", "sshd")).to be_false
Expand Down
11 changes: 5 additions & 6 deletions library/system/test/hw_detection_test.rb
@@ -1,7 +1,6 @@
#!/usr/bin/env rspec

require "yast"

require_relative "test_helper"
require_relative "../src/lib/yast2/hw_detection"

describe "HwDetection" do
Expand Down Expand Up @@ -33,22 +32,22 @@

describe "#memory" do
it "returns detected memory size in bytes" do
Yast::SCR.should_receive(:Read).with(Yast::Path.new(".probe.memory")).and_return([@memory])
expect(Yast::SCR).to receive(:Read).with(path(".probe.memory")).and_return([@memory])
expect(Yast2::HwDetection.memory).to eq(@ramsize)
end

it "sums detected memory sizes" do
Yast::SCR.should_receive(:Read).with(Yast::Path.new(".probe.memory")).and_return([@memory, @memory])
expect(Yast::SCR).to receive(:Read).with(path(".probe.memory")).and_return([@memory, @memory])
expect(Yast2::HwDetection.memory).to eq(2 * @ramsize)
end

it "ignores non-memory devices" do
Yast::SCR.should_receive(:Read).with(Yast::Path.new(".probe.memory")).and_return([@memory, @non_memory])
expect(Yast::SCR).to receive(:Read).with(path(".probe.memory")).and_return([@memory, @non_memory])
expect(Yast2::HwDetection.memory).to eq(@ramsize)
end

it "raises exception when detection fails" do
Yast::SCR.should_receive(:Read).with(Yast::Path.new(".probe.memory")).and_return(nil)
expect(Yast::SCR).to receive(:Read).with(path(".probe.memory")).and_return(nil)
expect { Yast2::HwDetection.memory }.to raise_error
end
end
Expand Down
15 changes: 5 additions & 10 deletions library/system/test/kernel_test.rb
@@ -1,24 +1,19 @@
#!/usr/bin/env rspec

top_srcdir = File.expand_path("../../../..", __FILE__)
inc_dirs = Dir.glob("#{top_srcdir}/library/*/src")
ENV["Y2DIR"] = inc_dirs.join(":")

require "yast"
require_relative "test_helper"
require "tmpdir"

include Yast::Logger

Yast.import "Kernel"
Yast.import "FileUtils"
Yast.import "SCR"

DEFAULT_DATA_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "data/modules.d")

describe "Kernel" do
let(:stubbed_modules_dir) { File.join(File.dirname(__FILE__), "data", "modules.d") }

before do
log.info "--- test ---"
stub_const("Yast::KernelClass::MODULES_DIR", DEFAULT_DATA_DIR)
stub_const("Yast::KernelClass::MODULES_DIR", stubbed_modules_dir)
@default_modules = {
Yast::KernelClass::MODULES_CONF_FILE => [],
"MODULES_LOADED_ON_BOOT.conf" => ["module-a", "module-b"],
Expand Down Expand Up @@ -103,7 +98,7 @@
describe "when modules.d directory exists" do
it "stores all modules to be loaded to configuration files and returns true" do
Dir.mktmpdir do |tmpdir|
FileUtils.cp_r(DEFAULT_DATA_DIR + "/.", tmpdir)
FileUtils.cp_r(stubbed_modules_dir + "/.", tmpdir)

stub_const("Yast::KernelClass::MODULES_DIR", tmpdir)
Yast::Kernel.reset_modules_to_load
Expand Down
54 changes: 29 additions & 25 deletions library/system/test/proc_cmdline_test.rb
@@ -1,40 +1,44 @@
#!/usr/bin/env rspec

top_srcdir = File.expand_path("../../../..", __FILE__)
inc_dirs = Dir.glob("#{top_srcdir}/library/*/src")
ENV["Y2DIR"] = inc_dirs.join(":")

require "yast"

Yast.import "SCR"

DEFAULT_DATA_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "data")

def assign_root_path(directory)
root = File.join(DEFAULT_DATA_DIR, directory)
desc = Yast::WFM.SCROpen("chroot=#{root}:scr", false)
Yast::WFM.SCRSetDefault(desc)
end
require_relative "test_helper"

describe "SCR" do
describe ".proc.cmdline" do
describe "Read" do
let(:data_dir) { File.join(File.dirname(__FILE__), "data") }
let(:expected_list) { %w(biosdevname=1 initrd=initrd install=hd:/// splash=silent) }
let(:read_list) { Yast::SCR.Read(Yast::Path.new(".proc.cmdline")).sort }
let(:read_list) { Yast::SCR.Read(path(".proc.cmdline")).sort }

before do
change_scr_root(File.join(data_dir, chroot))
end

after do
reset_scr_root
end

it "parses correctly simple files" do
assign_root_path("cmdline-simple")
expect(read_list).to eq(expected_list)
context "processing a simple file" do
let(:chroot) { "cmdline-simple" }

it "parses it correctly" do
expect(read_list).to eq(expected_list)
end
end

it "parses correctly files with two separators" do
assign_root_path("cmdline-twoseparators")
expect(read_list).to eq(expected_list)
context "processing a file with two separators" do
let(:chroot) { "cmdline-twoseparators" }

it "parses it correctly" do
expect(read_list).to eq(expected_list)
end
end

it "parses correctly files with several lines" do
assign_root_path("cmdline-newlines")
expect(read_list).to eq(expected_list)
context "processing a file with several lines" do
let(:chroot) { "cmdline-newlines" }

it "parses it correctly" do
expect(read_list).to eq(expected_list)
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions library/system/test/test_helper.rb
@@ -0,0 +1,6 @@
top_srcdir = File.expand_path("../../../..", __FILE__)
inc_dirs = Dir.glob("#{top_srcdir}/library/*/src")
ENV["Y2DIR"] = inc_dirs.join(":")

require "yast"
require_relative "../../general/test/scr_stub"
14 changes: 7 additions & 7 deletions library/types/src/modules/String.rb
Expand Up @@ -44,7 +44,7 @@ def main
@calnum = Ops.add(@calpha, @cdigit)
@cpunct = "!\"\#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
@cgraph = Ops.add(@calnum, @cpunct)
@cspace = " \n\t"
@cspace = "\f\r\n\t\v"
@cprint = Ops.add(@cspace, @cgraph)

# 64 characters is the base undeline length
Expand Down Expand Up @@ -491,14 +491,14 @@ def ParseOptions(options, parameters)

# backslah sequences
backslash_seq = {
"a" => "a", # alert
"b" => "", # backspace
"e" => "e", # escape
"f" => "", # FF
"a" => "\a", # alert
"b" => "\b", # backspace
"e" => "\e", # escape
"f" => "\f", # FF
"n" => "\n", # NL
"r" => " ", # CR
"r" => "\r", # CR
"t" => "\t", # tab
"v" => "v", # vertical tab
"v" => "\v", # vertical tab
"\\" => "\\", # backslash
# backslash will be removed later,
# double quote and escaped double quote have to be different
Expand Down
6 changes: 6 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Jan 27 14:16:20 UTC 2015 - jreidinger@suse.com

- fixed \r, \f, \v and \b characters lost during conversion to
Ruby

-------------------------------------------------------------------
Tue Jan 27 11:51:54 UTC 2015 - cwh@suse.com

Expand Down

0 comments on commit c6c8dc8

Please sign in to comment.