Skip to content

Commit

Permalink
Merge pull request #13 from xonixx/multiline
Browse files Browse the repository at this point in the history
Multiline
  • Loading branch information
xonixx committed Jun 11, 2023
2 parents 904e783 + f753a97 commit 0e70ab0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
12 changes: 10 additions & 2 deletions fhtagn.awk
Expand Up @@ -14,7 +14,7 @@ function initTmpRnd( c) {
c | getline Rnd # additional source of "random"
close(c)
}
function fhtagn( i,file,err,l,code,nr,line,random,exitCode,stdOutF,stdErrF,testStarted,expected) {
function fhtagn( i,file,err,l,code,nr,line,random,exitCode,stdOutF,stdErrF,testStarted,expected,hasMoreCode) {
for (i = 1; i < ARGC; i++) {
file = ARGV[i]
for (nr = 1; (err = getline l < file) > 0; nr++) {
Expand All @@ -28,7 +28,12 @@ function fhtagn( i,file,err,l,code,nr,line,random,exitCode,stdOutF,stdErrF,tes
stdErrF = tmpFile(random, "err")
code = substr(l,2)
line = nr
exitCode = system("(" code ") 1>" stdOutF " 2>" stdErrF) # can it be that {} are better than ()?
if (!(hasMoreCode = l ~ /\\$/))
exitCode = run(code,stdOutF,stdErrF)
} else if (hasMoreCode) {
code = code "\n" l
if (!(hasMoreCode = l ~ /\\$/))
exitCode = run(code,stdOutF,stdErrF)
} else if (l ~ /^[|@?]/) {
# parse result block (|@?)
expected = expected l "\n"
Expand Down Expand Up @@ -70,5 +75,8 @@ function prefixFile(prefix, fname, l,res,err) {
close(fname)
return res
}
function run(code,stdOutF,stdErrF) {
return system("(" code ") 1>" stdOutF " 2>" stdErrF) # can it be that {} are better than ()?
}
function rndS() { return int(2147483647 * rand()) "." Rnd }
function tmpFile(random, ext) { return sprintf("%s/%s.%s.%s", Tmp, Prog, random, ext) }
28 changes: 28 additions & 0 deletions tests/4-multiline.tush
@@ -0,0 +1,28 @@

OK 1
====

$ echo 111; \
echo 222
| 111
| 222

OK 2
====

$ echo 111; \
echo 222; \
echo 333 >&2 ; \
exit 7
| 111
| 222
@ 333
? 7

Test err
========

$ echo 111; \
echo 222
| 111
| 777
11 changes: 11 additions & 0 deletions tests/fhtagn.tush
Expand Up @@ -58,3 +58,14 @@ $ cd "$MYDIR"; ALL=1 ./tests/trimBlank.sh $FHTAGN tests/1.tush tests/2.tush test
| ---blank---
| result=FAIL, failure=2, success=4, total=6, files=3

$ cd "$MYDIR"; ./tests/trimBlank.sh $FHTAGN tests/4-multiline.tush
| tests/4-multiline.tush:25: $ echo 111; \
| echo 222
| --- expected
| +++ actual
| @@ -1,3 +1,3 @@
| | 111
| -| 777
| +| 222
| ---blank---
? 1

0 comments on commit 0e70ab0

Please sign in to comment.