From 784ceb4937ab0a0e7c2beb17ac773de3d8d4ad14 Mon Sep 17 00:00:00 2001 From: clanmills Date: Fri, 2 Oct 2020 18:36:57 +0100 Subject: [PATCH 01/11] nls-test script and reference file. --- test/data/nls-test.out | 10 +++++++++ test/nls-test.sh | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 test/data/nls-test.out create mode 100755 test/nls-test.sh diff --git a/test/data/nls-test.out b/test/data/nls-test.out new file mode 100644 index 00000000..9312e3fa --- /dev/null +++ b/test/data/nls-test.out @@ -0,0 +1,10 @@ +exiv2: Une action doit être spécifié +exiv2: Au moins un fichier est nécessaire +Utilisation : exiv2 [ options ] [ action ] fichier ... + +Manipulation des métadonnées EXIF issues des images. +exiv2: Se debe especificar una acción +exiv2: Se requiere un archivo al menos +Uso: exiv2 [ opciones ] [ acción ] archivo ... + +manipular los metadatos Exif de las imágenes. diff --git a/test/nls-test.sh b/test/nls-test.sh new file mode 100755 index 00000000..220045b1 --- /dev/null +++ b/test/nls-test.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# Test driver for exiv2.exe nls support + +source ./functions.source + +( cd "$testdir" + nls=$(runTest exiv2 -vVg nls|tail -1) + platform=$(runTest exiv2 -vVg platform|tail -1) + if [ "$nls" != "enable_nls=1" ]; then + echo "exiv2 not bulid with nls" + exit 0 + fi + if [ "$platform" == "platform=windows" ]; then + echo "nls_test cannot be run msvc builds" >2 + exit 0 + fi + if [ "$platform" == "platform=linux" ]; then + LANG=LANGUAGE + else + LANG=LANG + fi + ## + # if necessary ditto /usr/local/share/locale -> build/share/locale + share=${bin}../share + if [ ! -e $share ]; then + mkdir -p $share + fi + usr=/usr/local/share/locale + if [ -e "$usr" -a -e "$share" ]; then + cp -r "$usr" "$share" + else + echo "localisation files are not installed in $usr" + exit 0 + fi + ## + # test a couple of languages + for l in fr_FR es_ES; do + LC_ALL=$l LANG=$l ${bin}exiv2 + done + +) 3>&1 > $results 2>&1 + +reportTest + +# That's all Folks! +## From e103fb846439d943c60672efad9f78cfe9bd6c50 Mon Sep 17 00:00:00 2001 From: clanmills Date: Fri, 2 Oct 2020 18:37:36 +0100 Subject: [PATCH 02/11] Makefile updated to run nls-test.sh as part of bash_tests --- test/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Makefile b/test/Makefile index b5a745c5..0af7cf29 100644 --- a/test/Makefile +++ b/test/Makefile @@ -83,6 +83,7 @@ TESTS = addmoddel.sh \ iotest.sh \ iptctest.sh \ iso65k-test.sh \ + nls-test.sh \ modify-test.sh \ path-test.sh \ preview-test.sh \ @@ -110,6 +111,7 @@ exiv2-test \ imagetest \ iotest \ iptctest \ +nls-test \ preview-test \ tiff-test \ write-test \ From 73069e36cfafb14cfbc9f6f7fa019da34686dd79 Mon Sep 17 00:00:00 2001 From: clanmills Date: Sun, 11 Oct 2020 19:07:09 +0100 Subject: [PATCH 03/11] Enable CentOS on gitLab-ci. --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da665139..d01a90f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,10 +59,10 @@ Ubuntu: <<: *default_config <<: *distro_build -# CentOS: -# image: centos:7 -# <<: *default_config -# <<: *distro_build +CentOS: + image: centos:7 + <<: *default_config + <<: *distro_build OpenSUSE: image: opensuse/tumbleweed From d300f3d812bb35d255c133ac82424feafe417523 Mon Sep 17 00:00:00 2001 From: clanmills Date: Sun, 11 Oct 2020 19:44:50 +0100 Subject: [PATCH 04/11] Temporarily neuter DEXIV2_TEAM_USE_SANITIZERS to get CentOS to build. --- cmake/compilerFlags.cmake | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index ed0e1e33..7b682531 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -58,36 +58,36 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN #add_compile_options(-fasynchronous-unwind-tables) - if ( EXIV2_TEAM_USE_SANITIZERS ) - # ASAN is available in gcc from 4.8 and UBSAN from 4.9 - # ASAN is available in clang from 3.1 and UBSAN from 3.3 - # UBSAN is not fatal by default, instead it only prints runtime errors to stderr - # => make it fatal with -fno-sanitize-recover (gcc) or -fno-sanitize-recover=all (clang) - # add -fno-omit-frame-pointer for better stack traces - if ( COMPILER_IS_GCC ) - if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) - set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover") - elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8 ) - set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") - endif() - elseif( COMPILER_IS_CLANG ) - if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) - set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all") - elseif ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4 ) - set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined") - elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.1 ) - set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") - endif() - endif() - - # sorry, ASAN does not work on Windows - if ( NOT CYGWIN AND NOT MINGW AND NOT MSYS ) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS}") - endif() - endif() +# if ( EXIV2_TEAM_USE_SANITIZERS ) +# # ASAN is available in gcc from 4.8 and UBSAN from 4.9 +# # ASAN is available in clang from 3.1 and UBSAN from 3.3 +# # UBSAN is not fatal by default, instead it only prints runtime errors to stderr +# # => make it fatal with -fno-sanitize-recover (gcc) or -fno-sanitize-recover=all (clang) +# # add -fno-omit-frame-pointer for better stack traces +# if ( COMPILER_IS_GCC ) +# if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) +# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover") +# elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8 ) +# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") +# endif() +# elseif( COMPILER_IS_CLANG ) +# if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) +# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all") +# elseif ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4 ) +# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined") +# elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.1 ) +# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") +# endif() +# endif() +# +# # sorry, ASAN does not work on Windows +# if ( NOT CYGWIN AND NOT MINGW AND NOT MSYS ) +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}") +# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}") +# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}") +# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS}") +# endif() +# endif() endif() endif () From 11082c13d0e4f5848a2fd824c1a28dc1f7c9825f Mon Sep 17 00:00:00 2001 From: clanmills Date: Sun, 11 Oct 2020 19:59:28 +0100 Subject: [PATCH 05/11] Revert the last two changes. GitLab/centOS makes no sense. Will build on MacMini. --- .gitlab-ci.yml | 8 +++--- cmake/compilerFlags.cmake | 60 +++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d01a90f2..da665139 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,10 +59,10 @@ Ubuntu: <<: *default_config <<: *distro_build -CentOS: - image: centos:7 - <<: *default_config - <<: *distro_build +# CentOS: +# image: centos:7 +# <<: *default_config +# <<: *distro_build OpenSUSE: image: opensuse/tumbleweed diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index 7b682531..ed0e1e33 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -58,36 +58,36 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN #add_compile_options(-fasynchronous-unwind-tables) -# if ( EXIV2_TEAM_USE_SANITIZERS ) -# # ASAN is available in gcc from 4.8 and UBSAN from 4.9 -# # ASAN is available in clang from 3.1 and UBSAN from 3.3 -# # UBSAN is not fatal by default, instead it only prints runtime errors to stderr -# # => make it fatal with -fno-sanitize-recover (gcc) or -fno-sanitize-recover=all (clang) -# # add -fno-omit-frame-pointer for better stack traces -# if ( COMPILER_IS_GCC ) -# if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) -# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover") -# elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8 ) -# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") -# endif() -# elseif( COMPILER_IS_CLANG ) -# if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) -# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all") -# elseif ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4 ) -# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined") -# elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.1 ) -# set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") -# endif() -# endif() -# -# # sorry, ASAN does not work on Windows -# if ( NOT CYGWIN AND NOT MINGW AND NOT MSYS ) -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}") -# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}") -# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}") -# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS}") -# endif() -# endif() + if ( EXIV2_TEAM_USE_SANITIZERS ) + # ASAN is available in gcc from 4.8 and UBSAN from 4.9 + # ASAN is available in clang from 3.1 and UBSAN from 3.3 + # UBSAN is not fatal by default, instead it only prints runtime errors to stderr + # => make it fatal with -fno-sanitize-recover (gcc) or -fno-sanitize-recover=all (clang) + # add -fno-omit-frame-pointer for better stack traces + if ( COMPILER_IS_GCC ) + if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) + set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover") + elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8 ) + set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") + endif() + elseif( COMPILER_IS_CLANG ) + if ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 ) + set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined -fno-sanitize-recover=all") + elseif ( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.4 ) + set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address,undefined") + elseif( CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.1 ) + set(SANITIZER_FLAGS "-fno-omit-frame-pointer -fsanitize=address") + endif() + endif() + + # sorry, ASAN does not work on Windows + if ( NOT CYGWIN AND NOT MINGW AND NOT MSYS ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${SANITIZER_FLAGS}") + endif() + endif() endif() endif () From 2adde8dd738833f6078157a63453321f5b2c600a Mon Sep 17 00:00:00 2001 From: clanmills Date: Sun, 11 Oct 2020 20:43:33 +0100 Subject: [PATCH 06/11] Fix compiling http.cpp and reinstate centOS on gitLab. --- .gitlab-ci.yml | 8 ++++---- src/CMakeLists.txt | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index da665139..d01a90f2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,10 +59,10 @@ Ubuntu: <<: *default_config <<: *distro_build -# CentOS: -# image: centos:7 -# <<: *default_config -# <<: *distro_build +CentOS: + image: centos:7 + <<: *default_config + <<: *distro_build OpenSUSE: image: opensuse/tumbleweed diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83cbbb00..220ffead 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,10 +40,6 @@ add_library( exiv2lib_int OBJECT unused.h ) -if (COMPILER_IS_GCC OR COMPILER_IS_CLANG) - set_source_files_properties(http.cpp PROPERTIES COMPILE_FLAGS -fno-sanitize=address,undefined) -endif() - add_library( exiv2lib ../include/exiv2/config.h ../include/exiv2/exiv2.hpp From e60625abc2ebdbc37890046be5e70fdcfb40bcb7 Mon Sep 17 00:00:00 2001 From: clanmills Date: Sun, 11 Oct 2020 21:24:51 +0100 Subject: [PATCH 07/11] Disable centOS on CI. The web-server goes crazy althought this doesn't happen in the terminal on centOS. --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d01a90f2..da665139 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,10 +59,10 @@ Ubuntu: <<: *default_config <<: *distro_build -CentOS: - image: centos:7 - <<: *default_config - <<: *distro_build +# CentOS: +# image: centos:7 +# <<: *default_config +# <<: *distro_build OpenSUSE: image: opensuse/tumbleweed From 64e64b4a9bd3bb3ecfaf68788fcfff44c18af886 Mon Sep 17 00:00:00 2001 From: LeoHsiao Date: Mon, 12 Oct 2020 23:06:59 +0800 Subject: [PATCH 08/11] Enhance function find(), cp(), rm(), mv() --- tests/bash_tests/testcases.py | 7 +- tests/bash_tests/utils.py | 125 ++++++++++++++++++++++------------ 2 files changed, 83 insertions(+), 49 deletions(-) diff --git a/tests/bash_tests/testcases.py b/tests/bash_tests/testcases.py index 90b03821..27752aab 100644 --- a/tests/bash_tests/testcases.py +++ b/tests/bash_tests/testcases.py @@ -923,7 +923,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42 e = BT.Executer('exiv2 -pp {filename}', vars(), assert_returncode=None, redirect_stderr_to_stdout=False) out += e.stdout out += 'Exit code: {}'.format(e.returncode) - BT.rm(*BT.find(image + '-preview*')) + BT.rm(*BT.find(pattern=image + '-preview*')) out += '\nCommand: exiv2 -f -ep ' + filename e = BT.Executer('exiv2 -f -ep {filename}', vars(), assert_returncode=None, redirect_stderr_to_stdout=False) @@ -933,7 +933,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42 # Check the difference e = BT.Executer('exiv2 -pp {filename}', vars(), assert_returncode=None, redirect_stderr_to_stdout=False) preview_num = e.stdout[:e.stdout.find(':')].lstrip('Preview ') - for test_file in BT.find('{image}-preview{preview_num}.*'.format(**vars())): + for test_file in BT.find(pattern='{image}-preview{preview_num}.*'.format(**vars())): reference_file = os.path.join(preview_dir, test_file) if BT.diffCheck(reference_file, test_file, in_bytes=True): pass_count += 1 @@ -954,8 +954,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42 try: import lxml except ModuleNotFoundError: - print('ignored') - print('Missing module lxml, please install: `pip install lxml`') + print('Skipped. Because it misses module lxml. Please install: `pip install lxml`') return out = BT.Output() diff --git a/tests/bash_tests/utils.py b/tests/bash_tests/utils.py index 73ecae3c..a7e319d9 100644 --- a/tests/bash_tests/utils.py +++ b/tests/bash_tests/utils.py @@ -44,36 +44,17 @@ Part 2: Here are some common functions that are poorly coupled with test cases. """ -def cp(src, dest): - """ It is used to copy one file, cannot handle directories """ - shutil.copy(src, dest) - -def mv(src, dest): - """ It is used to move one file, cannot handle directories """ - shutil.move(src, dest) - - -def rm(*files): - """ It is used to remove files, cannot handle directories """ - for i in files: - try: - os.remove(i) - except FileNotFoundError: - continue - - -def find(pattern=None, re_pattern=None, directory='.', depth=-1, onerror=print) -> list: +def find(directory='.', pattern=None, re_pattern=None, depth=-1, onerror=print) -> list: """ - Find files that match the pattern in the specified directory and return their paths. + Find files and directories that match the pattern in the specified directory and return their paths. + Work in recursive mode. If there are thousands of files, the runtime may be several seconds. + - `directory` : Find files in this directory and its subdirectories - `pattern` : Filter filename based on shell-style wildcards. - `re_pattern` : Filter filename based on regular expressions. - - `directory` : Find files in this directory and its subdirectories - `depth` : Depth of subdirectories. If its value is negative, the depth is infinite. - `onerror` : A callable parameter. it will be called if an exception occurs. - Work in recursive mode. If there are thousands of files, the runtime may be several seconds. - Sample: >>> find(pattern='*.py') >>> find(re_pattern='.*.py') @@ -85,25 +66,72 @@ def find(pattern=None, re_pattern=None, directory='.', depth=-1, onerror=print) file_list = os.listdir(directory) except PermissionError as e: # Sometimes it does not have access to the directory onerror("PermissionError: {}".format(e)) - return -1 + return [] + + def match(name, pattern=None, re_pattern=None): + if pattern and not fnmatch.fnmatch(name, pattern): + return False + if re_pattern and not re.findall(re_pattern, name): + return False + return True path_list = [] - for filename in file_list: - path = os.path.join(directory, filename) - if depth != 0 and os.path.isdir(path): - sub_list = find(path, depth-1, pattern, re_pattern, onerror) - if sub_list != -1: - path_list.extend(sub_list) - continue - if pattern and not fnmatch.fnmatch(filename, pattern): - continue - if re_pattern and not re.findall(re_pattern, filename): - continue - path_list.append(path) + if match(os.path.basename(directory), pattern, re_pattern): + path_list.append(directory) + if depth != 0: + for filename in file_list: + path = os.path.join(directory, filename) + if os.path.isdir(path): + path_list.extend(find(path, pattern, re_pattern, depth-1, onerror)) + continue + if match(filename, pattern, re_pattern): + path_list.append(path) return path_list +def cp(src, dst): + """ Copy one or more files or directories. It simulates `cp -rf src dst`. """ + if os.path.isfile(src): + shutil.copy(src, dst) + elif os.path.isdir(src): + if os.path.isdir(dst): + dst_dir = os.path.join(dst, os.path.basename(src)) + else: + dst_dir = dst + for src_path in find(src): + relpath = os.path.relpath(src_path, src) + dst_path = os.path.join(dst_dir, relpath) + if os.path.isdir(src_path): + os.makedirs(dst_path, exist_ok=True) + else: + shutil.copy(src_path, dst_path) + else: + raise ValueError('src is not a valid path to a file or directory.') + + +def rm(*paths): + """ Remove one or more files or directories. It simulates `rm -rf paths`. """ + for path in paths: + if os.path.isfile(path): + os.remove(path) + elif os.path.isdir(path): + for sub_path in find(path, depth=1)[1:]: + if os.path.isdir(sub_path): + rm(sub_path) + else: + os.remove(sub_path) + os.rmdir(path) # Remove the directory only when it is empty + else: + continue + + +def mv(src, dst): + """ Move one or more files or directories. """ + cp(src, dst) + rm(src) + + def cat(*files, encoding=None, return_bytes=False): if return_bytes: result = b'' @@ -319,12 +347,12 @@ Part 3: Here are some functions that are highly coupled to test cases. """ -def copyTestFile(src, dest=''): +def copyTestFile(src, dst=''): """ Copy one test file from data_dir to tmp_dir """ - if not dest: - dest = src + if not dst: + dst = src shutil.copy(os.path.join(Config.data_dir, src), - os.path.join(Config.tmp_dir, dest)) + os.path.join(Config.tmp_dir, dst)) def diffCheck(file1, file2, in_bytes=False, encoding=None): @@ -382,6 +410,7 @@ class Executer: def __init__(self, cmd: str, vars_dict=dict(), cwd=None, + extra_env=dict(), encoding=None, stdin: (str, bytes) = None, redirect_stderr_to_stdout=True, @@ -390,6 +419,12 @@ class Executer: decode_output=True): self.cmd = cmd.format(**vars_dict) self.cwd = cwd or Config.tmp_dir + + # set environment variables + self.env = os.environ.copy() + self.env.update({'TZ': 'GMT-8'}) + self.env.update(extra_env) + self.encoding = encoding or Config.encoding self.stdin = stdin # self.stdout = None @@ -410,7 +445,7 @@ class Executer: else: self.args = shlex.split(args, posix=os.name == 'posix') - # check stdin + # Check stdin if self.stdin: if not isinstance(stdin, bytes): self.stdin = str(stdin).encode(self.encoding) @@ -426,9 +461,9 @@ class Executer: # Execute the command in subprocess try: - my_env = os.environ.copy() - my_env['TZ'] = 'GMT-8' - with subprocess.Popen(self.args,env=my_env, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, cwd=self.cwd) as self.subprocess: + with subprocess.Popen(self.args, cwd=self.cwd, env=self.env, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=stderr) as self.subprocess: try: output = self.subprocess.communicate(self.stdin, timeout=10) # Assign (stdout, stderr) to output except subprocess.TimeoutExpired: @@ -447,7 +482,7 @@ class Executer: output = [i.decode(self.encoding) for i in output] self.stdout, self.stderr = [i or None for i in output] - # check return code + # Check return code self.returncode = self.subprocess.returncode if self.assert_returncode and self.returncode not in self.assert_returncode: log.error('Failed to execute: {}'.format(self.args)) From fc91004830bd2c0e101be53932f5f7e53a3e6f54 Mon Sep 17 00:00:00 2001 From: LeoHsiao Date: Mon, 12 Oct 2020 23:08:59 +0800 Subject: [PATCH 09/11] add nls_test() --- tests/bash_tests/testcases.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/bash_tests/testcases.py b/tests/bash_tests/testcases.py index 27752aab..4e16c492 100644 --- a/tests/bash_tests/testcases.py +++ b/tests/bash_tests/testcases.py @@ -860,6 +860,40 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42 BT.reportTest('modify-test', out) + def nls_test(self): + # Test driver for exiv2.exe nls support + nls = BT.Executer('exiv2 -vVg nls').stdout.split('\n')[1] + platform = BT.Executer('exiv2 -vVg platform').stdout.split('\n')[1] + + if nls != 'enable_nls=1': + print('Skipped. Because exiv2 is not built with nls.') + return + if platform == 'platform=windows': + print('Skipped. Because nls_test cannot be run msvc builds.') + return + + # variable LANG is unused + # if platform == 'platform=linux': + # LANG = 'LANGUAGE' + # else: + # LANG = 'LANG' + + share_dir = os.path.normpath(os.path.join(BT.Config.bin_dir, '..', 'share2')) + os.makedirs(share_dir, exist_ok=True) + + locale_dir = '/usr/local/share/locale' + if os.path.isdir(locale_dir) and os.path.isdir(share_dir): + BT.cp(locale_dir, share_dir) + else: + print('Skipped. Because localisation files are not installed in {}.'.format(locale_dir)) + + # The above part is checking the environment, and the following part is executing the actual test + out = BT.Output() + for language in ['fr_FR', 'es_ES']: + out += BT.Executer('exiv2', extra_env={'LC_ALL': language, 'LANG': language}, assert_returncode=[1]) + BT.reportTest('nls-test', out) + + def path_test(self): # Mini test-driver for path utility functions BT.copyTestFile('path-test.txt') From fe4a495ca2ab6f91d8473c870ebd7ac569b910ee Mon Sep 17 00:00:00 2001 From: clanmills Date: Tue, 13 Oct 2020 15:11:13 +0100 Subject: [PATCH 10/11] Fixing variable LANG --- test/nls-test.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/nls-test.sh b/test/nls-test.sh index 220045b1..7948d30c 100755 --- a/test/nls-test.sh +++ b/test/nls-test.sh @@ -4,8 +4,9 @@ source ./functions.source ( cd "$testdir" + nls=$(runTest exiv2 -vVg nls|tail -1) - platform=$(runTest exiv2 -vVg platform|tail -1) + platform=$(${bin}exiv2${exe} -vVg platform|tail -1) if [ "$nls" != "enable_nls=1" ]; then echo "exiv2 not bulid with nls" exit 0 @@ -34,9 +35,11 @@ source ./functions.source fi ## # test a couple of languages - for l in fr_FR es_ES; do - LC_ALL=$l LANG=$l ${bin}exiv2 - done + for l in fr_FR es_ES; do ( + export LC_ALL=$l + export $LANG=$l + runTest exiv2 + ) done ) 3>&1 > $results 2>&1 From ae1fbab6458f263b3fb46fda6be84cf615567a8f Mon Sep 17 00:00:00 2001 From: LeoHsiao Date: Wed, 14 Oct 2020 19:52:32 +0800 Subject: [PATCH 11/11] Fix variable LANG in nls_test() --- tests/bash_tests/testcases.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/bash_tests/testcases.py b/tests/bash_tests/testcases.py index 4e16c492..10a0fe6d 100644 --- a/tests/bash_tests/testcases.py +++ b/tests/bash_tests/testcases.py @@ -868,15 +868,15 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42 if nls != 'enable_nls=1': print('Skipped. Because exiv2 is not built with nls.') return + if platform == 'platform=windows': print('Skipped. Because nls_test cannot be run msvc builds.') return - - # variable LANG is unused - # if platform == 'platform=linux': - # LANG = 'LANGUAGE' - # else: - # LANG = 'LANG' + + if platform == 'platform=linux': + LANG = 'LANGUAGE' + else: + LANG = 'LANG' share_dir = os.path.normpath(os.path.join(BT.Config.bin_dir, '..', 'share2')) os.makedirs(share_dir, exist_ok=True) @@ -890,7 +890,7 @@ set Exif.Photo.DateTimeDigitized 2020:05:26 07:31:42 # The above part is checking the environment, and the following part is executing the actual test out = BT.Output() for language in ['fr_FR', 'es_ES']: - out += BT.Executer('exiv2', extra_env={'LC_ALL': language, 'LANG': language}, assert_returncode=[1]) + out += BT.Executer('exiv2', extra_env={'LC_ALL': language, LANG: language}, assert_returncode=[1]) BT.reportTest('nls-test', out)