Extract base main for tests.