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 a84333e
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 158 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)
71 changes: 37 additions & 34 deletions tests/test_library.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
# Tests library functions and types.
#
# Version: 20230410
# Version: 20231001

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;

LIBRARY_TESTS="data_block data_string distributed_link_tracker_properties error file_header io_handle known_folder_location link_target_identifier location_information notify special_folder_location";
LIBRARY_TESTS_WITH_INPUT="file support";
OPTION_SETS="";
OPTION_SETS=();

INPUT_GLOB="*";

Expand Down Expand Up @@ -78,47 +78,50 @@ 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}/?"`;
IFS=$'\n' INPUT_FILES=( $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?") );
else
IFS=$'\n' INPUT_FILES=( $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}) );
fi
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
local TESTED_WITH_OPTIONS=0;

for OPTION_SET in ${OPTION_SETS[@]};
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=$?;
local TEST_DATA_OPTION_FILE=$(get_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");

if test ${RESULT} -ne ${EXIT_SUCCESS};
if test -f ${TEST_DATA_OPTION_FILE};
then
break;
TESTED_WITH_OPTIONS=1;

run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SET}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
fi
done
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}";

if ${TESTED_WITH_OPTIONS} -eq 0;
then
run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;
fi

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

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
Expand Down
53 changes: 46 additions & 7 deletions tests/test_lnkinfo.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
# Info tool testing script
#
# Version: 20230410
# Version: 20231001

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;

PROFILES=("lnkinfo");
OPTIONS_PER_PROFILE=("");
OPTION_SETS="";
OPTION_SETS=();

INPUT_GLOB="*";

Expand Down Expand Up @@ -89,14 +89,53 @@ do
fi
TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");

run_test_on_test_set_with_options "${TEST_SET_DIRECTORY}" "lnkinfo" "with_stdout_reference" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${OPTIONS[@]}";
RESULT=$?;
RESULT=${EXIT_SUCCESS};

# Ignore failures due to corrupted data.
if test "${TEST_SET}" = "corrupted";
if test -f "${TEST_SET_DIRECTORY}/files";
then
RESULT=${EXIT_SUCCESS};
IFS=$'\n' INPUT_FILES=( $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?") );
else
IFS=$'\n' INPUT_FILES=( $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}) );
fi
for INPUT_FILE in ${INPUT_FILES[@]};
do
TESTED_WITH_OPTIONS=0;

for OPTION_SET in ${OPTION_SETS[@]};
do
TEST_DATA_OPTION_FILE=$(get_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");

if test -f ${TEST_DATA_OPTION_FILE};
then
TESTED_WITH_OPTIONS=1;

run_test_on_input_file "${TEST_SET_DIRECTORY}" "lnkinfo" "with_stdout_reference" "${OPTION_SET}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;

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

if ${TESTED_WITH_OPTIONS} -eq 0;
then
run_test_on_input_file "${TEST_SET_DIRECTORY}" "lnkinfo" "with_stdout_reference" "" "${TEST_EXECUTABLE}" "${INPUT_FILE}" ${ARGUMENTS[@]};
RESULT=$?;
fi

# Ignore failures due to corrupted data.
if test "${TEST_SET}" = "corrupted";
then
RESULT=${EXIT_SUCCESS};
fi
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
Expand Down
Loading

0 comments on commit a84333e

Please sign in to comment.