Skip to content

Instantly share code, notes, and snippets.

@ormaaj
Created September 19, 2015 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ormaaj/1e4b7109983fc8861d0f to your computer and use it in GitHub Desktop.
Save ormaaj/1e4b7109983fc8861d0f to your computer and use it in GitHub Desktop.
$ doc/projects/bash/testcases/pattest.py
bash dash ksh mksh zsh bb posh jsh
x=\\; case \\x in "${x}""${x}"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in "${x}"${x}x) :;; *) false; esac 0 0 1 1 1 1 1 1
x=\\; case \\x in "${x}""\\"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in "${x}"\\x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in ${x}"${x}"x) :;; *) false; esac 1 0 1 1 1 1 1 1
x=\\; case \\x in ${x}${x}x) :;; *) false; esac 0 0 1 1 1 1 1 1
x=\\; case \\x in ${x}"\\"x) :;; *) false; esac 1 0 1 1 1 1 1 1
x=\\; case \\x in ${x}\\x) :;; *) false; esac 1 0 1 1 1 1 1 1
x=\\; case \\x in "\\""${x}"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in "\\"${x}x) :;; *) false; esac 0 0 1 1 1 1 1 1
x=\\; case \\x in "\\""\\"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in "\\"\\x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in \\"${x}"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in \\${x}x) :;; *) false; esac 0 0 1 1 1 1 1 1
x=\\; case \\x in \\"\\"x) :;; *) false; esac 1 1 1 1 1 1 1 1
x=\\; case \\x in \\\\x) :;; *) false; esac 1 1 1 1 1 1 1 1
~ $ cat doc/projects/bash/testcases/pattest.py
#!/usr/bin/env python3
import subprocess, itertools
class Shell(list):
def __init__(self, shell, cmds):
self.shell = shell
super().__init__([(x, self.__run(x)) for x in cmds])
def __iter__(self):
while True:
try:
self[0][1].communicate()
yield (lambda x: (x[0], x[1].returncode, self.shell))(self.pop(0))
except IndexError:
raise StopIteration()
def __run(self, cmd):
return subprocess.Popen([self.shell, "-c", cmd])
def main():
template = r'x=\\; case \\x in {0}{1}x) :;; *) false; esac'
tests = [template.format(*x) for x in itertools.product(['"${x}"', '${x}', r'"\\"', r'\\'], repeat=2)]
shells = [Shell(x, tests) for x in ["bash", "dash", "ksh", "mksh", "zsh", "bb", "posh", "jsh"]]
print(" " * 54, " ".join(x.shell for x in shells))
for row in zip(*shells):
print("{0:55}{1}".format(row[0][0], "".join(str(test) + (" " * len(shell)) for x, test, shell in row)))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment