Looking for help, but also providing feedback.
In the tests for ls-tree, it seems 3 randomly named files are generated to test the sorting/ordering of the output. In this case, it is “blueberry”, “pear”, and “mango”. When running tests locally (I would use the same tree object if I knew what it was, see feedback below), codecrafters test reports:
Expected “blueberry\nmango\npear\n” as stdout, got: “blueberry\npear\nmango\n”
Yet when I do:
git ls-tree --name-only b96a33bbd2d5ba747aa429e9089de785adb6e2e2 && ~/code/codecrafters/git/your_program.sh ls-tree --name-only b96a33bbd2d5ba747aa429e9089de785adb6e2e2
I get output identical to the official git implementation (directories alphabetically, then files alphabetically) with every failing test case codecrafters gives me:
blueberry
mango
pear
blueberry
mango
pear
I’m not sure where the issue is, how the test suite is calling my program differently, or how to effectively debug this. The test suite is pretty much a black box and my output matches the official implementation.
My feedback:
- The debug info for this test is rather useless. All it adds is “Writing a tree to git storage..” with no information about the tree itself and it seems to get deleted right after the tests run or I can’t find it. So reproducing locally outside of the test suite is rather difficult. I’m not sure how/if I can decode the SHA1 it gives me to see what the tree object it created looks like.
- Tests should be deterministic. Rather than generating a random/pseudorandom set of files, the tests should use a predefined set of files/words in multiple test cases to ensure sorting, ordering, etc.. is done correctly. I didn’t notice this issue until I had moved onto the write tree challenge as the tests passed the first time and still do intermittently.
Repo published: GitHub - JSchneidler/codecrafters-git-go
