[loader] Check if requires list passes tests and add optionals to it

This way _sort() has knowledge of optional requires to sort them as
dependencies