|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +#------------------------------------------------------------------------------ |
| 4 | +# Script that tests that the compiler works correctly regardless of the locale |
| 5 | +# setting. As a prerequisite, the following locales must be enabled system-wide: |
| 6 | +# C, tr_TR.utf8, ja_JP.eucjp. |
| 7 | +# |
| 8 | +# Usage: |
| 9 | +# <script name>.sh <path to solc binary> |
| 10 | +# |
| 11 | +# ------------------------------------------------------------------------------ |
| 12 | +# This file is part of solidity. |
| 13 | +# |
| 14 | +# solidity is free software: you can redistribute it and/or modify |
| 15 | +# it under the terms of the GNU General Public License as published by |
| 16 | +# the Free Software Foundation, either version 3 of the License, or |
| 17 | +# (at your option) any later version. |
| 18 | +# |
| 19 | +# solidity is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# You should have received a copy of the GNU General Public License |
| 25 | +# along with solidity. If not, see <http://www.gnu.org/licenses/> |
| 26 | +# |
| 27 | +# (c) 2022 solidity contributors. |
| 28 | +#------------------------------------------------------------------------------ |
| 29 | + |
| 30 | +set -eo pipefail |
| 31 | + |
| 32 | +REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 33 | +# shellcheck source=scripts/common.sh |
| 34 | +source "${REPO_ROOT}/scripts/common.sh" |
| 35 | + |
| 36 | +solc_binary="$1" |
| 37 | +(( $# == 1 )) || fail "Expected exactly 1 argument." |
| 38 | + |
| 39 | +# This test won't work without some specific locales installed |
| 40 | +locale -a | grep -e "^tr_TR\.utf8$" || fail "Locale 'tr_TR.utf8' not available." |
| 41 | +locale -a | grep -e "^ja_JP\.eucjp$" || fail "Locale 'ja_JP.eucjp' not available." |
| 42 | +locale -a | grep -e "^C$" || fail "Locale 'C' not available." |
| 43 | +locale -a | grep -e "^__invalid_locale__$" && fail "'__invalid_locale__' is not supposed to be a valid locale name." |
| 44 | + |
| 45 | +i="i" |
| 46 | + |
| 47 | +test_code=$(cat <<'EOF' |
| 48 | + // SPDX-License-Identifier: GPL-3.0 |
| 49 | + pragma solidity *; |
| 50 | + library L {} |
| 51 | +EOF |
| 52 | +) |
| 53 | + |
| 54 | +# Whatever locale is set by default. |
| 55 | +printTask "Testing the default locale..." |
| 56 | +default_locale_output=$(echo "$test_code" | "$solc_binary" - --bin) |
| 57 | + |
| 58 | +# Plain C locale |
| 59 | +printTask "Testing the C locale..." |
| 60 | +export LC_ALL=C |
| 61 | +[[ ${i^^} == "I" ]] || assertFail |
| 62 | +c_locale_output=$(echo "$test_code" | "$solc_binary" - --bin) |
| 63 | +diff_values "$default_locale_output" "$c_locale_output" |
| 64 | + |
| 65 | +# Turkish locale, which has capitalization rules (`i` -> `İ` and `I` to `ı`) that can make identifiers invalid. |
| 66 | +printTask "Testing the Turkish locale..." |
| 67 | +export LC_ALL=tr_TR.utf8 |
| 68 | +[[ ${i^^} != "I" ]] || assertFail |
| 69 | +tr_locale_output=$(echo "$test_code" | "$solc_binary" - --bin) |
| 70 | +diff_values "$default_locale_output" "$tr_locale_output" |
| 71 | + |
| 72 | +# A different locale, that should not do anything special to ASCII chars. |
| 73 | +printTask "Testing the Japanese locale..." |
| 74 | +export LC_ALL=ja_JP.eucjp |
| 75 | +[[ ${i^^} == "I" ]] || assertFail |
| 76 | +ja_locale_output=$(echo "$test_code" | "$solc_binary" - --bin) |
| 77 | +diff_values "$default_locale_output" "$ja_locale_output" |
| 78 | + |
| 79 | +# The compiler should not crash if the locale is not valid. |
| 80 | +printTask "Testing an invalid locale..." |
| 81 | +export LC_ALL=__invalid_locale__ || true |
| 82 | +invalid_locale_output=$(echo "$test_code" | "$solc_binary" - --bin) |
| 83 | +diff_values "$default_locale_output" "$invalid_locale_output" |
0 commit comments