the use of /D option for popd looks ok to me
I would like to see tests for popd in case the directory saved in the pushd command no longer exists (to validate that the return_code value is the correct one)
* to be added to both test_builtins.bat and test_builtins.cmd in the success/failure PUSHD/POPD part
quick local test here show that the return_code is not the same as using CD to a non existing directory
also saving & restoring errorlevel in popd looks quite ugly ; it's likely preferable to introduce a helper to do the actual work of changing directory, and handle errorlevel outside of the helper