Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bc: test if #174

Open
briandfoy opened this issue Jun 21, 2023 · 3 comments
Open

bc: test if #174

briandfoy opened this issue Jun 21, 2023 · 3 comments
Labels
Priority: low get to this whenever Program: bc The bc program Type: testing testing, that is not an existing test bug

Comments

@briandfoy
Copy link
Owner

No description provided.

@briandfoy briandfoy added Priority: low get to this whenever Program: bc The bc program Type: testing testing, that is not an existing test bug labels Jun 21, 2023
@mknos
Copy link
Contributor

mknos commented Sep 28, 2023

$ cat bc.sh 
#!/bin/sh

BC='perl bc'

bc()
{
    code="$1"
    echo "$code" | $BC | fgrep -c ok
}

for tst in \
  'if (0 == 0) { print "ok"; }' \
  'if (1 != 0) { print "ok"; }' \
  'if (1 > 0) { print "ok"; }' \
  'if (0 < 1) { print "ok"; }' \
  'a=2; if (a == 2) { print "ok"; }' \
  'a=2; if (a == 2 && 1 == 1) { print "ok"; }' \
; do
    ok=$(bc "$tst")
    echo "SUCCESS=$ok -- $tst"
    if [ $ok != 1 ]; then
        echo ABORT
	exit 1
    fi
done
echo 'ALL OK'
exit 0

$ ./bc.sh  
SUCCESS=1 -- if (0 == 0) { print "ok"; }
SUCCESS=1 -- if (1 != 0) { print "ok"; }
SUCCESS=1 -- if (1 > 0) { print "ok"; }
SUCCESS=1 -- if (0 < 1) { print "ok"; }
SUCCESS=1 -- a=2; if (a == 2) { print "ok"; }
SUCCESS=0 -- a=2; if (a == 2 && 1 == 1) { print "ok"; }
ABORT

@briandfoy
Copy link
Owner Author

Thanks, I'll look at this and integrate it and move on your PR.

@mknos
Copy link
Contributor

mknos commented Oct 6, 2023

SUCCESS=0 -- a=2; if (a == 2 && 1 == 1) { print "ok"; }

I didn't investigate why this was happening. But now I think it could be an order of operation problem because adding more parens makes it evaluate to true:

a=2; if ((a==2) && (1==1)) { print "ok"; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: low get to this whenever Program: bc The bc program Type: testing testing, that is not an existing test bug
Projects
None yet
Development

No branches or pull requests

2 participants