From bc6341483802340433886c9297cbc905295431a5 Mon Sep 17 00:00:00 2001 From: matiwari Date: Tue, 6 Aug 2024 23:45:01 +0530 Subject: [PATCH] CI gating tests migration to tmt --- .fmf/version | 1 + intltool.spec | 5 +- plans/basic.fmf | 5 ++ tests/cases/context.xml | 19 ++++++ tests/cases/context.xml.in | 17 +++++ tests/cases/context.xml.in.h | 7 +++ tests/intltool_tests.py | 109 +++++++++++++++++++++++++++++++++ tests/main.fmf | 6 ++ tests/results/context.xml | 19 ++++++ tests/results/context.xml.in.h | 7 +++ tests/test.sh | 25 ++++++++ 11 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 .fmf/version create mode 100644 plans/basic.fmf create mode 100644 tests/cases/context.xml create mode 100644 tests/cases/context.xml.in create mode 100644 tests/cases/context.xml.in.h create mode 100644 tests/intltool_tests.py create mode 100644 tests/main.fmf create mode 100644 tests/results/context.xml create mode 100644 tests/results/context.xml.in.h create mode 100755 tests/test.sh 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/intltool.spec b/intltool.spec index 87b83be..095af57 100644 --- a/intltool.spec +++ b/intltool.spec @@ -1,7 +1,7 @@ Name: intltool Summary: Utility for internationalizing various kinds of data files Version: 0.51.0 -Release: 27%{?dist} +Release: 28%{?dist} License: GPL-2.0-or-later WITH Autoconf-exception-generic #VCS: bzr:https://code.edge.launchpad.net/~intltool/intltool/trunk Source: https://edge.launchpad.net/intltool/trunk/%{version}/+download/intltool-%{version}.tar.gz @@ -69,6 +69,9 @@ fi %{_mandir}/man8/intltool*.8* %changelog +* Tue Aug 6 2024 Manish Tiwari - 0.51.0-28 +- CI gating tests migration to tmt + * Mon Jun 24 2024 Troy Dawson - 0.51.0-27 - Bump release for June 2024 mass rebuild 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/cases/context.xml b/tests/cases/context.xml new file mode 100644 index 0000000..e21ad0e --- /dev/null +++ b/tests/cases/context.xml @@ -0,0 +1,19 @@ + + + <_name>Foo + + + + <_name msgctxt="1"> +Bar + + + + <_name msgctxt="2"> +Bar + + + + <_name>Baz + + diff --git a/tests/cases/context.xml.in b/tests/cases/context.xml.in new file mode 100644 index 0000000..4b58d97 --- /dev/null +++ b/tests/cases/context.xml.in @@ -0,0 +1,17 @@ + + + <_name>Foo + + + + <_name msgctxt="1">Bar + + + + <_name msgctxt="2">Bar + + + + <_name>Baz + + diff --git a/tests/cases/context.xml.in.h b/tests/cases/context.xml.in.h new file mode 100644 index 0000000..161a65b --- /dev/null +++ b/tests/cases/context.xml.in.h @@ -0,0 +1,7 @@ +char *s = N_("Foo"); +/* This is the comment on the first Bar */ +char *s = C_("1", "Bar"); +/* This is the comment on the second Bar */ +char *s = C_("2", "Bar"); +/* This is the comment on Baz */ +char *s = N_("Baz"); diff --git a/tests/intltool_tests.py b/tests/intltool_tests.py new file mode 100644 index 0000000..4a0ffa2 --- /dev/null +++ b/tests/intltool_tests.py @@ -0,0 +1,109 @@ +#!/usr/bin/python3 + +import logging +import subprocess +from difflib import Differ + +logging.basicConfig(level=logging.INFO) + + +COMMANDS = [ + "intltool-extract", + "intltool-merge" + ] +INPUT_FILE = "cases/context.xml.in" + + +def test_intltool_installation(cmd: str): + """ + Check if intltool is installed correctly + """ + try: + intltool_cmd = subprocess.Popen([cmd], stdout=subprocess.PIPE) + intltool_cmd_execution_response = intltool_cmd.communicate() + assert "Usage" in str(intltool_cmd_execution_response) + except FileNotFoundError: + logging.error(f"Either {cmd} is not installed or not accessible.") + except OSError: + logging.error(f"Some OSError occurred while executing {cmd}") + except AssertionError: + logging.error(f"[CMD] output does not include text: Usage.") + else: + logging.info(f"Execution of {cmd} succeed. Test Passed.") + + +def test_intltool_extract(cmd, input_file): + """ + Check intltool extract behavior + """ + try: + intltool_extract = subprocess.Popen( + [cmd, "--type=gettext/xml", input_file, "--update"], + stdout=subprocess.PIPE) + intltool_extract_execution_response = intltool_extract.communicate() + assert "Wrote" in str(intltool_extract_execution_response) + except AssertionError: + logging.error(f"Writing output file for {input_file} file failed.") + except Exception as e: + logging.error(e) + else: + logging.info(f"Writing output file for {input_file} succeed.") + + comparison_test_pass = True + with open("{}.h".format(input_file)) as output_file, open("results/{}.h".format("context.xml.in")) as refer_file: + differ = Differ() + for line in differ.compare(output_file.readlines(), refer_file.readlines()): + if line.startswith("+") or line.startswith("-"): + comparison_test_pass = False + + try: + assert comparison_test_pass + except AssertionError: + logging.error("Extracted file does NOT match with the result. Test failed.") + else: + logging.info("Extracted file does match with the result. Test passed.") + + +def test_intltool_merge(cmd, input_file): + """ + Check intltool merge behavior + """ + merged_file = "context.xml" + try: + intltool_merge = subprocess.Popen( + [cmd, "-o", "cases", input_file, "cases/{}".format(merged_file)], + stdout=subprocess.PIPE) + intltool_merge_execution_response = intltool_merge.communicate() + assert "Merging" in str(intltool_merge_execution_response) + except AssertionError: + logging.error(f"Writing output file for {input_file} file failed.") + except Exception as e: + logging.error(e) + else: + logging.info(f"Writing output file for {input_file} succeed.") + + comparison_test_pass = True + with open("cases/{}".format(merged_file)) as output_file, open("results/{}".format(merged_file)) as refer_file: + differ = Differ() + for line in differ.compare(output_file.readlines(), refer_file.readlines()): + if line.startswith("+") or line.startswith("-"): + comparison_test_pass = False + + try: + assert comparison_test_pass + except AssertionError: + logging.error("Merged file does NOT match with the result. Test failed.") + else: + logging.info("Merged file does match with the result. Test passed.") + + +if __name__ == "__main__": + """ + Executes test cases + """ + logging.info("Executing test cases for Intltool..") + for CMD in COMMANDS: + test_intltool_installation(CMD) + test_intltool_extract(COMMANDS[0], INPUT_FILE) + test_intltool_merge(COMMANDS[1], INPUT_FILE) + logging.info("Tests execution of Intltool completed!") diff --git a/tests/main.fmf b/tests/main.fmf new file mode 100644 index 0000000..278bfa9 --- /dev/null +++ b/tests/main.fmf @@ -0,0 +1,6 @@ +summary: Run intltool test +test: ./test.sh +framework: beakerlib +require: + - intltool + - python3 diff --git a/tests/results/context.xml b/tests/results/context.xml new file mode 100644 index 0000000..e21ad0e --- /dev/null +++ b/tests/results/context.xml @@ -0,0 +1,19 @@ + + + <_name>Foo + + + + <_name msgctxt="1"> +Bar + + + + <_name msgctxt="2"> +Bar + + + + <_name>Baz + + diff --git a/tests/results/context.xml.in.h b/tests/results/context.xml.in.h new file mode 100644 index 0000000..161a65b --- /dev/null +++ b/tests/results/context.xml.in.h @@ -0,0 +1,7 @@ +char *s = N_("Foo"); +/* This is the comment on the first Bar */ +char *s = C_("1", "Bar"); +/* This is the comment on the second Bar */ +char *s = C_("2", "Bar"); +/* This is the comment on Baz */ +char *s = N_("Baz"); diff --git a/tests/test.sh b/tests/test.sh new file mode 100755 index 0000000..35c7015 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="intltool" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "TmpDir=\`mktemp -d\`" 0 "Creating tmp directory" + rlRun "cp -r cases results intltool_tests.py $TmpDir" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlLog "Run intltool_tests.py" + rlRun "python3 intltool_tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd