Deal with multiline environment variables in tests

If an environment variable has newlines in it, some of our own tests would
break due to the way we compare the output of reports with golden results.
Mangle the output of kyua a bit more so that our comparisons work.

Discovered by Travis CI builds where the non-root environment has changed
and now includes a rvm_debug environment variable that contains a function.
(Looks bogus on their side.)
Replace use of d_type member of struct dirent with stat()

Illumos does not have the d_type member in struct dirent. To be more
portable,

this web page:

http://stackoverflow.com/questions/2197918/cross-platform-way-of-testing-whether-a-file-is-a-directory

recommends converting code like this:

    if (de->d_type == DT_DIR)
    {
       return 0;
    }

to this:

    struct stat s; /*include sys/stat.h if necessary */
    ..
    ..
    stat(de->d_name, &s);
    if (s.st_mode & S_IFDIR)
    {
        return 0;
    }