Skip to content

Commit

Permalink
Changes for CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Oct 1, 2023
1 parent cc01c5c commit 715e3d3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 125 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.71])

AC_INIT(
[liblnk],
[20230928],
[20231001],
[[email protected]])

AC_CONFIG_SRCDIR(
Expand Down
4 changes: 2 additions & 2 deletions liblnk.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<package >
<metadata>
<id>liblnk</id>
<version>20230928</version>
<version>20231001</version>
<authors>Joachim Metz</authors>
<owners>joachimmetz</owners>
<license type="expression">LGPL-3.0-or-later</license>
<projectUrl>https://github.com/libyal/liblnk</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<title>liblnk</title>
<description>Library to access the Windows Shortcut File (LNK) format</description>
<releaseNotes>Release of liblnk 20230928</releaseNotes>
<releaseNotes>Release of liblnk 20231001</releaseNotes>
<copyright>Copyright (C) 2009-2023</copyright>
<tags>native</tags>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions tests/lnk_test_libcpath.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The internal libcpath header
* The libcpath header wrapper
*
* Copyright (C) 2009-2022, Joachim Metz <[email protected]>
* Copyright (C) 2009-2023, Joachim Metz <[email protected]>
*
* Refer to AUTHORS for acknowledgements.
*
Expand Down
70 changes: 42 additions & 28 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@
#
# Script to run Python test scripts.
#
# Copyright (C) 2009-2023, Joachim Metz <[email protected]>
#
# Refer to AUTHORS for acknowledgements.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Version: 20231001

import glob
import os
import sys
import unittest


test_profile = ".pylnk"
input_glob = "*.lnk"
option_sets = []


def ReadIgnoreList(test_profile):
"""Reads the test profile ignore file if it exists.
Args:
test_profile (str): test profile.
Returns:
set[str]: ignore list.
"""
ignore_file_path = os.path.join("tests", "input", test_profile, "ignore")
if os.path.isfile(ignore_file_path):
with open(ignore_file_path, "r", encoding="utf-8") as file_object:
return set([line.strip() for line in file_object.readlines()])

return set()


if __name__ == "__main__":
print(f"Using Python version {sys.version!s}")

Expand All @@ -33,30 +40,37 @@

test_scripts = test_loader.discover("tests", pattern="*.py")

test_profile = ".pylnk"
input_glob = "*.lnk"

ignore_list = set()

ignore_file_path = f"tests/input/{test_profile}/ignore"
if os.path.isfile(ignore_file_path):
with open(ignore_file_path, "r", encoding="utf-8") as file_object:
ignore_list = set([line.strip() for line in file_object.readlines()])
ignore_list = ReadIgnoreList(test_profile)

test_set = None
source_file = None

for test_set in glob.glob("tests/input/*"):
test_set = test_set.rsplit('/', maxsplit=1)[-1]
for test_set in glob.glob(os.path.join("tests", "input", "*")):
test_set = test_set.rsplit(os.path.sep, maxsplit=1)[-1]
if not test_set or test_set[0] == '.' or test_set in ignore_list:
continue

source_files = glob.glob(f"tests/input/{test_set:s}/{input_glob:s}")
source_files = glob.glob(os.path.join(
"tests", "input", test_set, input_glob))
if source_files:
source_file = source_files[0]
break

setattr(unittest, "source", source_file)

for option_set in option_sets:
test_options = None

test_file = os.path.basename(source_file)
test_options_file_path = os.path.join(
"tests", "input", test_profile, test_set,
f"{test_file:s}.{option_set:s}")
if os.path.isfile(test_options_file_path):
with open(test_options_file_path, "r", encoding="utf-8") as file_object:
test_options = file_object.read().strip()

setattr(unittest, option_set, test_options)

test_results = test_runner.run(test_scripts)
if not test_results.wasSuccessful():
sys.exit(1)
56 changes: 18 additions & 38 deletions tests/test_library.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Tests library functions and types.
#
# Version: 20230410
# Version: 20231001

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand Down Expand Up @@ -78,47 +78,27 @@ run_test_with_input()

local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");

local OLDIFS=${IFS};

# IFS="\n" is not supported by all platforms.
IFS="
";

if test -f "${TEST_SET_DIRECTORY}/files";
then
for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`;
do
if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
IFS=$'\n' INPUT_FILES=( $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?") );
else
for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`;
do
if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
IFS=$'\n' INPUT_FILES=( $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}) );
fi
IFS=${OLDIFS};
for INPUT_FILE in ${INPUT_FILES[@]};
do
if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
Expand Down
41 changes: 13 additions & 28 deletions tests/test_python_module.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Tests Python module functions and types.
#
# Version: 20230410
# Version: 20231001

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand Down Expand Up @@ -68,37 +68,22 @@ test_python_function_with_input()

local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");

local OLDIFS=${IFS};

# IFS="\n"; is not supported by all platforms.
IFS="
";

if test -f "${TEST_SET_DIRECTORY}/files";
then
for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`;
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
IFS=$'\n' INPUT_FILES=( $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?") );
else
for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`;
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
IFS=$'\n' INPUT_FILES=( $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}) );
fi
IFS=${OLDIFS};
for INPUT_FILE in ${INPUT_FILES[@]};
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
Expand Down
39 changes: 13 additions & 26 deletions tests/test_runner.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Bash functions to run an executable for testing.
#
# Version: 20230410
# Version: 20231001
#
# When CHECK_WITH_ASAN is set to a non-empty value the test executable
# is run with asan, otherwise it is run without.
Expand Down Expand Up @@ -1258,35 +1258,22 @@ run_test_on_test_set_with_options()

local RESULT=${EXIT_SUCCESS};

# IFS="\n"; is not supported by all platforms.
IFS="
";

if test -f "${TEST_SET_DIRECTORY}/files";
then
for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`;
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "${TEST_MODE}" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
IFS=$'\n' INPUT_FILES=( $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?") );
else
for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`;
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "${TEST_MODE}" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
IFS=$'\n' INPUT_FILES=( $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}) );
fi
IFS=${OLDIFS};
for INPUT_FILE in ${INPUT_FILES[@]};
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "${TEST_MODE}" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done

return ${RESULT};
}
Expand Down

0 comments on commit 715e3d3

Please sign in to comment.