forked from maurelian/solidity-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 10
/
newTest.sh
executable file
·48 lines (40 loc) · 910 Bytes
/
newTest.sh
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
#!/bin/bash
num=0
for file in $(ls test/*.sol) ; do
base=$(basename $file .sol)
# get chars of basename before underscore
prefix=$(echo $base | cut -d_ -f1)
# if prefix is a number
if [[ $prefix =~ ^[0-9]+$ ]] ; then
# get the number
new_num=$prefix
fi
# compare new_num to num
if [ $new_num -gt $num ] ; then
num=$new_num
fi
done
num=$((num+1))
if [[ $1 ]] ; then
newTest=$1
else
# get input for new test
echo "Enter name of new test: "
read newTest
fi
# Replace spaces with _
newTest=${newTest// /_}
newfile="test/${num}_${newTest}.t.sol"
cat test/0_Template.t.sol \
| sed "s/TestX/Test$num/g" \
| sed "s/test_X/test_$newTest/g" \
> $newfile
echo
echo New test created: ${newTest}
echo
echo "To run tests:"
echo "forge test --mc Test${num}"
echo
echo "Edit the new test file:"
echo "code ${newfile}"
code . ${newfile}