Add register / clear warnings API

Also add a unit test.

Fixes #51