SamirTalwar / smoke

Runs tests against anything, using command-line arguments, STDIN, STDOUT and STDERR.
MIT License
88 stars 10 forks source link

--bless adds Windows newlines in binary files #61

Closed codecop closed 2 years ago

codecop commented 2 years ago

Hi Samir, hope you are doing well. I am using latest Smoke to test some command line tools. Some tools create binary output, e.g. BMP images. In these situations,

  - name: "XCOLOR"
    command: "..\\bin\\XCOLOR 80x25x256.bmp test.out 0 1"
    files:
      - path: test.out
        contents:
          file: xcolor.bmp

the xcolor.bmp had 0d added before all 0a bytes. I am using Windows. I guess it is something of the fwrite/C function or mode of file you use. Or maybe we need a switch to indicate binary files?

SamirTalwar commented 2 years ago

Yes, you're right; Smoke assumes that the file is text and writes with the system line endings. I think it would be great to support a "binary" mode, where files are read and written in binary mode, and error output is shown using hex, not writing a nonsensical diff.

However, diffing a binary is kind of beyond me right now; I don't have the time to look into it.

As a workaround, you could consider using output filters to pipe the file through something like hexdump (looks like this is available as part of the Cygwin util-linux package); this would effectively convert it to ASCII so diffs and the --bless flag will work correctly. You can see an example of filters in https://github.com/SamirTalwar/smoke/blob/v2.3.0/fixtures/processing-filters/smoke.yaml.

codecop commented 2 years ago

Thank you. So it is known. All good then.

SamirTalwar commented 2 years ago

Known, but not solved. If you would like this feature, please re-open the issue and I'll try and make time in the next month or so. If you like, we can pair on it. 😃

codecop commented 2 years ago

Thank you for offering it. Not at the moment...