Skip to content

Commit

Permalink
Run the libyui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed Oct 15, 2020
1 parent a2d8479 commit 12c144d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 16 deletions.
6 changes: 3 additions & 3 deletions package/yast2-ruby-bindings.spec
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ BuildRequires: yast2-ycp-ui-bindings-devel >= 4.3.1
# 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
# The mentioned test requires to check if tmux is there, because tmux is
# needed to execute the test in headless systems
BuildRequires: which
# The mentioned test requires tmux in order to be executed in headless systems
# Also many other libyui tests to come
BuildRequires: tmux

# only a soft dependency, the Ruby debugger is optional
Suggests: rubygem(%{rb_default_ruby_abi}:byebug)
Expand Down
16 changes: 13 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#
# CMakeLists.txt for yast2/ruby-bindings/tests/ruby
#
# CMakeLists.txt for yast-ruby-bindings/tests

# use
# make test
# or, for verbose output,
# make test ARGS=-V
# ARGS is passed to ctest; see also
# man ctest

ENABLE_TESTING()

Expand All @@ -12,3 +17,8 @@ endforeach(test)

ADD_TEST("integration" ruby ${CMAKE_CURRENT_SOURCE_DIR}/integration/run.rb)
ADD_TEST("translations" rspec --format doc ${CMAKE_CURRENT_SOURCE_DIR}/integration/translations_spec.rb)

file(GLOB libyui_tests "libyui/*.test")
foreach(test ${libyui_tests})
ADD_TEST(${test} ${test})
endforeach()
2 changes: 1 addition & 1 deletion tests/libyui/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

- `foo` - main script of the test case
- `foo.test` - main script of the test case
- `foo.rb` - UI set up
12 changes: 11 additions & 1 deletion tests/libyui/table_sort_wrong_cell_1165388.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#!/usr/sbin/yast
#! /usr/bin/env ruby

# See table_sort_wrong_cell_1165388.test

require_relative "../test_helper"
require "yast"

if Yast.ui_component == ""
Yast.ui_component = ARGV[0] || "ncurses"
end

module Yast
class TableCellClient < Client
def main
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#!/bin/sh

# Verify that changing a value in a sorted table works correctly.
# See https://bugzilla.opensuse.org/show_bug.cgi?id=1165388

set -u # unset variables are an error
. ../examples/screenshots-tui/scripts/tmux-uitest.sh
MYDIR=$(dirname "$0")
# shellcheck source=/dev/null # that file is checked separately
. "$MYDIR"/tmux-uitest.sh
BASE=table_sort_wrong_cell_1165388

tmux_new_session /usr/sbin/yast ./"$BASE".rb || exit
tmux_new_session "$MYDIR"/"$BASE".rb || exit
trap tmux_cleanup EXIT

tmux_await "Table sorting test" || exit
sleep 0.1 # draw the rest of the screen

Expand Down
20 changes: 14 additions & 6 deletions tests/libyui/tmux-uitest.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
# tmux-uitest.sh - a shell library to test Text User Interface using tmux

SESSION=uitest
: ${VERBOSE=false}
: "${VERBOSE=false}"

# $@ commands
tmux_new_session() {
Expand All @@ -18,15 +21,15 @@ tmux_new_session() {
tmux_grep() {
local REGEX="$1"
tmux capture-pane -t "$SESSION" -p | grep -E --quiet "$REGEX"
RESULT=(${PIPESTATUS[@]})
RESULT=("${PIPESTATUS[@]}")

if [ ${RESULT[0]} != 0 ]; then
if [ "${RESULT[0]}" != 0 ]; then
# capturing the pane failed; the session may have exited already
return 2
fi

# capturing went fine, pass on the grep result
test ${RESULT[1]} = 0
test "${RESULT[1]}" = 0
}

# $1 regex (POSIX ERE) to find in captured pane
Expand Down Expand Up @@ -68,7 +71,13 @@ tmux_send_keys() {
tmux send-keys -t "$SESSION" "$1"
}

# $1 session name
# usage: trap tmux_cleanup EXIT
tmux_cleanup() {
if tmux_has_session; then
tmux_kill_session
fi
}

# ret code: true or false
tmux_has_session() {
if $VERBOSE; then
Expand All @@ -79,7 +88,6 @@ tmux_has_session() {
}


# $1 session name
tmux_kill_session() {
if $VERBOSE; then
echo Killing the session
Expand Down

0 comments on commit 12c144d

Please sign in to comment.