From 7d9e230c72bca185dda8a204c51cd07553926463 Mon Sep 17 00:00:00 2001 From: sshil Date: Thu, 9 Jan 2025 13:47:29 +0530 Subject: [PATCH] Add tmt testcase for CI --- .fmf/version | 1 + plans/itstool.fmf | 20 +++++++++++++++ tests/main.fmf | 4 +++ tests/run_tests.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test.xml | 3 +++ 5 files changed, 90 insertions(+) create mode 100644 .fmf/version create mode 100644 plans/itstool.fmf create mode 100644 tests/main.fmf create mode 100644 tests/run_tests.sh create mode 100644 tests/test.xml 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/itstool.fmf b/plans/itstool.fmf new file mode 100644 index 0000000..57a4187 --- /dev/null +++ b/plans/itstool.fmf @@ -0,0 +1,20 @@ +summary: Basic smoke test for itstool +discover: + how: fmf +execute: + how: tmt +prepare: + - name: ensure-test-xml + how: shell + script: | + echo "Current directory: $(pwd)" + echo "Listing files in the current directory:" + ls -l + echo "Checking if test.xml is available in the VM..." + if [ ! -f /usr/share/doc/itstool/examples/test.xml ]; then + echo "test.xml not found, copying it..." + mkdir -p /usr/share/doc/itstool/examples/ + cp tests/test.xml /usr/share/doc/itstool/examples/ + else + echo "test.xml found!" + fi diff --git a/tests/main.fmf b/tests/main.fmf new file mode 100644 index 0000000..28728f3 --- /dev/null +++ b/tests/main.fmf @@ -0,0 +1,4 @@ +require: +- itstool +test: bash ./run_tests.sh +framework: shell diff --git a/tests/run_tests.sh b/tests/run_tests.sh new file mode 100644 index 0000000..ca2c18b --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,62 @@ +#!/bin/bash -e + +# Debugging: Ensure the file exists +echo "Checking for /usr/share/doc/itstool/examples/test.xml..." +ls -l /usr/share/doc/itstool/examples/test.xml || exit 1 + +# Proceed with the test +cp /usr/share/doc/itstool/examples/test.xml /tmp/itstool_test/ +itstool /tmp/itstool_test/test.xml -o /tmp/itstool_test/test.generated.po +diff /tmp/itstool_test/test.expected.po /tmp/itstool_test/test.generated.po + +# Define directories for output +OUTPUT_DIR="/tmp/itstool_test" +mkdir -p "$OUTPUT_DIR" + +# Test data +TEST_XML="/usr/share/doc/itstool/examples/test.xml" +EXPECTED_PO="$OUTPUT_DIR/test.expected.po" +GENERATED_PO="$OUTPUT_DIR/test.generated.po" +NORMALIZED_PO="$OUTPUT_DIR/test.normalized.po" + +# Create expected output +cat > "$EXPECTED_PO" <\\n" +"Language-Team: LANGUAGE \\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=UTF-8\\n" +"Content-Transfer-Encoding: 8bit\\n" + +#. (itstool) path: root/greeting +#: test.xml:2 +msgid "Hello, World!" +msgstr "" + +EOF + +# Copy test XML file +cp "$TEST_XML" "$OUTPUT_DIR/test.xml" + +# Run itstool to generate PO file +itstool -o "$GENERATED_PO" "$OUTPUT_DIR/test.xml" + +# Normalize the generated PO file +sed -e "s|POT-Creation-Date: .*|POT-Creation-Date: DATE_PLACEHOLDER\"|" \ + -e "s|#: .*test.xml|#: test.xml|g" \ + "$GENERATED_PO" > "$NORMALIZED_PO" + +# Compare normalized PO file with expected output +if diff -u "$EXPECTED_PO" "$NORMALIZED_PO"; then + echo "PASS: itstool successfully generated the expected PO file." +else + echo "FAIL: The generated PO file does not match the expected output." + echo "Expected: $EXPECTED_PO" + echo "Generated: $NORMALIZED_PO" + exit 1 +fi + diff --git a/tests/test.xml b/tests/test.xml new file mode 100644 index 0000000..0081e38 --- /dev/null +++ b/tests/test.xml @@ -0,0 +1,3 @@ + + Hello, World! +