title: How to test panics?
body: <p>I'm currently pondering how to write tests that check if a given piece of code panicked? I know that Go uses <a href="https://golang.org/doc/effective_go.html#recover" rel="noreferrer"><code>recover</code></a> to catch panics, but unlike say, Java code, you can't really specify what code should be skipped in case of a panic or what have you. So if I have a function:</p>
  
  <pre><code>func f(t *testing.T) {
      defer func() {
          if r := recover(); r != nil {
              fmt.Println("Recovered in f", r)
          }
      }()
      OtherFunctionThatPanics()
      t.Errorf("The code did not panic")
  }
  </code></pre>
  
  <p>I can't really tell whether <code>OtherFunctionThatPanics</code> panicked and we recovered, or if the function did not panic at all. How do I specify which code to skip over if there is no panic and which code to execute if there is a panic? How can I check whether there was some panic we recovered from?</p>