1

I am writing specialised rules and oracles for Shake and I would like to write tests for those functions. How can I do that in Shake? I did not find any simple to use actionToIO function that could do the job.

For example, I would like to test the behaviour of the following :

checkGitWorkDirIsClean = do
  Stdout out <- cmd "git" [ "status", "-s", "-uno" ]
  pure $ null $ filter (/= "") (lines out)

so I could create prepare directories containing minimalistic git data and test the function against those directories.

insitu
  • 4,488
  • 3
  • 25
  • 42
  • I had a look at Shake's source code and it seems tests all rely on setting up some directory and running tests with `shakeXXX ...` so that everything happens in IO. I wrote a couple tests following that strategy. – insitu Jan 31 '20 at 19:56

1 Answers1

1

Generally speaking, testing build systems is hard. Shake has various linting related features that are probably the best way to the the entirety of the build system.

For testing small fragments, it's best if you can make them in IO rather than Action. In the above case, cmd can be run in both the Action and IO monads, so testing it in IO is probably much easier.

If you do have fragments in Action the only way to drive that through a Shake build system is using something like the shake function. If you want to do so in a consistent way, often setting shakeFiles to /dev/null can be useful, as that will cause Shake not to write to a database, so every run will be as though Shake was starting from a clean slate.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85
  • 1
    Thanks a lot Neil! I have had a look at Shake's (impressive) set of tests and tried the later approach, but working in a per-test temporary directory, as I am using also `git` which needs a prepared directory. The `/dev/null` trick sounds interesting though. The tests are a bit clunky and verbose but at least they provide some safety. – insitu Feb 02 '20 at 20:09