From 4cd3a9cdf65a8f0b96de21420b98b8e02181e4f4 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 30 Mar 2026 11:49:10 +0200 Subject: move testing-only things into test/ --- .ci/run_foo.ps1 | 24 ---------- .ci/verify_arch.ps1 | 82 -------------------------------- .ci/verify_arch.sh | 56 ---------------------- .ci/verify_symbols.ps1 | 1 - .ci/verify_symbols.sh | 43 ----------------- .github/actions/check-arch/action.yml | 4 +- .github/actions/check-symbols/action.yml | 2 +- .github/workflows/basic.yml | 10 ++-- .github/workflows/boost_toolsets.yml | 4 +- .github/workflows/example_toolsets.yml | 4 +- .github/workflows/msvc_versions.yml | 4 +- examples/boost/CMakeLists.txt | 12 ----- examples/boost/foo.cpp | 13 ----- examples/simple/CMakeLists.txt | 11 ----- examples/simple/baz.cpp | 7 --- examples/simple/baz.hpp | 9 ---- examples/simple/foo.cpp | 9 ---- test/examples/boost/CMakeLists.txt | 12 +++++ test/examples/boost/foo.cpp | 13 +++++ test/examples/boost/run.ps1 | 24 ++++++++++ test/examples/simple/CMakeLists.txt | 11 +++++ test/examples/simple/baz.cpp | 7 +++ test/examples/simple/baz.hpp | 9 ++++ test/examples/simple/foo.cpp | 9 ++++ test/scripts/verify_arch.ps1 | 82 ++++++++++++++++++++++++++++++++ test/scripts/verify_arch.sh | 56 ++++++++++++++++++++++ test/scripts/verify_symbols.ps1 | 1 + test/scripts/verify_symbols.sh | 43 +++++++++++++++++ 28 files changed, 280 insertions(+), 282 deletions(-) delete mode 100644 .ci/run_foo.ps1 delete mode 100644 .ci/verify_arch.ps1 delete mode 100755 .ci/verify_arch.sh delete mode 100644 .ci/verify_symbols.ps1 delete mode 100755 .ci/verify_symbols.sh delete mode 100644 examples/boost/CMakeLists.txt delete mode 100644 examples/boost/foo.cpp delete mode 100644 examples/simple/CMakeLists.txt delete mode 100644 examples/simple/baz.cpp delete mode 100644 examples/simple/baz.hpp delete mode 100644 examples/simple/foo.cpp create mode 100644 test/examples/boost/CMakeLists.txt create mode 100644 test/examples/boost/foo.cpp create mode 100644 test/examples/boost/run.ps1 create mode 100644 test/examples/simple/CMakeLists.txt create mode 100644 test/examples/simple/baz.cpp create mode 100644 test/examples/simple/baz.hpp create mode 100644 test/examples/simple/foo.cpp create mode 100644 test/scripts/verify_arch.ps1 create mode 100755 test/scripts/verify_arch.sh create mode 100644 test/scripts/verify_symbols.ps1 create mode 100755 test/scripts/verify_symbols.sh diff --git a/.ci/run_foo.ps1 b/.ci/run_foo.ps1 deleted file mode 100644 index 578911f..0000000 --- a/.ci/run_foo.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -param( - [Parameter(Mandatory=$true)] - [string] $FooPath -) - -$foo_path = [System.IO.Path]::GetFullPath($FooPath) -if ($IsWindows) { - $foo_path += '.exe' -} - -$relative = 'test.txt' -$absolute = Join-Path (Get-Location).Path $relative - -$actual = & $foo_path $relative -echo 'Actual output:' -echo $actual - -$expected = $foo_path,$absolute -echo 'Expected output:' -echo $expected - -if (Compare-Object $actual $expected -CaseSensitive) { - throw 'Unexpected output' -} diff --git a/.ci/verify_arch.ps1 b/.ci/verify_arch.ps1 deleted file mode 100644 index 183a8c5..0000000 --- a/.ci/verify_arch.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -param( - [Parameter(Mandatory=$true)] - [string] $Path, - [Parameter(Mandatory=$true)] - [ValidateSet('x64', 'x86')] - [string] $Arch -) - -$ErrorActionPreference = "Stop"; -Set-PSDebug -Strict - -function Get-MachineType { - param( - [Parameter(Mandatory=$true)] - [string] $Arch - ) - - $machine_type = switch ($Arch) { - 'x64' { 0x8664 } - 'x86' { 0x14c } - default { throw "Unsupported architecture: $Arch" } - } - return $machine_type -} - -function Parse-MachineType { - param( - [Parameter(Mandatory=$true)] - [string] $Path - ) - - $header_offset_offset = 0x3c - $machine_type_offset = 4 # Two words - - $bytes = [System.IO.File]::ReadAllBytes($Path) - $header_offset = [System.BitConverter]::ToUInt32($bytes, $header_offset_offset) - $machine_type = [System.BitConverter]::ToUInt16($bytes, $header_offset + $machine_type_offset) - - return $machine_type -} - -function Verify-Architecture { - param( - [Parameter(Mandatory=$true)] - [string] $Path, - [Parameter(Mandatory=$true)] - [string] $Arch - ) - - $actual = Parse-MachineType -Path $Path - $actual_hex = "0x{0:x}" -f $actual - $expected = Get-MachineType -Arch $Arch - $expected_hex = "0x{0:x}" -f $expected - - if ($actual -eq $expected) { - Write-Host "File '$Path' matches architecture '$Arch'." - } else { - Write-Host "File '$Path' DOES NOT match architecture '$Arch'." - Write-Error "Expected machine type '$expected_hex', actual machine type is '$actual_hex'." - } -} - -function Test-AppVeyor { - return Test-Path env:APPVEYOR -} - -function Verify-ArchitectureAppVeyor { - if (Test-AppVeyor) { - $appveyor_cwd = pwd - } - - try { - Verify-Architecture -Path $script:Path -Arch $script:Arch - } finally { - if (Test-AppVeyor) { - cd $appveyor_cwd - Set-PSDebug -Off - } - } -} - -Verify-ArchitectureAppVeyor diff --git a/.ci/verify_arch.sh b/.ci/verify_arch.sh deleted file mode 100755 index aafc5e8..0000000 --- a/.ci/verify_arch.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -script_name="$( basename -- "${BASH_SOURCE[0]}" )" -readonly script_name - -elf_file_class() { - local path - for path; do - od --address-radix=n --skip-bytes=4 --read-bytes=1 --format=x1 -- "$path" - done -} - -arch_to_file_class() { - local arch - for arch; do - case "$arch" in - x86) - echo '01' - ;; - x64) - echo '02' - ;; - *) - echo "$script_name: unsupported architecture: $arch" >&2 - return 1 - ;; - esac - done -} - -main() { - if [ "$#" -ne 2 ]; then - echo "usage: $script_name BIN_PATH ARCH" >&2 - return 1 - fi - - local path="$1" - local arch="$2" - - local expected - expected=" $( arch_to_file_class "$arch" )" - local actual - actual="$( elf_file_class "$path" )" - - if [ "$expected" = "$actual" ]; then - echo "$script_name: file '$path' matches architecture '$arch'" - else - echo "$script_name: file '$path' DOES NOT match architecture '$arch'" - echo "$script_name: expected ELF file class '$expected', actual file class is '$actual'" >&2 - return 1 - fi -} - -main "$@" diff --git a/.ci/verify_symbols.ps1 b/.ci/verify_symbols.ps1 deleted file mode 100644 index ebe6d99..0000000 --- a/.ci/verify_symbols.ps1 +++ /dev/null @@ -1 +0,0 @@ -Write-Host "Not going to check symbols for a Windows executable." diff --git a/.ci/verify_symbols.sh b/.ci/verify_symbols.sh deleted file mode 100755 index 73cc6ba..0000000 --- a/.ci/verify_symbols.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -o nounset -o pipefail - -script_name="$( basename -- "${BASH_SOURCE[0]}" )" -readonly script_name - -main() { - if [ "$#" -lt 1 ]; then - echo "usage: $script_name BIN_PATH [SYMBOL...]" >&2 - return 1 - fi - - local path="$1" - shift - - local nm - nm="$( nm --demangle -- "$path" 2>&1 )" - - if [ "$#" -eq 0 ]; then - if [ "$nm" == "nm: $path: no symbols" ]; then - echo "$script_name: file '$path' has no symbols, as expected" - return 0 - else - echo "$script_name: file '$path' should not have symbols, but it does" >&2 - return 1 - fi - fi - - local symbol - for symbol; do - if echo "$nm" | grep -F -e " $symbol"; then - echo "$script_name: file '$path' has symbol '$symbol'" - else - echo "$script_name: symbol '$symbol' wasn't found in file '$path'" - echo "$script_name: here's the complete symbol list:" - echo "$nm" - return 1 - fi - done -} - -main "$@" diff --git a/.github/actions/check-arch/action.yml b/.github/actions/check-arch/action.yml index b85be4e..b8e4d64 100644 --- a/.github/actions/check-arch/action.yml +++ b/.github/actions/check-arch/action.yml @@ -12,9 +12,9 @@ runs: steps: - run: | $script_path = if ($env:CI_TARGET_PE) { - Join-Path $env:GITHUB_WORKSPACE '.ci' 'verify_arch.ps1' + Join-Path $env:GITHUB_WORKSPACE 'test' 'scripts' 'verify_arch.ps1' } else { - Join-Path $env:GITHUB_WORKSPACE '.ci' 'verify_arch.sh' + Join-Path $env:GITHUB_WORKSPACE 'test' 'scripts' 'verify_arch.sh' } $exe_path = (Join-Path '${{ inputs.path }}' 'bin' 'foo') + $env:CI_EXE_EXT diff --git a/.github/actions/check-symbols/action.yml b/.github/actions/check-symbols/action.yml index 7428be3..3681f52 100644 --- a/.github/actions/check-symbols/action.yml +++ b/.github/actions/check-symbols/action.yml @@ -16,7 +16,7 @@ runs: $lib_dir = Join-Path $install_dir 'lib' $script_path = if ($env:CI_TARGET_ELF) { - Join-Path $env:GITHUB_WORKSPACE '.ci' 'verify_symbols.sh' + Join-Path $env:GITHUB_WORKSPACE 'test' 'scripts' 'verify_symbols.sh' } else { throw "Verifying symbols for PE executables is not implemented" } diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 5b1f63e..fa2bc0a 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -51,10 +51,9 @@ jobs: python -m project.boost.build boost/ filesystem - name: Build example project run: | - $src_dir = Join-Path examples boost - python -m project.build --boost boost/ --install install/ -- $src_dir build/ + python -m project.build --boost boost/ --install install/ -- test/examples/boost/ build/ - name: Run example project - run: ./.ci/run_foo.ps1 (Join-Path (Get-Location).Path install bin foo) + run: ./test/examples/boost/run.ps1 ./install/bin/foo # Check that the most basic use-case works w/ different Python versions. python-versions: @@ -96,10 +95,9 @@ jobs: boost-build boost/ filesystem - name: Build example project run: | - $src_dir = Join-Path examples boost - project-build --boost boost/ --install install/ -- $src_dir build/ + project-build --boost boost/ --install install/ -- test/examples/boost/ build/ - name: Run example project - run: ./.ci/run_foo.ps1 (Join-Path (Get-Location).Path install bin foo) + run: ./test/examples/boost/run.ps1 ./install/bin/foo # Build a Python package and upload to PyPI. publish: diff --git a/.github/workflows/boost_toolsets.yml b/.github/workflows/boost_toolsets.yml index 8f90191..ea7d287 100644 --- a/.github/workflows/boost_toolsets.yml +++ b/.github/workflows/boost_toolsets.yml @@ -3,7 +3,7 @@ name: Boost (toolsets) on: push: paths: - - 'examples/**' + - 'test/**' - 'project/**' schedule: # Weekly, at 5:30 AM on Saturday (somewhat randomly chosen). @@ -149,7 +149,7 @@ jobs: id: build_example uses: ./.github/actions/build-example with: - src-dir: examples/boost + src-dir: test/examples/boost boost-dir: '${{ env.BOOST_DIR }}' toolset: '${{ matrix.toolset }}' platform: '${{ matrix.platform }}' diff --git a/.github/workflows/example_toolsets.yml b/.github/workflows/example_toolsets.yml index 94ca380..42e1ec3 100644 --- a/.github/workflows/example_toolsets.yml +++ b/.github/workflows/example_toolsets.yml @@ -3,7 +3,7 @@ name: Examples (toolsets) on: push: paths: - - 'examples/**' + - 'test/**' - 'project/**' schedule: # Weekly, at 5:30 AM on Saturday (somewhat randomly chosen). @@ -122,7 +122,7 @@ jobs: id: build uses: ./.github/actions/build-example with: - src-dir: 'examples/${{ matrix.example }}' + src-dir: 'test/examples/${{ matrix.example }}' toolset: '${{ matrix.toolset }}' platform: '${{ matrix.platform }}' configuration: '${{ matrix.configuration }}' diff --git a/.github/workflows/msvc_versions.yml b/.github/workflows/msvc_versions.yml index 22f0d76..fd3c747 100644 --- a/.github/workflows/msvc_versions.yml +++ b/.github/workflows/msvc_versions.yml @@ -3,7 +3,7 @@ name: Visual Studio versions on: push: paths: - - 'examples/**' + - 'test/**' - 'project/**' schedule: # Weekly, at 5:30 AM on Saturday (somewhat randomly chosen). @@ -98,7 +98,7 @@ jobs: id: build_example uses: ./.github/actions/build-example with: - src-dir: examples/boost + src-dir: test/examples/boost boost-dir: '${{ env.BOOST_DIR }}' toolset: '${{ matrix.toolset }}' platform: '${{ matrix.platform }}' diff --git a/examples/boost/CMakeLists.txt b/examples/boost/CMakeLists.txt deleted file mode 100644 index 0e92e38..0000000 --- a/examples/boost/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(example_boost) - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -find_package(Boost REQUIRED COMPONENTS filesystem) -add_executable(foo foo.cpp) -target_link_libraries(foo PRIVATE Boost::disable_autolinking Boost::filesystem) - -install(TARGETS foo RUNTIME DESTINATION bin) diff --git a/examples/boost/foo.cpp b/examples/boost/foo.cpp deleted file mode 100644 index 6219e68..0000000 --- a/examples/boost/foo.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include - -int main(int argc, char* argv[]) { - namespace fs = boost::filesystem; - std::cout << argv[0] << '\n'; - for (int i = 1; i < argc; ++i) { - std::cout << fs::absolute(boost::filesystem::path{argv[i]}).string() - << '\n'; - } - return 0; -} diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt deleted file mode 100644 index 50a588b..0000000 --- a/examples/simple/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(example_simple) - -add_library(baz SHARED baz.cpp) -target_include_directories(baz PUBLIC .) - -add_executable(foo foo.cpp) -target_link_libraries(foo PRIVATE baz) - -install(TARGETS foo baz RUNTIME DESTINATION bin LIBRARY DESTINATION lib) diff --git a/examples/simple/baz.cpp b/examples/simple/baz.cpp deleted file mode 100644 index d108ae3..0000000 --- a/examples/simple/baz.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "baz.hpp" - -#include - -void baz() { - std::cout << "baz\n"; -} diff --git a/examples/simple/baz.hpp b/examples/simple/baz.hpp deleted file mode 100644 index 2fc9b2a..0000000 --- a/examples/simple/baz.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#ifdef _MSC_VER -#define DLLEXPORT __declspec(dllexport) -#else -#define DLLEXPORT -#endif - -DLLEXPORT void baz(); diff --git a/examples/simple/foo.cpp b/examples/simple/foo.cpp deleted file mode 100644 index 7e928e1..0000000 --- a/examples/simple/foo.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include - -int main() { - std::cout << "foo\n"; - baz(); - return 0; -} diff --git a/test/examples/boost/CMakeLists.txt b/test/examples/boost/CMakeLists.txt new file mode 100644 index 0000000..0e92e38 --- /dev/null +++ b/test/examples/boost/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.15) + +project(example_boost) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Boost REQUIRED COMPONENTS filesystem) +add_executable(foo foo.cpp) +target_link_libraries(foo PRIVATE Boost::disable_autolinking Boost::filesystem) + +install(TARGETS foo RUNTIME DESTINATION bin) diff --git a/test/examples/boost/foo.cpp b/test/examples/boost/foo.cpp new file mode 100644 index 0000000..6219e68 --- /dev/null +++ b/test/examples/boost/foo.cpp @@ -0,0 +1,13 @@ +#include + +#include + +int main(int argc, char* argv[]) { + namespace fs = boost::filesystem; + std::cout << argv[0] << '\n'; + for (int i = 1; i < argc; ++i) { + std::cout << fs::absolute(boost::filesystem::path{argv[i]}).string() + << '\n'; + } + return 0; +} diff --git a/test/examples/boost/run.ps1 b/test/examples/boost/run.ps1 new file mode 100644 index 0000000..578911f --- /dev/null +++ b/test/examples/boost/run.ps1 @@ -0,0 +1,24 @@ +param( + [Parameter(Mandatory=$true)] + [string] $FooPath +) + +$foo_path = [System.IO.Path]::GetFullPath($FooPath) +if ($IsWindows) { + $foo_path += '.exe' +} + +$relative = 'test.txt' +$absolute = Join-Path (Get-Location).Path $relative + +$actual = & $foo_path $relative +echo 'Actual output:' +echo $actual + +$expected = $foo_path,$absolute +echo 'Expected output:' +echo $expected + +if (Compare-Object $actual $expected -CaseSensitive) { + throw 'Unexpected output' +} diff --git a/test/examples/simple/CMakeLists.txt b/test/examples/simple/CMakeLists.txt new file mode 100644 index 0000000..50a588b --- /dev/null +++ b/test/examples/simple/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) + +project(example_simple) + +add_library(baz SHARED baz.cpp) +target_include_directories(baz PUBLIC .) + +add_executable(foo foo.cpp) +target_link_libraries(foo PRIVATE baz) + +install(TARGETS foo baz RUNTIME DESTINATION bin LIBRARY DESTINATION lib) diff --git a/test/examples/simple/baz.cpp b/test/examples/simple/baz.cpp new file mode 100644 index 0000000..d108ae3 --- /dev/null +++ b/test/examples/simple/baz.cpp @@ -0,0 +1,7 @@ +#include "baz.hpp" + +#include + +void baz() { + std::cout << "baz\n"; +} diff --git a/test/examples/simple/baz.hpp b/test/examples/simple/baz.hpp new file mode 100644 index 0000000..2fc9b2a --- /dev/null +++ b/test/examples/simple/baz.hpp @@ -0,0 +1,9 @@ +#pragma once + +#ifdef _MSC_VER +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif + +DLLEXPORT void baz(); diff --git a/test/examples/simple/foo.cpp b/test/examples/simple/foo.cpp new file mode 100644 index 0000000..7e928e1 --- /dev/null +++ b/test/examples/simple/foo.cpp @@ -0,0 +1,9 @@ +#include + +#include + +int main() { + std::cout << "foo\n"; + baz(); + return 0; +} diff --git a/test/scripts/verify_arch.ps1 b/test/scripts/verify_arch.ps1 new file mode 100644 index 0000000..183a8c5 --- /dev/null +++ b/test/scripts/verify_arch.ps1 @@ -0,0 +1,82 @@ +param( + [Parameter(Mandatory=$true)] + [string] $Path, + [Parameter(Mandatory=$true)] + [ValidateSet('x64', 'x86')] + [string] $Arch +) + +$ErrorActionPreference = "Stop"; +Set-PSDebug -Strict + +function Get-MachineType { + param( + [Parameter(Mandatory=$true)] + [string] $Arch + ) + + $machine_type = switch ($Arch) { + 'x64' { 0x8664 } + 'x86' { 0x14c } + default { throw "Unsupported architecture: $Arch" } + } + return $machine_type +} + +function Parse-MachineType { + param( + [Parameter(Mandatory=$true)] + [string] $Path + ) + + $header_offset_offset = 0x3c + $machine_type_offset = 4 # Two words + + $bytes = [System.IO.File]::ReadAllBytes($Path) + $header_offset = [System.BitConverter]::ToUInt32($bytes, $header_offset_offset) + $machine_type = [System.BitConverter]::ToUInt16($bytes, $header_offset + $machine_type_offset) + + return $machine_type +} + +function Verify-Architecture { + param( + [Parameter(Mandatory=$true)] + [string] $Path, + [Parameter(Mandatory=$true)] + [string] $Arch + ) + + $actual = Parse-MachineType -Path $Path + $actual_hex = "0x{0:x}" -f $actual + $expected = Get-MachineType -Arch $Arch + $expected_hex = "0x{0:x}" -f $expected + + if ($actual -eq $expected) { + Write-Host "File '$Path' matches architecture '$Arch'." + } else { + Write-Host "File '$Path' DOES NOT match architecture '$Arch'." + Write-Error "Expected machine type '$expected_hex', actual machine type is '$actual_hex'." + } +} + +function Test-AppVeyor { + return Test-Path env:APPVEYOR +} + +function Verify-ArchitectureAppVeyor { + if (Test-AppVeyor) { + $appveyor_cwd = pwd + } + + try { + Verify-Architecture -Path $script:Path -Arch $script:Arch + } finally { + if (Test-AppVeyor) { + cd $appveyor_cwd + Set-PSDebug -Off + } + } +} + +Verify-ArchitectureAppVeyor diff --git a/test/scripts/verify_arch.sh b/test/scripts/verify_arch.sh new file mode 100755 index 0000000..aafc5e8 --- /dev/null +++ b/test/scripts/verify_arch.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +script_name="$( basename -- "${BASH_SOURCE[0]}" )" +readonly script_name + +elf_file_class() { + local path + for path; do + od --address-radix=n --skip-bytes=4 --read-bytes=1 --format=x1 -- "$path" + done +} + +arch_to_file_class() { + local arch + for arch; do + case "$arch" in + x86) + echo '01' + ;; + x64) + echo '02' + ;; + *) + echo "$script_name: unsupported architecture: $arch" >&2 + return 1 + ;; + esac + done +} + +main() { + if [ "$#" -ne 2 ]; then + echo "usage: $script_name BIN_PATH ARCH" >&2 + return 1 + fi + + local path="$1" + local arch="$2" + + local expected + expected=" $( arch_to_file_class "$arch" )" + local actual + actual="$( elf_file_class "$path" )" + + if [ "$expected" = "$actual" ]; then + echo "$script_name: file '$path' matches architecture '$arch'" + else + echo "$script_name: file '$path' DOES NOT match architecture '$arch'" + echo "$script_name: expected ELF file class '$expected', actual file class is '$actual'" >&2 + return 1 + fi +} + +main "$@" diff --git a/test/scripts/verify_symbols.ps1 b/test/scripts/verify_symbols.ps1 new file mode 100644 index 0000000..ebe6d99 --- /dev/null +++ b/test/scripts/verify_symbols.ps1 @@ -0,0 +1 @@ +Write-Host "Not going to check symbols for a Windows executable." diff --git a/test/scripts/verify_symbols.sh b/test/scripts/verify_symbols.sh new file mode 100755 index 0000000..73cc6ba --- /dev/null +++ b/test/scripts/verify_symbols.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset -o pipefail + +script_name="$( basename -- "${BASH_SOURCE[0]}" )" +readonly script_name + +main() { + if [ "$#" -lt 1 ]; then + echo "usage: $script_name BIN_PATH [SYMBOL...]" >&2 + return 1 + fi + + local path="$1" + shift + + local nm + nm="$( nm --demangle -- "$path" 2>&1 )" + + if [ "$#" -eq 0 ]; then + if [ "$nm" == "nm: $path: no symbols" ]; then + echo "$script_name: file '$path' has no symbols, as expected" + return 0 + else + echo "$script_name: file '$path' should not have symbols, but it does" >&2 + return 1 + fi + fi + + local symbol + for symbol; do + if echo "$nm" | grep -F -e " $symbol"; then + echo "$script_name: file '$path' has symbol '$symbol'" + else + echo "$script_name: symbol '$symbol' wasn't found in file '$path'" + echo "$script_name: here's the complete symbol list:" + echo "$nm" + return 1 + fi + done +} + +main "$@" -- cgit v1.3