ponylang / pony-stable

:horse: A simple dependency manager for the Pony language.
BSD 2-Clause "Simplified" License
134 stars 18 forks source link

Stop looking for bundle.json if an invalid one is found #68

Closed srenatus closed 6 years ago

srenatus commented 6 years ago

The previous behaviour was a little irritating:

If invoked in /some/nested/dir, stable would try to read

/some/nested/dir/bundle.json

and if that failed (because the file didn't exist or was invalid), it would try to read, subsequently,

/some/nested/bundle.json
/some/bundle.json
/bundle.json

This implied that errors reading any found bundle.json were printed, but stable kept trying to find a valid one, and eventually, having reached /bundle.json and assuming it didn't exist, would print

No bundle.json in current working directory or ancestors.

With this change, the logic is different: stable will first try to find an existing bundle.json, and then attempt to read it. If it fails, it will not go on, but stop.


Questions

Q: How to test this?

A: I went with the last option, introducing a primitive BundleLocator, and adding tests for that. I've failed to hide it better, as calling it _BundleLocator made it impossible to import it in tests, it seems?

mfelsche commented 6 years ago

What you could do to test a package private class/actor/whateveryouwantbasically is to create a _test.pony file in the source directory and create a TestList in there, that is not private, that is not a Main actor and that has a make constructor. In this file you can add tests for private apis and add them to the TestList. In the test package you can then instantiate that TestList from _test.pony and run its test.

As an example: https://github.com/ponylang/http/blob/master/http/_test.pony and https://github.com/ponylang/http/blob/master/http/test/main.pony

This way you can have both tests for private and public apis.

srenatus commented 6 years ago

@mfelsche thank you! I'll update this PR in a bit. (I had actually looked at that http code yesterday, but it didn't "click". Your words did it, however 👍)

I generally wonder how we approach "hiding" in pony-stable -- I mean, I suppose we could hide much more of its current API surface; but also, I wonder if we need to. I think this isn't meant to be used as a library, so we probably aren't too strict about it. (This could be an argument against adapting BundleLocator to be a private primitive, but I still prefer that, and want to adapt the PR.)

srenatus commented 6 years ago

Don't merge ⚠️ this isn't quite right for the case where there's no bundle.json.

Before: it would create one. Now: it fails. The None case of the match here needs adaptation. I'll take care of that.

srenatus commented 6 years ago

✔️ This could be good to go. Since this is currently still lacking any integration-y tests, I suppose we could either scrutinize this PR thoroughly, or hold it off until we have some.

On that topic, I'd be happy to help. It seems like #28 got a little stuck?

⏩ I could imagine either adding tests for Main() with a pre-created Env (pointing to some temp dir, if that's possible), then checking the outcome. Alternatively, building the binary and testing it by some other means (either another ponytest suite, or something like bats) would seem useful as well. What do you think?

SeanTAllen commented 6 years ago

@srenatus I think that some integration tests as part of this would be a great addition to the PR. If you want to pick up #28, that would be awesome.

srenatus commented 6 years ago

@SeanTAllen I've split off getting integration test scaffolding in: #70 ☝️

SeanTAllen commented 6 years ago

@srenatus sounds good to me.

mfelsche commented 6 years ago

@srenatus this needs to be rebased.

srenatus commented 6 years ago

@mfelsche thanks for the heads-up; by current plan is leave this rot^Wwaiting until #73 is in -- since that would at least give a little assurance that this isn't breaking the world. :)

srenatus commented 6 years ago

@mfelsche rebased and updated ✔️

mfelsche commented 6 years ago

booyah!