Revert r180082 and add a test for SetEnv function