Fixed tests for ShellMessages failures.

Also delayed the invocation of System.gc until all temp directories are deleted, to improve build performance.