Skip to content

Commit

Permalink
[test] Failing test cases for a couple bugs
Browse files Browse the repository at this point in the history
- issue #1850 - parsing command.Simple
- issue #1826 - crash with b'' literals and Id.Unknown_Tok
  • Loading branch information
Andy C committed Feb 27, 2024
1 parent 7cd9edb commit b34c74e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 44 deletions.
47 changes: 24 additions & 23 deletions mycpp/examples/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#from mycpp.mylib import switch, str_switch, log
from mycpp.mylib import switch, log


def TestString(s):
# type: (str) -> None

Expand All @@ -28,37 +29,37 @@ def TestString(s):


def run_tests():
# type: () -> None
# type: () -> None

TestString('spam')
TestString('foo')
TestString('zzz')
TestString('spam')
TestString('foo')
TestString('zzz')

x = 5
with switch(x) as case:
if case(0):
print('zero')
print('zero')
x = 5
with switch(x) as case:
if case(0):
print('zero')
print('zero')

elif case(1, 2):
print('one or two')
elif case(1, 2):
print('one or two')

elif case(3, 4):
print('three or four')
elif case(3, 4):
print('three or four')

else:
print('default')
print('another')
else:
print('default')
print('another')


def run_benchmarks():
# type: () -> None
raise NotImplementedError()
# type: () -> None
raise NotImplementedError()


if __name__ == '__main__':
if os.getenv('BENCHMARK'):
log('Benchmarking...')
run_benchmarks()
else:
run_tests()
if os.getenv('BENCHMARK'):
log('Benchmarking...')
run_benchmarks()
else:
run_tests()
40 changes: 20 additions & 20 deletions mycpp/examples/varargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@

from typing import Any


CONST = "myconst"


def run_tests():
# type: () -> None
# type: () -> None

log('constant string')
log('constant string')

print_stderr('stderr_line')
print_stderr('stderr_line')

# Positional args
log("log %d %s", 42, "LL")
# Positional args
log("log %d %s", 42, "LL")

# Escaped %%
log("[%%] %d %s", 42, "LL")
# Escaped %%
log("[%%] %d %s", 42, "LL")

log(CONST)
log(CONST)


def run_benchmarks():
# type: () -> None
# type: () -> None

# Test the interpreted format strings vs. the compiler!
# This might not be enough to get over startup time
r = "'repr'" + ' "repr"'
for i in xrange(10000):
log("[%%] %d %s %r", 123456789, "string", r)
# Test the interpreted format strings vs. the compiler!
# This might not be enough to get over startup time
r = "'repr'" + ' "repr"'
for i in xrange(10000):
log("[%%] %d %s %r", 123456789, "string", r)


if __name__ == '__main__':
if os.getenv('BENCHMARK'):
log('Benchmarking...')
run_benchmarks()
else:
run_tests()
if os.getenv('BENCHMARK'):
log('Benchmarking...')
run_benchmarks()
else:
run_tests()
34 changes: 33 additions & 1 deletion spec/ysh-scope.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## oils_failures_allowed: 1
## oils_failures_allowed: 2

# Demonstrations for users. Could go in docs.

Expand Down Expand Up @@ -359,6 +359,38 @@ AFTER mutate
(Dict) {"key":"mutated","key2":"mutated"}
## END

#### setglobal a[i] inside proc

shopt -s ysh:upgrade

var a = [0]

proc mutate {
var a = [1] # shadows global var

echo 'hi from mutate'
setglobal a[0] = 42

pp line (a)
}

echo 'BEFORE mutate'
pp line (a)

mutate

echo 'AFTER mutate'
pp line (a)

## STDOUT:
BEFORE mutate
(List) [0]
hi from mutate
(List) [42]
AFTER mutate
(List) [42]
## END


#### unset inside proc uses local scope
shopt --set parse_brace
Expand Down
42 changes: 42 additions & 0 deletions test/ysh-parse-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,37 @@ test-oils-issue-1118() {
'
}

test-oils-issue-1850() {
_ysh-should-parse 'pp line (42); pp line (43)'
#_osh-should-parse 'pp line (42); pp line (43)'

return

# Extra word is bad
_ysh-parse-error 'pp line (42) extra'

# Bug -- newline or block should come after arg list
_ysh-parse-error 'pp line (42), echo'

# This properly checks a similar error. It's in a word.
_ysh-parse-error 'pp line @(echo), echo'

# Common cases
_ysh-should-parse 'pp line (42)'
_ysh-should-parse 'pp line (42) '
_ysh-should-parse 'pp line (42);'
_ysh-should-parse 'pp line (42) { echo hi }'

return

# Original bug

# Accidental comma instead of ;
# Wow this is parsed horribly
# Why does this replace (42) with (43)
_ysh-parse-error 'pp line (42), pp line (43)'
}

test-proc-args() {
set +o errexit

Expand Down Expand Up @@ -1363,6 +1394,17 @@ hi
'
}

test-bug-1826() {
return

read -r code_str << 'EOF'
echo b'\xff'
EOF

_parse-error "$code_str"
}


#
# Entry Points
#
Expand Down

0 comments on commit b34c74e

Please sign in to comment.