testlib: improve test target handling