borkdude/carve

Automate the carving process?

AndreaCrotti opened this issue · 7 comments

Assuming someone has decent test coverage, it would be cool to semi automate the whole carving process, and one way would to:

  • set a command to run all the tests
  • make carve run that command after every form is deleted (either in interactive or non interactive mode), and if they pass just delete otherwise undo and add to .carveignore

I guess tests should be fast enough, but I think this would really help the initial carving on bigger projects.
What do you think @borkdude ?

I think this could be done as a script outside of carve, using carve as a library, not as a test-runner.

Yes in theory but is there a way to remove only one thing? Or maybe eventually carve only one file at a time?

If yes I guess it could be scripted more or less easily, by backing up the file, running carve, running tests and restoring if tests failed.

You're right, Carve could maybe have a :verify-fn hook in which you could run the tests (or lint the project, etc), if the function returns true or doesn't throw, then continue, else revert that step. Maybe the reverting could happen by backing up the file before carving and reverting that file in case of an error.

So btw I just added some hacky code locally to make it run only on N number of files at a time, which works, so in theory it would be possible to script from outside as well.

However I think that the analysis phase can be quite slow on a big project, and by driving it from the outside I guess that would have to be redone for every change right?
(tbf if it's fully automated it doesn't matter as much can just leave it running by itself, but still might be nice to not make it take forever)

Another thing is that potentially you don't want to run cljs tests if you are only carving clj files, so maybe the hook could be something like file-regexp => verify-fn
{#"*.clj$" "make unit-test-clj", not sure if that gets too complicated though, if tests are fast enough you can also just run them all every time.

The :verify-fn could receive a map and also could return a map with :continue true or false. Map in, map out (mimo) is usually flexible enough for future extension. In the input map we could include the filename.

Yeah ok sounds good, I hacked something together externally for now to try it out but yeah it would be definitively useful to integrate this.