Browse Source

support COLUMNS environment variable in apt tools

apt usually gets the width of the window from the terminal or failing
that has a default value, but especially for testing it can be handy
to control the size as you can't be sure that variable sized content
will always be linebreaked as expected in the testcases.
tags/debian/1.6_alpha6
David Kalnischkies 3 years ago
parent
commit
3f8664036e
3 changed files with 44 additions and 6 deletions
  1. +18
    -2
      apt-private/private-output.cc
  2. +13
    -0
      test/integration/test-00-commands-have-help
  3. +13
    -4
      test/integration/test-kernel-helper-autoremove

+ 18
- 2
apt-private/private-output.cc View File

@@ -67,8 +67,24 @@ bool InitOutput(std::basic_streambuf<char> * const out) /*{{{*/
c1out.rdbuf(devnull.rdbuf());

// deal with window size changes
signal(SIGWINCH,SigWinch);
SigWinch(0);
auto cols = getenv("COLUMNS");
if (cols != nullptr)
{
char * colends;
auto const sw = strtoul(cols, &colends, 10);
if (*colends != '\0' || sw == 0)
{
_error->Warning("Environment variable COLUMNS was ignored as it has an invalid value: \"%s\"", cols);
cols = nullptr;
}
else
ScreenWidth = sw;
}
if (cols == nullptr)
{
signal(SIGWINCH,SigWinch);
SigWinch(0);
}

if(!isatty(1))
{


+ 13
- 0
test/integration/test-00-commands-have-help View File

@@ -86,3 +86,16 @@ testmoo '@1484822790' 'Have you mooed today?'
testmoo '@1484822791' 'Have you mooed today?'
testmoo '@1484822792' 'Have you mooed today?'
testmoo '@1484822793' 'Have you mooed today?'

# that also helps with reproducibility of output…
export COLUMNS=80
testsuccess aptget moo
export COLUMNS=0
testwarning aptget moo
export COLUMNS=80a
testwarning aptget moo
export COLUMNS=a80
testwarning aptget moo
export COLUMNS=
testwarning aptget moo
unset COLUMNS

+ 13
- 4
test/integration/test-kernel-helper-autoremove View File

@@ -116,16 +116,17 @@ msgmsg "run without parameter"
testprotected
msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
export COLUMNS=99999
testsuccessequal "Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
${CURRENTKERNEL}-dbg
linux-headers-1000000-1-generic linux-image-1.0.0-2-generic ${CURRENTKERNEL}-dbg
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
Remv linux-headers-1000000-1-generic [100.0.0-1]
Remv linux-image-1.0.0-2-generic [1.0.0-2]
Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
unset COLUMNS

msgmsg "install unknown kernel"
# even if installed/uname reports a kernel which we can't find via dpkg,
@@ -136,32 +137,39 @@ msgtest 'Check kernel autoremoval protection list does not include' 'old kernel'
testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel'
testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list
export COLUMNS=9
testsuccessequal "Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
linux-headers-1000000-1-generic linux-image-1.0.0-2-generic
linux-headers-1000000-1-generic
linux-image-1.0.0-2-generic
${CURRENTKERNEL}-dbg
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
Remv linux-headers-1000000-1-generic [100.0.0-1]
Remv linux-image-1.0.0-2-generic [1.0.0-2]
Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
unset COLUMNS

msgmsg "install an old kernel"
testprotected 1.0.0-2-generic
msgtest 'Check kernel autoremoval protection list includes' 'installed kernel'
testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list
export COLUMNS=9
testsuccessequal "Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
linux-headers-1000000-1-generic ${CURRENTKERNEL}-dbg
linux-headers-1000000-1-generic
${CURRENTKERNEL}-dbg
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
Remv linux-headers-1000000-1-generic [100.0.0-1]
Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
unset COLUMNS

# rt kernel was put on hold while the protected list was generated
testsuccess aptmark unhold "${CURRENTKERNEL}-rt"
export COLUMNS=99999
testsuccessequal "Reading package lists...
Building dependency tree...
Reading state information...
@@ -170,3 +178,4 @@ The following packages will be REMOVED:
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
Remv linux-headers-1000000-1-generic [100.0.0-1]
Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -s
unset COLUMNS

Loading…
Cancel
Save