From e8e097cf0e0b03bedb3eb35dd34ad01537abc7a9 Mon Sep 17 00:00:00 2001 From: Konstantinos Kallas Date: Wed, 22 Jun 2022 18:58:32 -0400 Subject: [PATCH] Fix redir variable parsing bug (#582) Signed-off-by: Konstantinos Kallas --- compiler/parser/ceda/ast2a.py | 24 +++++++++---------- .../tests/interface_tests/redir-var-test.sh | 10 ++++++++ evaluation/tests/interface_tests/run.sh | 7 ++++++ 3 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 evaluation/tests/interface_tests/redir-var-test.sh diff --git a/compiler/parser/ceda/ast2a.py b/compiler/parser/ceda/ast2a.py index e9b65c691..239b70fea 100644 --- a/compiler/parser/ceda/ast2a.py +++ b/compiler/parser/ceda/ast2a.py @@ -163,25 +163,25 @@ def mk_file (ty, n): return ["File", [ty, n.nfile.fd, arg]]; -def mk_dup (ty, n): - ndup = n.ndup; - vname = ndup.vname; - - tgt = []; +def mk_dup(ty, n): + ndup = n.ndup + vname = ndup.vname + + tgt = [] if (not vname): - dupfd = ndup.dupfd; + dupfd = ndup.dupfd if (dupfd == -1): - tgt.append (["C", ORD_MINUS]); + tgt.append(["C", ORD_MINUS]) else: - dupfd_str = str (dupfd); + dupfd_str = str(dupfd) - for i in range (len (dupfd_str)): - tgt.append (["C", ord (dupfd_str [i])]); + for i in range(len(dupfd_str)): + tgt.append(["C", ord(dupfd_str[i])]) else: - tgt = to_arg (vname.narg); + tgt = to_arg(vname.contents.narg) - return (["Dup", [ty, ndup.fd, tgt]]); + return (["Dup", [ty, ndup.fd, tgt]]) def mk_here (ty, n): diff --git a/evaluation/tests/interface_tests/redir-var-test.sh b/evaluation/tests/interface_tests/redir-var-test.sh new file mode 100644 index 000000000..e82ffd7cb --- /dev/null +++ b/evaluation/tests/interface_tests/redir-var-test.sh @@ -0,0 +1,10 @@ +#!/bin/sh +func_emit_tests_Makefile_am () +{ + ofd=3 + { + echo hi + } >&$ofd +} +fd=1 +echo hi >&$fd diff --git a/evaluation/tests/interface_tests/run.sh b/evaluation/tests/interface_tests/run.sh index c97b16b74..a7fba89ec 100755 --- a/evaluation/tests/interface_tests/run.sh +++ b/evaluation/tests/interface_tests/run.sh @@ -297,6 +297,12 @@ test_exclam() $shell test-exclam.sh } +test_redir_var_test() +{ + local shell=$1 + $shell redir-var-test.sh +} + ## We run all tests composed with && to exit on the first that fails if [ "$#" -eq 0 ]; then run_test test1 @@ -337,6 +343,7 @@ if [ "$#" -eq 0 ]; then run_test test_quoting run_test test_var_assgn_default run_test test_exclam + run_test test_redir_var_test else for testname in $@ do