A cross-platform command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, C projects - a cookiecutter fork
The biggest "suck" of templates as they are in cookiecutter is there's no incentive structure to ensure the templates expand to something that's in working order.
It's super easy to accidentally commit something that fails some sort of linting, making all your new code projects fail linters right away, or fail to build, etc.
I always wished I could write tests relating to my cookiecutter templates, that would say something like "if I expand the template with the following variables, then I should be able to run make and see a JAR/ZIP/DEB/WHL file in dist/".
I implemented something like that in here, see https://github.com/OverkillGuy/python-template/tree/main/tests
Specifically, it has a template() function that expands the template in a tmpdir, and tests like this that use the templated repo as fixture, and assess that if we run command X, we get output Y in file.
This is built to allow running the command in a docker container based on a Dockerfile in my template, a nice touch to allow self-contained tests (such as trying to run templates + tests for python versions I haven't got locally), but that's a bit overkill for some.
I wish cookieninja adopted some of that testability, moving some of the infrastructure I built in my tests folder into the core lib, facilitating testability of all cookiecutter templates.
Specifically, I recommend:
Adopt some "render the template in tempdir" fixture that's easily importable (from cookieninja.tests import template_expand_tmpdir?)
Adopt some datastructure like my Template to bind an tmp-expanded-template together into a path + context that spawned it, simplifying tests
Help (somehow? not sure how) to matrix-select template expansions (currently done by pytest.mark.parametrize, but I wish I could do specific stuff like "run this for all variants of python version, but only for run_in_dev = True cases".
Package the necessary dev-tools to enable such tests (I use Faker lib to generate fake project names, which is funny to me). Running test commands via docker is a big one, for instance.
(Stretch) Provide something quick and dirty like my make try for quickly expanding the template + run some cmd, which I find super useful when debugging or expanding the template.
Encourage others to maintain tests, by adding this to docs and adding tests to well known templates as example
The biggest "suck" of templates as they are in cookiecutter is there's no incentive structure to ensure the templates expand to something that's in working order. It's super easy to accidentally commit something that fails some sort of linting, making all your new code projects fail linters right away, or fail to build, etc.
I always wished I could write tests relating to my cookiecutter templates, that would say something like "if I expand the template with the following variables, then I should be able to run
make
and see a JAR/ZIP/DEB/WHL file indist/
".I implemented something like that in here, see https://github.com/OverkillGuy/python-template/tree/main/tests Specifically, it has a template() function that expands the template in a tmpdir, and tests like this that use the templated repo as fixture, and assess that if we run command X, we get output Y in file. This is built to allow running the command in a docker container based on a Dockerfile in my template, a nice touch to allow self-contained tests (such as trying to run templates + tests for python versions I haven't got locally), but that's a bit overkill for some.
I wish cookieninja adopted some of that testability, moving some of the infrastructure I built in my tests folder into the core lib, facilitating testability of all cookiecutter templates.
Specifically, I recommend:
from cookieninja.tests import template_expand_tmpdir
?)make try
for quickly expanding the template + run some cmd, which I find super useful when debugging or expanding the template.