I'm looking at getting the shell tests passing, but have a dilemma (quadlemma?) regarding newlines in the YAML output.
The beanstalkd protocol uses CR+LF newlines, but the YAML in stats, stats-job and stats-tube commands uses LF newlines. This makes it very difficult to write *.expected files that contain beanstalkd protocol response lines as well as YAML.
Note that the YAML spec supports any kind of newline; CR+LF, LF or CR:
http://www.yaml.org/spec/1.2/spec.html#id2774608
I see a few possible options:
Option 1: Use CR+LF in YAML response data
This would make the beanstalkd protocol more predictable, and would require no changes to protocol.txt which doesn't specify which newlines YAML uses.
However, it would possibly break beanstalkd clients that assume LF and don't handle CR+LF. I've only recently fixed this in Pheanstalk.
Option 2: Use diff --strip-trailing-cr in check-one.sh
This will convert the diff input from CR+LF to LF.
The downside is that the tests will no longer pick up any actual newline bugs, for example a protocol response ending in LF instead of CR+LF.
Also, I can only confirm that the option is available in GNU diffutils - I don't know if there's other common diff implementations out there that don't support it.
*Option 3: Split .expected files into parts when required.
If example.commands expects a beanstalk response line, then YAML data, then another beanstalk response line, split it into example.expected.1 example.expected.2 and example.expected.3, where example.expected.2 is saved with LF newlines, and the others with CR+LF.
This solution makes managing the *.expected files a bit of a pain, but it doesn't impact on beanstalkd itself, nor weaken the test assertions.
Option 4: Define a basic syntax to specify newline type
For example the _.expected files could be pre-processed to convert all newlines to CR+LF unless the end in the string "<LF>".
This would add pre-processing complexity and a new (tiny) syntax, but would leave the .expected files more manageable.
It would also make the tests less fragile to accidentally saving _.expected with the wrong newline type.
Any preferences or better ideas on how I should go about this?
Cheers!
Paul