Getting Started with Whisker
Install
Whisker needs the Go toolchain, version 1.27 or later: whisker turns your program into Go and asks Go to compile it.
With Homebrew:
brew install 135yshr/tap/whisker
With Go:
go install github.com/135yshr/meow/cmd/whisker@latest
Or download an archive for macOS, Linux or Windows from the releases page. Check the install with:
whisker version
Your first program
Save this as hello.wsk:
fn greet(name string) string {
return "Hello, " + name + "!"
}
print(greet("World"))Run it:
whisker run hello.wsk
# Hello, World!
whisker hello.wsk does the same.
Build a binary
whisker build hello.wsk -o hello
./hello
The binary needs nothing else to run: no Whisker, no Go.
To see the Go that Whisker writes, without building it:
whisker transpile hello.wsk
A function whose parameters and result are all int, float, string or bool gets a plain Go signature, and its arithmetic is Go arithmetic. Everything else is carried in the runtime’s Value type.
Test
A file named foo_test.wsk holds tests for foo.wsk. A function whose name starts with test_ is a test:
// math_test.wsk
fn test_add() {
assert_eq(1 + 2, 3)
}whisker test
whisker test finds every _test.wsk file in the current directory. It can also run fuzz tests (-fuzz), measure coverage (-cover) and mutation-test your tests (-mutate).
A function named prop_… is a property: it runs on generated inputs instead of one you chose, and a failing input is shrunk to a small one. Every parameter needs a type annotation.
// math_test.wsk
fn prop_add_commutative(a int, b int) {
assert(a + b == b + a)
}whisker test runs a property on 100 inputs. -prop-count <n> changes that, and a failure prints a seed that -seed <n> replays.
Format and lint
whisker fmt -w hello.wsk
whisker lint ./...
Next steps
- Take the Tour of Whisker, which ends with contracts: what a function needs and promises, checked as it runs and proved with
whisker verify. - Keep the Quick Reference open while you write.
- Try programs in the Playground without installing anything.