Idiomatic way to add examples to dub package

FreeSlave freeslave93 at gmail.com
Thu Apr 26 18:16:01 UTC 2018


Most dub packages are libraries and should provide runnable 
examples.
What's the current idiomatic way to add examples? I used 
sub-packages with dependency on the library and "*" as version 
and running them as dub run :examplename
Now I've noticed vibed uses a different scheme - examples are 
like separate packages that are supposed to ran with --root 
option (if running from the library root directory) and specify 
the dependency with "path" property like here 
https://github.com/vibe-d/vibe.d/blob/master/examples/http_server/dub.json
That involves more typing when running an example but keeps the 
main dub.json independent from examples (no need to specify 
sub-packages)

Also I still don't understand if I need to include 
dub.selections.json in VCS repo. I read somewhere that it should 
be included but vibed examples don't have dub.selections.json. 
E.g. here 
https://github.com/dlang/dub/issues/829#issuecomment-215741874 
jacob-carlborg  said
> For applications the dub.selection.json files should be in 
> version control, for libraries it should not be

Examples are applications so I thought dub.selections.json should 
be included. But it may be an outdated information.

If there're tutorials on both topics (how to include examples and 
when one should include dub.selections.json in VCS), I would like 
to read them. I could not find any useful info on code.dlang.org 
regarding these issues, while those look like basic issues that 
must be covered in manuals.


More information about the Digitalmars-d-learn mailing list