From bb00087b6cf6db68e3f56d41b59265d8438406e2 Mon Sep 17 00:00:00 2001 From: Mike FABIAN Date: Wed, 10 Jul 2024 16:45:33 +0200 Subject: [PATCH] Resolves: RHELMISC-5984 Add tmt based CI test --- .fmf/version | 1 + plans/basic.fmf | 5 +++++ tests/foma-input.txt | 3 +++ tests/main.fmf | 7 +++++++ tests/runtest.sh | 23 +++++++++++++++++++++++ tests/test_foma.py | 25 +++++++++++++++++++++++++ 6 files changed, 64 insertions(+) create mode 100644 .fmf/version create mode 100644 plans/basic.fmf create mode 100644 tests/foma-input.txt create mode 100644 tests/main.fmf create mode 100755 tests/runtest.sh create mode 100644 tests/test_foma.py diff --git a/.fmf/version b/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/plans/basic.fmf b/plans/basic.fmf new file mode 100644 index 0000000..c1627f9 --- /dev/null +++ b/plans/basic.fmf @@ -0,0 +1,5 @@ +summary: Basic smoke test +discover: + how: fmf +execute: + how: tmt diff --git a/tests/foma-input.txt b/tests/foma-input.txt new file mode 100644 index 0000000..bdb3098 --- /dev/null +++ b/tests/foma-input.txt @@ -0,0 +1,3 @@ +def Animals c a t | d o g ; +regex Animals+ ; +print defined diff --git a/tests/main.fmf b/tests/main.fmf new file mode 100644 index 0000000..9496f9c --- /dev/null +++ b/tests/main.fmf @@ -0,0 +1,7 @@ +framework: beakerlib +duration: 10m +require: +- foma +- python3 +test: ./runtest.sh + diff --git a/tests/runtest.sh b/tests/runtest.sh new file mode 100755 index 0000000..72376bb --- /dev/null +++ b/tests/runtest.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm python3 + rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" + rlRun "cp test_foma.py foma-input.txt $tmp" + rlRun "pushd $tmp" + rlPhaseEnd + + rlPhaseStartTest + rlRun "python3 test_foma.py -v" \ + 0 "Running test cases" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $tmp" 0 "Remove tmp directory" + rlPhaseEnd +rlJournalEnd diff --git a/tests/test_foma.py b/tests/test_foma.py new file mode 100644 index 0000000..53d3768 --- /dev/null +++ b/tests/test_foma.py @@ -0,0 +1,25 @@ +import unittest +import sys +import subprocess + +class TestFoma(unittest.TestCase): + + def test_dummy(self): + self.assertEqual(True, True) + + @unittest.expectedFailure + def test_expected_failure(self): + self.assertEqual(False, True) + + def test_foma(self): + cp = subprocess.run(['foma -f foma-input.txt'], encoding='UTF-8', text=True, shell=True, capture_output=True) + self.assertEqual( + 'defined Animals: 455 bytes. 6 states, 6 arcs, 2 paths.\n' + '471 bytes. 6 states, 8 arcs, Cyclic.\n' + 'Animals\t455 bytes. 6 states, 6 arcs, 2 paths.\n', + cp.stdout) + self.assertEqual('', cp.stderr) + self.assertEqual(0, cp.returncode) + +if __name__ == "__main__": + unittest.main()