From 08ddf8738b6239568a129b99501beee448e6bc1c Mon Sep 17 00:00:00 2001 From: Zdenek Dohnal Date: Thu, 29 Jun 2023 19:47:17 +0200 Subject: [PATCH] Fix and enhance sanity test for new libpaper There is a new libpaper version which brought several changes: - PAPERCONF variable is removed - a new binary - paper - is now shipped and deprecates paperconf - paper and paperconf reads from LC_PAPER, which is always populated, so reading of /etc/papersize is almost ignored - new support for user configs The test reflects that and add paper tests as well. --- .../basic-sanity-test-for-paperconf/main.fmf | 1 + .../runtest.sh | 123 +++++++++++++----- 2 files changed, 95 insertions(+), 29 deletions(-) diff --git a/Sanity/basic-sanity-test-for-paperconf/main.fmf b/Sanity/basic-sanity-test-for-paperconf/main.fmf index a5eafaa..02b9555 100644 --- a/Sanity/basic-sanity-test-for-paperconf/main.fmf +++ b/Sanity/basic-sanity-test-for-paperconf/main.fmf @@ -7,6 +7,7 @@ test: ./runtest.sh framework: beakerlib recommend: - libpaper + - paper duration: 5m enabled: true tag: diff --git a/Sanity/basic-sanity-test-for-paperconf/runtest.sh b/Sanity/basic-sanity-test-for-paperconf/runtest.sh index cf0abf3..6620b25 100755 --- a/Sanity/basic-sanity-test-for-paperconf/runtest.sh +++ b/Sanity/basic-sanity-test-for-paperconf/runtest.sh @@ -5,6 +5,7 @@ # runtest.sh of /CoreOS/libpaper/Sanity/basic-sanity-test-for-paperconf # Description: basic sanity test for paperconf # Author: kzilkova +# Zdenek Dohnal # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # @@ -38,47 +39,111 @@ rlJournalStart rlRun "pushd $TmpDir" SIZEBCKUP=$PAPERSIZE CONFBCKUP=$PAPERCONF - rlRun "rlFileBackup --missing-ok /etc/papersize" 0 "backup papersize" + if rlIsRHELLike '<10' + then + rlFileBackup --missing-ok /etc/papersize + fi rlPhaseEnd - rlPhaseStartTest - #test basic functionality of paperconf command - rlRun "paperconf | grep 'letter'" 0 "Correct default value" - rlRun "paperconf -p a4 -wm | grep '210 mm'" 0 "check a4 width in mm" - rlRun "paperconf -p a4 -sc | grep '21 cm 29.7 cm'" 0 "check a4 height and width in cm" - rlRun "paperconf -p a2 -N | grep 'A2'" 0 "check if a in a2 is capitalized" - rlRun "paperconf -p note -N | grep 'Note'" 0 "check if N in note is capitalized" - rlRun "paperconf -d | grep 'letter'" 0 "check if default paper is letter" - rlRun "paperconf -p as -z | grep 'as'" 0 "check if -z prints wrong paper" - rlRun "paperconf -p a3 | grep 'a3'" 0 "check if there is paper a3" - rlRun "paperconf -p a5 | grep 'a5'" 0 "check if there is paper a5" - rlRun "paperconf -p a4 -hi | grep '11.6929'" 0 "check a4 height in inches" - rlRun "paperconf -p a4 -n | grep 'a4'" 0 "check if n print name" + rlPhaseStartTest "paperconf" + rlLog "paperconf is deprecated, it will be removed in the future..." - #changing PAPERSIZE variable - rlRun "PAPERSIZE=a4 paperconf | grep 'a4'" 0 "value from papersize" - rlRun "PAPERSIZE=as paperconf |& grep 'unknown paper'" 0 "value from papersize with non-existent PAPARSIZE value inserted" + if test -x /usr/bin/paperconf + then + #test basic functionality of paperconf command + rlRun "paperconf | grep 'letter'" 0 "Correct default value" + rlRun "paperconf -p a4 -wm | grep '210 mm'" 0 "check a4 width in mm" + rlRun "paperconf -p a4 -sc | grep '21 cm 29.7 cm'" 0 "check a4 height and width in cm" + # reported upstream as https://github.com/rrthomas/libpaper/pull/47 + #rlRun "paperconf -p a2 -N | grep 'A2'" 0 "check if a in a2 is capitalized" + #rlRun "paperconf -p note -N | grep 'Note'" 0 "check if N in note is capitalized" + rlRun "paperconf -d | grep 'letter'" 0 "check if default paper is letter" + rlRun "paperconf -p as -z | grep 'as'" 0 "check if -z prints wrong paper" + rlRun "paperconf -p a3 | grep 'a3'" 0 "check if there is paper a3" + rlRun "paperconf -p a5 | grep 'a5'" 0 "check if there is paper a5" + rlRun "paperconf -p a4 -hi | grep '11.6929'" 0 "check a4 height in inches" + rlRun "paperconf -p a4 -n | grep 'a4'" 0 "check if n print name" - #changing PAPERCONF variable - rlRun "PAPERCONF=$TESTDIR/paper paperconf | grep 'a4'" 0 "value from paperconf" - rlRun "PAPERCONF=$TESTDIR/wrpaper paperconf |& grep 'unknown paper'" 0 "value from paperconf, wrong paper" - rlRun "PAPERCONF=$TESTDIR/nopaper paperconf | grep 'letter'" 0 "empty file, print letter" + #changing PAPERSIZE variable + rlRun "PAPERSIZE=a4 paperconf | grep 'a4'" 0 "value from papersize" + rlRun "PAPERSIZE=as paperconf |& grep 'unknown paper'" 0 "value from papersize with non-existent PAPARSIZE value inserted" - #changing paper size value through /etc/papersize file - rlRun "echo a5 >/etc/papersize" 0 "filling papersize with a5 paper" - rlRun "paperconf | grep 'a5'" 0 "value from papersize" + #changing LC_PAPER + rlRun "LC_PAPER='C.utf8' paperconf | grep 'a4'" + rlRun "LC_PAPER='' paperconf | grep 'letter'" - rlRun "echo as > /etc/papersize" 0 "filling papersize with nonsence" - rlRun "paperconf |& grep 'unknown paper'" 0 "value from papersize, nonsence" + #changing paper size value through /etc/papersize file - currently glibc sets LC_PAPER by default + #with some locale, so we have to fill non-existing one to bypass it... + + if rlIsRHELLike '>9' || rlIsFedora + then + WORKAROUND="LC_PAPER='smth'" + fi - rlRun "> /etc/papersize" 0 "remove content of /etc/papersize file" - rlRun "paperconf | grep 'letter'" 0 "value from papersize should now defaults to 'letter'" + rlRun "echo a5 >/etc/papersize" 0 "filling papersize with a5 paper" + rlRun "${WORKAROUND:""} paperconf | grep 'a5'" 0 "value from papersize" + + rlRun "echo as > /etc/papersize" 0 "filling papersize with nonsence" + rlRun "${WORKAROUND:""} paperconf |& grep 'unknown paper'" 0 "value from papersize, nonsence" + + rlRun "> /etc/papersize" 0 "remove content of /etc/papersize file" + rlRun "paperconf | grep 'letter'" 0 "value from papersize should now defaults to 'letter'" + else + rlLog "paperconf is not found..." + + if rlIsRHELLike "<11" + then + rlFail "paperconf has to be available on RHEL < 11" + fi + fi rlPhaseEnd + rlPhaseStartTest "paper" + if test -x /usr/bin/paper + then + rlRun "paper | grep 'Letter: 8.5x11 in'" 0 "The default is letter" + rlRun "paper --unit mm | grep '215.9x279.4 mm'" 0 "Try mm units" + rlRun "paper --unit pt | grep '612x792 pt'" 0 "Try pt units" + rlRun "paper --unit in | grep '8.5x11 in'" 0 "Try inch units" + rlRun "paper --all | grep 'A4'" 0 "Check if listing works" + rlAssertEquals "Check without sizes" $(paper --no-size) "Letter" + + #changing PAPERSIZE variable + rlRun "PAPERSIZE=a4 paper | grep 'A4'" 0 "value from papersize" + rlRun "PAPERSIZE=as paper |& grep 'unknown paper'" 0 "value from papersize with non-existent PAPARSIZE value inserted" + + #changing LC_PAPER + rlRun "LC_PAPER='C.utf8' paper | grep 'A4'" + rlRun "LC_PAPER='' paper | grep 'Letter'" + + #changing paper size value through /etc/papersize file - currently glibc sets LC_PAPER by default + #with some locale, so we have to fill non-existing one to bypass it... + rlRun "echo a5 >/etc/papersize" 0 "filling papersize with a5 paper" + rlRun "LC_PAPER='smth' paper | grep 'A5'" 0 "value from papersize" + + rlRun "echo as > /etc/papersize" 0 "filling papersize with nonsence" + rlRun "LC_PAPER='smth' paper |& grep 'unknown paper'" 0 "value from papersize, nonsence" + + rlRun "> /etc/papersize" 0 "remove content of /etc/papersize file" + rlRun "paper | grep 'Letter'" 0 "value from papersize should now defaults to 'letter'" + else + rlLog "paper not found..." + + if rlIsFedora || rlIsRHELLike '>9' + then + rlFail "paper has to be present on Fedora and RHEL > 9" + fi + fi + rlPhaseEnd + + rlPhaseStartCleanup PAPERSIZE=$SIZEBCKUP PAPERCONF=$CONFBCKUP - rlRun "rlFileRestore" 0 " restoring papersize" + if rlIsRHELLike '<10' + then + rlRun "rlFileRestore" 0 " restoring papersize" + fi rlRun "popd" rlRun "rm -r $TmpDir" 0 "Removing tmp directory" rlPhaseEnd