Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Code Reviews

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

66%
+2 −0
Code Reviews Writing a testable console program

Not using Rust myself I'll add to @InfiniteDissent's answer on: is there a better way to solve this problem altogether? Yes, there is, it's called a golden master test. Legacy code retreat t...

posted 10mo ago by LAFK‭

Answer
#1: Initial revision by user avatar LAFK‭ · 2023-06-28T15:59:03Z (10 months ago)
Not using Rust myself I'll add to @InfiniteDissent's answer on:


 > is there a better way to solve this problem altogether? 

Yes, there is, it's called a golden master test.

[Legacy code retreat](https://www.jbrains.ca/training/course/surviving-legacy-code) taught me [a golden master](https://www.codurance.com/publications/2012/11/11/testing-legacy-code-with-golden-master) testing technique for cases just like that.

1. You create a set of inputs for your application.
2. You capture a set of outputs for these inputs, creating working pairs: i1 -> o1, i2 -> o2, ... in -> on. **That is your golden master**.
3. For each change you should run all inputs and COMPARE the outputs with the golden master ones.

For console-heavy apps I'd usually do the following:

1. make your CLI app accept an array of inputs (or a file with inputs).
2. have the app source inputs from said array/file.
3. capture the output by redirecting it to a file.
4. Assuming that we have 40 sets of inputs: `for i in $(seq 40); do ./app input$i > output$i; done; diffOutputsWithGoldenMaster.sh`
5. For diffing the outputs, sometimes just `diff` is enough (I always tried to make it so). Sometimes, you want something special, usually to highlight clearer the parts broken. 

In short: I'd move the testing outside of the Rust app. I had success with this technique also with SQL, where I wanted to make sure all reports worked before and after we completely overhauled the engine for their making, running and exporting. We had two Jenkins jobs, one for query generation (in your case, message creation) and one for actual results of the reports being the same (the console log of your app run) as the golden master.

AFAIR, the name is from music recording, where the original, often golden CD, was "the master record", a collectors item. And the source of mass-production of CD albums.