tests: Utility to minimize test cases, continued #527
No reviewers
Labels
No labels
Compat/Breaking
Kind
Bad merge
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
New language
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#527
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "minimize"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
supersedes #469
this time I opened the branch on the main repo, so that we could collaborate on this if needed
WIP that will eventually close #456.
Warning: it's ugly! Lots of code duplication. No unit tests.
I am not sure what is the right place for this sort of code (if we want to have it at all in this repo :-D ). Intuitively,
mgf_dev
is quite fitting, but we need access to a lot of Mergiraf internals which have only beenpub(crate)
so far, and we don't have access to that as things stand. Making them fully public is possible, and after all we don't claim to maintain any sort of stability for the Rust API, so maybe it's not a big deal. But if we wanted to offer some sort of public interface in the future, this would probably make it harder.Arguably, one could also put the code in the root crate, and only expose the minimization function publicly, which could then be used by
mgf_dev
. For the mainmergiraf
binary, it would be dead code, so it wouldn't make it into the binary, but probably still inflate the compilation time a bit, and our test coverage would get a big hit (we could have a big integration test that covers most things, but it's a bit meh).args
into multiplearg
s a23a785642nodes_to_delete
d3121f67cdchoose
5dadce08b1short = ...
for cli flags d669807f27will_recurse
7d1fa725aadetect_suffix
to undersrc/utils.rs
75c362cc40read_file_to_string
to undersrc/utils.rs
19fc2b381bOption::as_deref
ae12041b7epasses_test
af9d75de1bif
to get rid of negated condition 3c2e8eef8apick_nodes_to_delete_internal
44d1b0d328minimize.rs
to mergiraf-the-lib f93027490dpretty_print
directly 7ece86601cb60e47025e
to0ba709127b
0ba709127b
to7dab7e1979
7dab7e1979
toa51b43b8bd
1f6eaa3149
to29fd1ecc2b
29fd1ecc2b
to6c285171d6
6c285171d6
to74213cdbbb
WIP: tests: Utility to minimize test cases, continuedto tests: Utility to minimize test cases, continuedI think this is good enough as a start -- should we merge it?
Oh, wait, there are some things to fix up -- give me a sec
74213cdbbb
to66b4b5bde8
Ok should be good to go now
@wetneb wrote in #576 (comment):
Sorry, still not quite following you. Looking at the source code, I think the testing command invocation ends up looking like:
Firstly, what does
testing_script
in the middle of the invocation achieve?.. I thought you'd want to pass to<script>
the<output_directory>
, not this literal string?Secondly, what I understand "just call mergiraf on the example" to mean is to run
mergiraf merge
? But doesn't that require me to know what the paths to base, left, and right files are (most importantly, their extensions)? Knowing<output_directory>
only brings me half-way.I'm completely blanking on this one... I think having a couple of example
mgf_dev minimize
invocations would really go a long waySure, here's an attempt at documenting it:
First, compile mergiraf on the
bundle-comments
branch (say, in release mode, so that the minimizing goes faster). Let's call that binaryfaulty_mergiraf
.Then let's get the example:
Then, write a script like this:
Let's call this script
run_faulty.sh
.Let's check that running the script on the example produces a return code indicating a panic (134):
The faulty script successfully fails on the example, yay! At each minimization step, the minimizer will check that the script has this status code and will reject any minimized version of the test case that doesn't pass this test. This makes it possible to minimize the test case under that particular constraint.
Let's do it then:
Note: running this on the current version of this branch seems to run into an infinite loop. From my original version it seems to work.
In such a simple case, writing a script is arguably a bit overkill, so you could just do instead:
At the end you have a minimized test case at
/tmp/minimized
.Ideas for improvement:
Funnily enough, in this particular case, the minimizer does an absolutely excellent job: it minimized the test case to the point that all three revisions (base, left and right) are completely empty, and the panic still happens! Not sure it really helps the debugging that much, because it's a bit degenerate, but hey, it's pretty good minimization :-DAh no nevermind I made a mistake - there is no panic for empty files.
Thank you very much, that was very helpful:)
Huh. Looking at the rebase diff, nothing really catches the eye.. I guess I'll try to bisect this
Okay, I now understood your explanation from the other thread. I guess if the result parses with treesitter we should be relatively alright? Succesfully compiling real world examples will be hard to impossible to automate. What we could try is running ghc on the files. GHC has multiple phases, first the parser, later renaming, then typechecking. We can probably check that ghc reaches the renamer (where name resolution happens and certainly will fail.) Sounds also a bit brittle. But feel free to ping me when you need more help in this regard.
Yeah I think that's as far as we can go with ghc -- but still, it sounds like a good additional step on top of the tree-sitter parsing, thanks for the tip @maralorn:)
We could maybe start collecting these language-specific testing scripts somewhere in the repo -- not sure whether we'll end up with a lot of them, but they could serve as a kind of documentation examples for future contributors.
66b4b5bde8
to5b9fdae881
5b9fdae881
to46e7b9596f
I propose to finally merge this :)
one last thing^^
@ -0,0 +496,4 @@
}
}
"#
.trim()
Maybe trim the minimized files instead (if that's even needed?)? The expected files we do control, so it's a bit strange to leave them untrimmed imo
Hmmm the formatter made this look quite ugly… well I might as well do all the trimming manually
I went ahead and turned the strings into non-raw ones.. imo having the first line on its own line is worth the slight ugliness of escaped quotes.
EDIT: can't approve my1 own PR, so if you agree with this last-second change, feel free to merge^^
well, that's what Codeberg considers it to be, anyway ↩︎
0ac0556ed8
tof8864f01a2
f8864f01a2
toc748f0636a