Create test for dependencies override and move override logic.

Create test for `dependencies` override and move override logic (for both `dependencies` and `main`) in a more... logical place.

The code was kinda hard to follow to see what was happening with the `dependencies` override, so I moved it at @stephenplusplus' suggestion.

We also didn't have a test testing all this `dependencies` voodoo, so I made one for that.