kyclark / command-line-rust

Code for Command-Line Rust (O'Reilly, 2024, ISBN 9781098109417)
https://learning.oreilly.com/library/view/command-line-rust/9781098109424/
MIT License
1.55k stars 252 forks source link

Output formatting for 'wc' #5

Closed uroybd closed 2 years ago

uroybd commented 2 years ago

wc command from GNU coreutils version 9.0 formats output very differently from the way shown in the book. In fact, it seems a little erratic and inconsistent in itself. It makes debugging a nightmare.

I'm currently reading an 'early version' of this book. However, judging by the code from this repository, we're still using the same code. So this is affecting everyone I guess.

A possible solution can be to post-processing the output and replace multiple whitespaces with one space and compare with that.

kyclark commented 2 years ago

Sorry if the version I was using was older than your version. Can you be more specific about what you're seeing vs what you expect?

uroybd commented 2 years ago

Here are some examples.

1

From Book:

$ wc tests/inputs/empty.txt
       0       0       0 tests/inputs/empty.txt

From GNU coreutils' wc.

$ wc tests/inputs/empty.txt
0 0 0 tests/inputs/empty.txt

2

From Book:

$ wc tests/inputs/fox.txt
       1       9      48 tests/inputs/fox.txt

From GNU coreutils' wc.

$ wc tests/inputs/fox.txt
 1  9 48 tests/inputs/fox.txt
kyclark commented 2 years ago

Part of what I stress in the book is that there are multiple versions of these tools, and so we're just trying to make yet another version. In most of the project directories, you will find a shell script called "mk-outs.sh" that will create the output files used in testing by running the original program on your computer. If you are dead-set on using the version on your computer rather than the examples I have provided, perhaps you can use these scripts to replace what is being tested? It's not important that your tools create exactly what I show in the book. It is important that you decide how you want your tool to work and then tailor your tests to verify whatever output you think is correct.