Is there a way to programatically test whether the current document is being compiled by (pdf)LaTeX or XeLaTeX?
There's also ifluatex. These packages define also
As Martin remarks, the iftex package does the work of both defining different conditionals. This package is automatically loaded with bidi.