oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.82k stars 154 forks source link

describe builtin for test framework #1022

Open andychu opened 2 years ago

andychu commented 2 years ago
proc p {
  echo hi
}

describe p {
  it 'prints to stdout' {
    p | grep hi   # do we turn off errexit here or something?
  }
}

depends on #631

Problem: for some legacy scripts, it would be useful to use a compatible shell test framework, not an incompatible one.

Possible solution: generate a shell script that's equivalent! or run it directly.

Hence running sharness, etc. which is #946

that seemed like the most promising one

andychu commented 2 years ago

on your wiki: "OSH Test Framework"

andychu commented 2 years ago

Also I looked into the TAP protocol

Would be nice to combine with our Python tests perhaps?

andychu commented 2 years ago

Actually ShellSpec has this DSL, it looks very elaborate

https://github.com/shellspec/shellspec#syntax-formatter-altshfmt

And appears to do code generation

I would like something that is in OSH syntax though. After we implement Oil blocks #631 I should ask the maintainer about it

andychu commented 2 years ago

I realized with the new typed args we can do something like

assert (status === 2)
assert (stdout === $'hello\n')
assert (stdout === '''
  hello
  ''')

expect (status === 2)

Although I think we shouldn't clobber the "expect" tool. TODO: see what other test frameworks use

andychu commented 2 years ago

Re-read this article: https://thomaslevine.com/computing/shell-testing/