You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m doing some sort of shell as a side project where I wanted to try/learn more on testing. Heard a lot of good things about snapshot testing and this insta crate so I wanted to try.
So my test are simple commands that I support in the shell.
I like the idea of having a "script file" where each line is a command that should be executed as a test. So I made the following test:
fntest_command(){
insta::glob!("snapshots-input/*.sh", |path| {let file = File::open(path).unwrap();let reader = BufReader::new(file);for line in reader.lines(){letmut line = line.unwrap();
line.push('\n');// We want the newline… it is there when the user enter itif line.is_empty(){// Empty line are present to visually separate sections, not to be testedcontinue;}letmut command = CommandLine::new(&line);let cmd = command.handle_command();// insta::with_settings!({// description => format!("Command line: {line}")// }, {
insta::assert_snapshot!(cmd.format());// })}});}
Discovering the project I added the "description" setting (commented here to show the evolution) to be able to see the line being tested.
But now I’m getting a strange behavior: some tests get mixed while I did not update cargo-insta, nor the test function. Like I’m getting a diff where the content correspond to exit 42 but the description command I see is invalid_command. Exactly like if the line where not read in order or insta loose mix them somehow.
Reading the doc I’m now trying to change the assert with the following: insta::assert_snapshot!(format!("{}", line.replace(' ', "_")), cmd.format(), &line);.
Do you think this change will "fix" my issue?
Should I not try to do this and have 1 file per test instead of 1 per line of a file? (Or only use inline test for this little sized tests?)
Is there a better/intended way?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I’m doing some sort of shell as a side project where I wanted to try/learn more on testing. Heard a lot of good things about snapshot testing and this
insta
crate so I wanted to try.So my test are simple commands that I support in the shell.
I like the idea of having a "script file" where each line is a command that should be executed as a test. So I made the following test:
Discovering the project I added the "description" setting (commented here to show the evolution) to be able to see the line being tested.
But now I’m getting a strange behavior: some tests get mixed while I did not update cargo-insta, nor the test function. Like I’m getting a diff where the content correspond to
exit 42
but the description command I see isinvalid_command
. Exactly like if the line where not read in order orinsta
loose mix them somehow.Reading the doc I’m now trying to change the assert with the following:
insta::assert_snapshot!(format!("{}", line.replace(' ', "_")), cmd.format(), &line);
.Do you think this change will "fix" my issue?
Should I not try to do this and have 1 file per test instead of 1 per line of a file? (Or only use inline test for this little sized tests?)
Is there a better/intended way?
Beta Was this translation helpful? Give feedback.
All reactions