[Chapel Merge] Fix issue with handling of catfiles that specify b

Branch: refs/heads/master
Revision: e1c61f2
Author: lydia-duncan
Log Message:

Merge pull request #16696 from lydia-duncan/fixSubtestForCRay

Fix issue with handling of catfiles that specify binary files in sub_test
[reviewed by @ronawho]

Prior to this change, if a compilation error caused
test/exercises/c-ray/old/c-ray to fail, we would get the message:

[Concatenating extra files: c-ray.catfiles]
Traceback (most recent call last):
  File "<$CHPL_HOME>/util/test/sub_test.py", line 1650, in <module>
    output += p.communicate()[0]
TypeError: must be str, not bytes
[Finished subtest "exercises/c-ray/old" - 44.944 seconds]

[Error 1 running sub_test in <$CHPL_HOME>/test/exercises/c-ray/old]

This was because we were trying to concatenate binary output into a value that
was a string (because the output from the compiler failure was a string).

With this change, we now get:

[Concatenating extra files: c-ray.catfiles]
[Executing binary diff c-ray.good c-ray.2.comp.out.tmp]
Binary files differed
[Error matching compiler output for exercises/c-ray/old/c-ray (compopts: 2)]
Instead of directly trying to concatenate the catfiles output, first check if it is of type bytes when the previous output is of type string. If so, try to decode the catfiles output, falling back to making all the output bytes if that fails. Then, if we have fallen back to using bytes because we couldn't decode the catfiles output, use DiffBinaryFiles instead of DiffFiles.

I also adjusted DiffBinaryFiles to not call trim_output, since trim_output
assumes it is given a string - when trim_output is instead given a bytes with
contents that don’t translate to a string, we get an error “'in ’
requires string as left operand, not int” when trying to replace not-printable
contents of the string with “~”

Passed a full paratest with futures, seemed to track the same number of tests.

Modified Files:
M util/test/sub_test.py

Compare: https://github.com/chapel-lang/chapel/compare/36921709813e...e1c61f2b2d9b