-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathassert_macro_compilation_failure.sh
More file actions
executable file
·85 lines (69 loc) · 2.85 KB
/
assert_macro_compilation_failure.sh
File metadata and controls
executable file
·85 lines (69 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
# File: test_failure_contracts.sh
# Description: This script tests that compilation fails for contracts within the
# 'failure_contracts' directory, as they contain code designed to break compilation
# (e.g., due to code generated by macros).
# --- Configuration and Environment ---
# Resolve the absolute path to the repository root.
REPO=$(git rev-parse --show-toplevel)
# Define the path to the Nargo binary. Allow override via environment variable.
# :? makes sure $NARGO is set, if not, it uses the default path.
NARGO=${NARGO:-"$REPO/noir/noir-repo/target/release/nargo"}
FAILURE_CONTRACTS_DIR="$(dirname "${BASH_SOURCE[0]}")/failure_contracts"
# --- Colors for Output ---
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly NC='\033[0m' # No Color
# --- Counters ---
total_tests=0
passed_tests=0
# --- Core Function ---
# Function to test compilation failure for a given contract directory.
test_compilation_failure() {
local contract_dir="$1"
((total_tests++))
echo -e "${YELLOW}-> Testing compilation failure for: $(basename "$contract_dir")${NC}"
# Use pushd/popd for cleaner directory management and error handling.
pushd "$contract_dir" > /dev/null
# Try to compile the contract.
# We redirect stderr (2>) to a temporary file instead of /dev/null to inspect the error message if needed.
# The '|| true' prevents the whole script from exiting if the command fails, which is expected here.
if "$NARGO" compile --pedantic-solving 2> compile_error.log; then
# Check if the compilation succeeded (exit code 0). This is the failure case.
echo -e "${RED}❌ Test FAILED: Compilation succeeded when it should have failed.${NC}"
popd > /dev/null
return 1
else
# Check if the compilation failed (non-zero exit code). This is the success case.
echo -e "${GREEN}✓ Test PASSED: Compilation failed as expected.${NC}"
# Cleanup the temporary error log file.
rm -f compile_error.log
((passed_tests++))
popd > /dev/null
return 0
fi
}
# --- Main Execution ---
# Check if the Nargo binary exists before running tests
if [ ! -x "$NARGO" ]; then
echo -e "${RED}Error: Nargo binary not found at '$NARGO'. Please build it or set the NARGO environment variable.${NC}"
exit 1
fi
# Test each subdirectory (contract) in the failure_contracts directory
for contract in "$FAILURE_CONTRACTS_DIR"/*; do
if [ -d "$contract" ]; then
test_compilation_failure "$contract"
fi
done
# --- Summary and Exit ---
echo -e "\n--- Test Summary ---"
echo -e "Total tests: ${total_tests}"
echo -e "Passed tests: ${passed_tests}"
echo -e "Failed tests: $((total_tests - passed_tests))"
# Exit with status 0 if all tests passed, 1 otherwise.
if [ "$total_tests" -eq "$passed_tests" ]; then
exit 0
else
exit 1
fi