Skip to content

cmdline tests are executed in their respective test directory #15996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions test/cmdlineTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ EOF
if jq 'has("ethdebug")' "$stdout_path" --exit-status > /dev/null; then
local temporary_file
temporary_file=$(mktemp -t cmdline-ethdebug-XXXXXX.tmp)
if [[ -e ${tdir}/strip-ethdebug ]]; then
if [[ -e strip-ethdebug ]]; then
jq --indent 4 '
(. | .. | objects | select(has("ethdebug"))) |= (.ethdebug = "<ETHDEBUG DEBUG DATA REMOVED>")
' "$stdout_path" > "$temporary_file"
Expand Down Expand Up @@ -350,9 +350,11 @@ test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "" "Error: Inva

printTask "Running general commandline tests..."
(
cd "$REPO_ROOT"/test/cmdlineTests/
for tdir in "${selected_tests[@]}"
do
# go back to the test root dir
cd "$REPO_ROOT"/test/cmdlineTests/

if ! [[ -d $tdir ]]
then
fail "Test directory not found: $tdir"
Expand All @@ -377,18 +379,21 @@ printTask "Running general commandline tests..."
fi
fi

scriptFiles="$(ls -1 "${tdir}/test."* 2> /dev/null || true)"
# jump into test dir
cd "${tdir}"

scriptFiles="$(ls -1 "test."* 2> /dev/null || true)"
scriptCount="$(echo "${scriptFiles}" | wc -w)"

inputFiles="$(ls -1 "${tdir}/input."* 2> /dev/null || true)"
inputFiles="$(ls -1 "input."* 2> /dev/null || true)"
inputCount="$(echo "${inputFiles}" | wc -w)"
(( inputCount <= 1 )) || fail "Ambiguous input. Found input files in multiple formats:"$'\n'"${inputFiles}"
(( scriptCount <= 1 )) || fail "Ambiguous input. Found script files in multiple formats:"$'\n'"${scriptFiles}"
(( inputCount == 0 || scriptCount == 0 )) || fail "Ambiguous input. Found both input and script files:"$'\n'"${inputFiles}"$'\n'"${scriptFiles}"

if (( scriptCount == 1 ))
then
if ! "$scriptFiles"
if ! "./$scriptFiles"
then
fail "Test script ${scriptFiles} failed."
fi
Expand All @@ -399,38 +404,38 @@ printTask "Running general commandline tests..."
# Use printf to get rid of the trailing newline
inputFile=$(printf "%s" "${inputFiles}")

if [ "${inputFile}" = "${tdir}/input.json" ]
if [ "${inputFile}" = "input.json" ]
then
! [ -e "${tdir}/stdin" ] || fail "Found a file called 'stdin' but redirecting standard input in JSON mode is not allowed."
! [ -e "stdin" ] || fail "Found a file called 'stdin' but redirecting standard input in JSON mode is not allowed."

stdin="${inputFile}"
inputFile=""
stdout="$(cat "${tdir}/output.json" 2>/dev/null || true)"
stdoutExpectationFile="${tdir}/output.json"
stdout="$(cat "output.json" 2>/dev/null || true)"
stdoutExpectationFile="output.json"
prettyPrintFlags=""
if [[ ! -f "${tdir}/no-pretty-print" ]]
if [[ ! -f "no-pretty-print" ]]
then
prettyPrintFlags="--pretty-json --json-indent 4"
fi

command_args="--standard-json ${prettyPrintFlags} "$(cat "${tdir}/args" 2>/dev/null || true)
command_args="--standard-json ${prettyPrintFlags} "$(cat "args" 2>/dev/null || true)
else
if [ -e "${tdir}/stdin" ]
if [ -e "stdin" ]
then
stdin="${tdir}/stdin"
[ -f "${tdir}/stdin" ] || fail "'stdin' is not a regular file."
stdin="stdin"
[ -f "stdin" ] || fail "'stdin' is not a regular file."
else
stdin=""
fi

stdout="$(cat "${tdir}/output" 2>/dev/null || true)"
stdoutExpectationFile="${tdir}/output"
command_args=$(cat "${tdir}/args" 2>/dev/null || true)
stdout="$(cat "output" 2>/dev/null || true)"
stdoutExpectationFile="output"
command_args=$(cat "args" 2>/dev/null || true)
fi
exitCodeExpectationFile="${tdir}/exit"
exitCodeExpectationFile="exit"
exitCode=$(cat "$exitCodeExpectationFile" 2>/dev/null || true)
err="$(cat "${tdir}/err" 2>/dev/null || true)"
stderrExpectationFile="${tdir}/err"
err="$(cat "err" 2>/dev/null || true)"
stderrExpectationFile="err"
test_solc_behaviour "$inputFile" \
"$command_args" \
"$stdin" \
Expand Down
4 changes: 2 additions & 2 deletions test/cmdlineTests/abi_via_ir/output
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

======= abi_via_ir/input.sol:C =======
======= input.sol:C =======
Contract JSON ABI
[
{
Expand Down Expand Up @@ -101,7 +101,7 @@ Contract JSON ABI
}
]

======= abi_via_ir/input.sol:L =======
======= input.sol:L =======
Contract JSON ABI
[
{
Expand Down
2 changes: 1 addition & 1 deletion test/cmdlineTests/abiencoderv2_no_warning/output
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

======= abiencoderv2_no_warning/input.sol:C =======
======= input.sol:C =======
Function signatures:
3fc03eeb: f((uint256))
4 changes: 2 additions & 2 deletions test/cmdlineTests/asm_json/output
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

======= asm_json/input.sol:C =======
======= input.sol:C =======
EVM assembly:
{
".code": [
Expand Down Expand Up @@ -1573,7 +1573,7 @@ EVM assembly:
}
},
"sourceList": [
"asm_json/input.sol",
"input.sol",
"#utility.yul"
]
}
4 changes: 2 additions & 2 deletions test/cmdlineTests/asm_json_no_pretty_print/output

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/cmdlineTests/ast_compact_json_no_pretty_json/output
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
JSON AST (compact format):


======= ast_compact_json_no_pretty_json/input.sol =======
{"absolutePath":"ast_compact_json_no_pretty_json/input.sol","exportedSymbols":{"C":[2]},"id":3,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"canonicalName":"C","contractDependencies":[],"contractKind":"contract","fullyImplemented":true,"id":2,"linearizedBaseContracts":[2],"name":"C","nameLocation":"69:1:0","nodeType":"ContractDefinition","nodes":[],"scope":3,"src":"60:13:0","usedErrors":[],"usedEvents":[]}],"src":"36:38:0"}
======= input.sol =======
{"absolutePath":"input.sol","exportedSymbols":{"C":[2]},"id":3,"license":"GPL-3.0","nodeType":"SourceUnit","nodes":[{"id":1,"literals":["solidity",">=","0.0"],"nodeType":"PragmaDirective","src":"36:22:0"},{"abstract":false,"baseContracts":[],"canonicalName":"C","contractDependencies":[],"contractKind":"contract","fullyImplemented":true,"id":2,"linearizedBaseContracts":[2],"name":"C","nameLocation":"69:1:0","nodeType":"ContractDefinition","nodes":[],"scope":3,"src":"60:13:0","usedErrors":[],"usedEvents":[]}],"src":"36:38:0"}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
JSON AST (compact format):


======= ast_compact_json_storage_layout_specifier/input.sol =======
======= input.sol =======
{
"absolutePath": "ast_compact_json_storage_layout_specifier/input.sol",
"absolutePath": "input.sol",
"exportedSymbols": {
"C": [
6
Expand Down
10 changes: 5 additions & 5 deletions test/cmdlineTests/ast_compact_json_with_base_path/output
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
JSON AST (compact format):


======= ast_compact_json_with_base_path/c.sol =======
======= c.sol =======
{
"absolutePath": "ast_compact_json_with_base_path/c.sol",
"absolutePath": "c.sol",
"exportedSymbols": {
"C": [
5
Expand Down Expand Up @@ -46,9 +46,9 @@ JSON AST (compact format):
],
"src": "36:38:0"
}
======= ast_compact_json_with_base_path/input.sol =======
======= input.sol =======
{
"absolutePath": "ast_compact_json_with_base_path/input.sol",
"absolutePath": "input.sol",
"exportedSymbols": {
"C": [
5
Expand All @@ -69,7 +69,7 @@ JSON AST (compact format):
"src": "36:22:1"
},
{
"absolutePath": "ast_compact_json_with_base_path/c.sol",
"absolutePath": "c.sol",
"file": "./c.sol",
"id": 2,
"nameLocation": "-1:-1:-1",
Expand Down
Loading