It may come as a shock to those in the Academia.SE environment that tend to be biased a bit towards disciplines involving code due to the connection with StackOverflow, but some disciplines don't involve programming at all! So of course generally no, PhD advisors are not "supposed to know" programming.
In a field where programming is the norm, then you can expect that anyone advising students in that field at a minimum did some programming at least in their past life as a student. For some, their programming knowledge may be stuck in the past (I imagine that professors are highly overrepresented in the population "current users of FORTRAN") or out of practice. For others, part of their job involves specifically teaching students to code (though the prior sentence may still apply..), or they still program as part of their research and are more on par with the students in their lab.
In summary: it depends, but you can certainly ask. You should have a better idea than anyone here whether it's reasonable to expect your specific advisor to have programming knowledge. However, I wouldn't bring basic programming questions to your advisor, or really anyone else, until you've made a solid effort to find a solution on your own.
As far as your own code, you're the one personally responsible for getting it "right". You shouldn't expect your advisor to grade your work the way an instructor would for a course. The ways to find that your code is working properly involve some combination of good proofreading and documentation of your own code (principles like breaking up your code into brief functions with clear and limited purpose can help immensely with this) and testing; I'd put the emphasis on the latter. Make sure your code is working right by giving it problems where you know or can verify the output. How to do this properly is a subject that could fill libraries.