Only check file type if there is a file, also adding tests for #272.