@Test
  public void checkDanglingQOut() {
    SetView<File> dangling = Sets.difference(outsFound, outsNeeded.keySet());
    assertTrue("dangling qouts: "+dangling,dangling.isEmpty());
  }
This test ensures that there are no dangling q.out files in the project

It has a cli functionlity to remove them if there are any.
itests/util/src/test/java/org/apache/hadoop/hive/cli/control/TestDanglingQOuts.java