add tests of 'cmdtest.py' in t/ subdir
This commit is contained in:
parent
f0e6f5c281
commit
a65f019e51
42
python/t/CMDTEST_exit_nonzero.py
Normal file
42
python/t/CMDTEST_exit_nonzero.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
|
||||||
|
from selftest_utils import SelftestUtils
|
||||||
|
|
||||||
|
class TC_exit_nonzero(SelftestUtils, TestCase):
|
||||||
|
|
||||||
|
def test_exit_nonzero_CORRECT(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("false") as c:',
|
||||||
|
' c.exit_nonzero()',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: false",
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_exit_nonzero_INCORRECT(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("true") as c:',
|
||||||
|
' c.exit_nonzero()',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: true",
|
||||||
|
"--- ERROR: exit_nonzero",
|
||||||
|
"actual: 0",
|
||||||
|
"expect: <nonzero value>",
|
||||||
|
"",
|
||||||
|
])
|
||||||
|
c.exit_nonzero()
|
||||||
|
|
||||||
|
def test_exit_nonzero_CORRECT_18(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("exit 18") as c:',
|
||||||
|
' c.exit_nonzero()',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: exit 18",
|
||||||
|
])
|
47
python/t/CMDTEST_exit_zero.py
Normal file
47
python/t/CMDTEST_exit_zero.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
from selftest_utils import SelftestUtils
|
||||||
|
|
||||||
|
class TC_exit_zero(SelftestUtils, TestCase):
|
||||||
|
|
||||||
|
def test_exit_zero_CORRECT(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("true") as c:',
|
||||||
|
' c.exit_zero()',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: true",
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_exit_zero_INCORRECT(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("false") as c:',
|
||||||
|
' c.exit_zero()',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: false",
|
||||||
|
"--- ERROR: exit_zero",
|
||||||
|
"actual: 1",
|
||||||
|
"expect: 0",
|
||||||
|
"",
|
||||||
|
])
|
||||||
|
c.exit_nonzero()
|
||||||
|
|
||||||
|
def test_exit_zero_INCORRECT_18(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("exit 18") as c:',
|
||||||
|
' c.exit_zero()',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: exit 18",
|
||||||
|
"--- ERROR: exit_zero",
|
||||||
|
"actual: 18",
|
||||||
|
"expect: 0",
|
||||||
|
"",
|
||||||
|
])
|
||||||
|
c.exit_nonzero()
|
71
python/t/CMDTEST_stdout_equal.py
Normal file
71
python/t/CMDTEST_stdout_equal.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
from selftest_utils import SelftestUtils
|
||||||
|
|
||||||
|
class TC_stdout_equal(SelftestUtils, TestCase):
|
||||||
|
|
||||||
|
def test_stdout_equal_CORRECT_EMPTY(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("true") as c:',
|
||||||
|
' c.stdout_equal([',
|
||||||
|
' ])',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: true",
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_stdout_equal_INCORRECT_EMPTY(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("echo hello") as c:',
|
||||||
|
' c.stdout_equal([',
|
||||||
|
' ])',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: echo hello",
|
||||||
|
"--- ERROR: stdout_equal",
|
||||||
|
"actual:",
|
||||||
|
" hello",
|
||||||
|
"expect:",
|
||||||
|
" <<empty>>",
|
||||||
|
])
|
||||||
|
c.exit_nonzero()
|
||||||
|
|
||||||
|
def test_stdout_equal_CORRECT_2_LINES(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("echo hello && echo world") as c:',
|
||||||
|
' c.stdout_equal([',
|
||||||
|
' "hello",',
|
||||||
|
' "world",',
|
||||||
|
' ])',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: echo hello && echo world",
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_stdout_equal_INCORRECT_2_LINES(self):
|
||||||
|
self.create_CMDTEST_foo(
|
||||||
|
'with self.cmd("echo hello && echo world && echo MORE") as c:',
|
||||||
|
' c.stdout_equal([',
|
||||||
|
' "hello",',
|
||||||
|
' "world",',
|
||||||
|
' ])',
|
||||||
|
)
|
||||||
|
|
||||||
|
with self.cmd_cmdtest() as c:
|
||||||
|
c.stdout_equal([
|
||||||
|
"### cmdline: echo hello && echo world && echo MORE",
|
||||||
|
"--- ERROR: stdout_equal",
|
||||||
|
"actual:",
|
||||||
|
" hello",
|
||||||
|
" world",
|
||||||
|
" MORE",
|
||||||
|
"expect:",
|
||||||
|
" hello",
|
||||||
|
" world",
|
||||||
|
])
|
||||||
|
c.exit_nonzero()
|
30
python/t/selftest_utils.py
Normal file
30
python/t/selftest_utils.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
|
||||||
|
import os
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
TOP = os.getcwd()
|
||||||
|
|
||||||
|
class SelftestUtils:
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.always_ignore_file('tmp-cmdtest-python/')
|
||||||
|
|
||||||
|
def create_CMDTEST_foo(self, *lines):
|
||||||
|
self.create_file("CMDTEST_foo.py", [
|
||||||
|
"class TC_foo(TestCase):",
|
||||||
|
" def setup(self):",
|
||||||
|
" #prepend_path #{BIN.inspect}",
|
||||||
|
" #prepend_path #{PLATFORM_BIN.inspect}",
|
||||||
|
" pass",
|
||||||
|
"",
|
||||||
|
" def test_foo(self):",
|
||||||
|
[ " " + line for line in lines],
|
||||||
|
])
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def cmd_cmdtest(self, *args):
|
||||||
|
cmdtest = "%s/cmdtest.py" % TOP
|
||||||
|
command = "%s --quiet CMDTEST_foo.py" % cmdtest
|
||||||
|
cmdline = ' '.join([command] + list(args))
|
||||||
|
with self.cmd(cmdline) as c:
|
||||||
|
yield c
|
Loading…
x
Reference in New Issue
Block a user