Skip to content

Commit

Permalink
Revamp @define #140 : fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Sep 18, 2023
1 parent 153a4ec commit 69df7ac
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 85 deletions.
11 changes: 8 additions & 3 deletions makesure.awk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BEGIN {
function makesure( i) {
while (getline > 0) {
Lines[NR] = $0
if ($1 ~ /^@/ && "@reached_if" != $1) reparseCli()
if ($1 ~ /^@/ && "@reached_if" != $1) if (reparseCli() < 0) continue
if ("@options" == $1) handleOptions()
else if ("@define" == $1) handleDefine()
else if ("@shell" == $1) handleShell()
Expand Down Expand Up @@ -147,7 +147,11 @@ function handleDefine() {
# $1 = ""
# handleDefineLine($0)
if (NF != 3) {
addError("@define NF != 3") # TODO better error msg
addError("Invalid @define syntax, should be @define VAR_NAME 'value'")
return
}
if ($2 !~ /^[A-Za-z_][A-Za-z0-9_]*$/) {
addError("Wrong variable name: '" $2 "'")
return
}
if (!($2 in DefineOverrides))
Expand Down Expand Up @@ -905,7 +909,8 @@ function reparseCli( res,i,err) {
err = parseCli_2($0, Vars, res)
if (err) {
addError("Syntax error: " err)
die(Error)
# die(Error)
return -1
} else {
$0 = "" # only for macos 10.15 awk version 20070501
for (i = NF = 0; i in res; i++) {
Expand Down
6 changes: 5 additions & 1 deletion tests/10_define.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@define A aaa
@define B "${A}bbb"
@define Commented value # just a comment
@define echo 'Hello'

@goal testA
echo A=$A
Expand Down Expand Up @@ -41,4 +42,7 @@ echo C=$C

@goal test_commented_define
echo "in goal: $Commented"
sh -c 'echo in child process: $Commented'
sh -c 'echo in child process: $Commented'

@goal echo
echo "$echo"
7 changes: 4 additions & 3 deletions tests/10_define.tush
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/10_define.sh test_commented_define
| in goal: value
| in child process: value

$ cd "$MYDIR"; ./$MAKESURE -f tests/10_define.sh echo
| goal 'echo' ...
| Hello

$ cd "$MYDIR"; ./$MAKESURE -f tests/10_define_in_goal.sh
@ Shell code is not allowed outside goals/libs:
@ tests/10_define_in_goal.sh:4: echo "$0"
Expand All @@ -80,6 +84,3 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/10_define_in_goal.sh
$ cd "$MYDIR"; ./$MAKESURE -f tests/10_define_issue_142.sh issue142
| goal 'issue142' ...
| a b



110 changes: 55 additions & 55 deletions tests/16_define_validation.tush
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

$ cd "$MYDIR"; ./$MAKESURE -f tests/16_define_validation.sh
$ cd "$MYDIR"; ./$MAKESURE -f tests/16_define_validation_pass.sh
| goal 'default' ...
| EMPTY=
| EMPTY1=
Expand Down Expand Up @@ -31,67 +31,67 @@ $ cd "$MYDIR"; ./$MAKESURE -f tests/16_define_validation.sh
| LC1=aaabbb bbbcc'c cc'ca b ceee eee

$ cd "$MYDIR"; ./$MAKESURE -f tests/16_define_validation_error.sh
@ Invalid define declaration:
@ Invalid @define syntax, should be @define VAR_NAME 'value':
@ tests/16_define_validation_error.sh:2: @define echo
@ Invalid define declaration:
@ Syntax error: wrong unquoted: 'echo;':
@ tests/16_define_validation_error.sh:3: @define echo;
@ Invalid define declaration:
@ Syntax error: wrong unquoted: 'echo;echo':
@ tests/16_define_validation_error.sh:4: @define echo;echo
@ Invalid define declaration:
@ Syntax error: wrong unquoted: ';':
@ tests/16_define_validation_error.sh:5: @define echo ; echo
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:6: @define echo 'Hello'
@ Invalid define declaration:
@ Syntax error: wrong unquoted: 'echo='Hello'':
@ tests/16_define_validation_error.sh:6: @define echo='Hello'
@ Syntax error: joined arguments:
@ tests/16_define_validation_error.sh:7: @define echo 'Hello';
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:8: @define A=aaa echo 'Hello'
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:9: @define B=aaa\ aaa echo 'Hello'
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:10: @define C='aaa aaa' echo 'Hello'
@ Invalid define declaration:
@ Invalid @define syntax, should be @define VAR_NAME 'value':
@ tests/16_define_validation_error.sh:8: @define A aaa echo 'Hello'
@ Syntax error: wrong unquoted: 'aaa\':
@ tests/16_define_validation_error.sh:9: @define B aaa\ aaa echo 'Hello'
@ Invalid @define syntax, should be @define VAR_NAME 'value':
@ tests/16_define_validation_error.sh:10: @define C 'aaa aaa' echo 'Hello'
@ Invalid @define syntax, should be @define VAR_NAME 'value':
@ tests/16_define_validation_error.sh:12: @define echo # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:13: @define echo 'Hello' # comment
@ Invalid define declaration:
@ Syntax error: wrong unquoted: 'echo='Hello'':
@ tests/16_define_validation_error.sh:13: @define echo='Hello' # comment
@ Syntax error: joined arguments:
@ tests/16_define_validation_error.sh:14: @define echo 'Hello'; # comment
@ Invalid define declaration:
@ Syntax error: wrong unquoted: ';#':
@ tests/16_define_validation_error.sh:15: @define echo 'Hello' ;# comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:16: @define A=aaa echo 'Hello' # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:17: @define B=aaa\ aaa echo 'Hello'# comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:18: @define C='aaa aaa' echo 'Hello' # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:19: @define C1='aaa aaa' echo 'Hello' ; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:22: @define B3='bbb ; bbb';
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:23: @define B4='bbb ; bbb' ;
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:24: @define BC3='bbb bbb'; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:25: @define BC4='bbb ; bbb' ; # comment
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:28: @define IL1=a||b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:29: @define IL2=a&b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:30: @define IL3=a&&b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:31: @define IL4=a!b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:32: @define IL5=a-b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:33: @define IL6=a+b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:34: @define IL7=a;;;b
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:36: @define 0wrong_name=123
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:37: @define wrong,name=123
@ Invalid define declaration:
@ tests/16_define_validation_error.sh:38: @define wrong-name=123
@ Invalid @define syntax, should be @define VAR_NAME 'value':
@ tests/16_define_validation_error.sh:16: @define A aaa echo 'Hello' # comment
@ Syntax error: wrong unquoted: 'aaa\':
@ tests/16_define_validation_error.sh:17: @define B aaa\ aaa echo 'Hello'# comment
@ Invalid @define syntax, should be @define VAR_NAME 'value':
@ tests/16_define_validation_error.sh:18: @define C 'aaa aaa' echo 'Hello' # comment
@ Syntax error: wrong unquoted: ';':
@ tests/16_define_validation_error.sh:19: @define C1 'aaa aaa' echo 'Hello' ; # comment
@ Syntax error: joined arguments:
@ tests/16_define_validation_error.sh:22: @define B3 'bbb ; bbb';
@ Syntax error: wrong unquoted: ';':
@ tests/16_define_validation_error.sh:23: @define B4 'bbb ; bbb' ;
@ Syntax error: joined arguments:
@ tests/16_define_validation_error.sh:24: @define BC3 'bbb bbb'; # comment
@ Syntax error: wrong unquoted: ';':
@ tests/16_define_validation_error.sh:25: @define BC4 'bbb ; bbb' ; # comment
@ Syntax error: wrong unquoted: 'a||b':
@ tests/16_define_validation_error.sh:28: @define IL1 a||b
@ Syntax error: wrong unquoted: 'a&b':
@ tests/16_define_validation_error.sh:29: @define IL2 a&b
@ Syntax error: wrong unquoted: 'a&&b':
@ tests/16_define_validation_error.sh:30: @define IL3 a&&b
@ Syntax error: wrong unquoted: 'a!b':
@ tests/16_define_validation_error.sh:31: @define IL4 a!b
@ Syntax error: wrong unquoted: 'a-b':
@ tests/16_define_validation_error.sh:32: @define IL5 a-b
@ Syntax error: wrong unquoted: 'a+b':
@ tests/16_define_validation_error.sh:33: @define IL6 a+b
@ Syntax error: wrong unquoted: 'a;;;b':
@ tests/16_define_validation_error.sh:34: @define IL7 a;;;b
@ Wrong variable name: '0wrong_name':
@ tests/16_define_validation_error.sh:36: @define 0wrong_name 123
@ Syntax error: wrong unquoted: 'wrong,name':
@ tests/16_define_validation_error.sh:37: @define wrong,name 123
@ Syntax error: wrong unquoted: 'wrong-name':
@ tests/16_define_validation_error.sh:38: @define wrong-name 123
? 1

46 changes: 23 additions & 23 deletions tests/16_define_validation_error.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@
@define echo;
@define echo;echo
@define echo ; echo
@define echo 'Hello'
@define echo='Hello'
@define echo 'Hello';
@define A=aaa echo 'Hello'
@define B=aaa\ aaa echo 'Hello'
@define C='aaa aaa' echo 'Hello'
@define A aaa echo 'Hello'
@define B aaa\ aaa echo 'Hello'
@define C 'aaa aaa' echo 'Hello'

@define echo # comment
@define echo 'Hello' # comment
@define echo='Hello' # comment
@define echo 'Hello'; # comment
@define echo 'Hello' ;# comment
@define A=aaa echo 'Hello' # comment
@define B=aaa\ aaa echo 'Hello'# comment
@define C='aaa aaa' echo 'Hello' # comment
@define C1='aaa aaa' echo 'Hello' ; # comment
@define A aaa echo 'Hello' # comment
@define B aaa\ aaa echo 'Hello'# comment
@define C 'aaa aaa' echo 'Hello' # comment
@define C1 'aaa aaa' echo 'Hello' ; # comment

# Let's disallow ';' for simplicity and unification
@define B3='bbb ; bbb';
@define B4='bbb ; bbb' ;
@define BC3='bbb bbb'; # comment
@define BC4='bbb ; bbb' ; # comment
@define B3 'bbb ; bbb';
@define B4 'bbb ; bbb' ;
@define BC3 'bbb bbb'; # comment
@define BC4 'bbb ; bbb' ; # comment

# Illegal chars. This is more restrictive than shell but simpler to parse
@define IL1=a||b
@define IL2=a&b
@define IL3=a&&b
@define IL4=a!b
@define IL5=a-b
@define IL6=a+b
@define IL7=a;;;b
@define IL1 a||b
@define IL2 a&b
@define IL3 a&&b
@define IL4 a!b
@define IL5 a-b
@define IL6 a+b
@define IL7 a;;;b

@define 0wrong_name=123
@define wrong,name=123
@define wrong-name=123
@define 0wrong_name 123
@define wrong,name 123
@define wrong-name 123

@goal default
echo 'Should not show'
Expand Down
File renamed without changes.

0 comments on commit 69df7ac

Please sign in to comment.