General-relativistic resistive magnetohydrodynamics in three dimensions: Formulation and tests