Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODULES-1821 support empty sections #274

Merged
merged 21 commits into from Oct 8, 2018

Conversation

cjepeway
Copy link
Contributor

I think I've fixed the problem of not being able to specify bare [sections], those without any settings in them. This issue was reported as MODULES-1821 some years back.

I also think I've fixed the problem of the stray newline that shows up at the beginning of an .ini file when an ini_setting is added to an empty file. I believe I have structured the commits in a way that that fix doesn't need to be merged at the same time as the empty section fix.

I haven't added any acceptance tests, as I don't have vagrant or virtualbox installed.

I'm quite willing to rework this pull request however you'd like, if you think these fixes or something like them would be accepted into the official repo. I'll need to do right by my day job, though, so any re-work of this pull request might take a week or two.

Let me know what y'all think.

@cjepeway
Copy link
Contributor Author

cjepeway commented May 1, 2018

Both AppVeyor and Travis CI are bombing on how multi-line strings are indented.

I'll clean those up once I get some feedback on the fixes.

I'd suggest cleaning up all the expected values to be transformations on orig_content as was done in f66ca0c.

@algrym
Copy link

algrym commented Jul 19, 2018

What ever happened with this?

cjepeway and others added 18 commits October 8, 2018 10:48
(MODULE-1821) There are quite a few tests of 'if no sections exist',
so group them into their own context.  The plan is to start on
supporting empty sections using this context.
(MODULES-1821) Add surrounding brackets to
expected value when testing that a empty section
(one without any settings) can be added to
an empty file.
A resource can now have a nil setting and value;
this indicates a section that has no settings,
and hence is empty.

Also, the global setting always exists, even for
empty files.

Finally, this changes how the global section is considered empty:
since the global section has no header, we can't call it empty
when its starting & ending lines are zero.  That, in fact, is
when it includes a single setting or comment.  Instead, we
consider the global section empty whenever it's new.

(Apologies, I'm trying to stage these git commits in a logical way,
but I'm working with changes made in an SVN repo that were much
more haphazard.  Until I stash the changes I have yet to commit,
I won't know whether these committed changes pass the tests.  So,
this commit may break tests.  We'll see.)
(MODULES-1821) The committed code doesn't yet include
fixes for the (kinda annoying) empty blank line that
the module puts into an empty or non-existent file
when it adds a module.  So, update the test to
expect that extra newline.
(MODULES-1821) These tests of working with empty files
now expect that an initial blank line won't be added
when adding a new section.

Strictly speaking, the following commits have nothing
to do with MODULES-1821.  But, well, that's another
thing I fixed, and so I'm committing these changes,
too.  They can be broken apart use the tag I previously
created, or so I hope.
Stop adding that superfluous intial blank line
when the section or setting is added to an empty
or non-existant file.
Test whether an empty section can be added to existing sections.
Rubocop is unhappy with "and" in boolean expressions,
so switch to && so it'll settle down.
(MODULES-1821) Add a test that a new setting
can be added to an empty section (one with
only a [section] line).
(MODULES-1821) When adding a setting to an empty, pre-existing
section (one with just a [section] header), the header wasn't
written out.  This commit is meant to fix that problem.
Prior to supporting empty sections, when the
the final line in a section was removed by
deleting its sole setting, the section's header
was also removed, thereby deleting the section.

For now, restore that behavior to preserve
backwards compatibility.

There may come a time when, in the world of
empty sections, deleting such a setting should
*not* cause the section header to be deleted.

That's a debate for the future.
@Lavinia-Dan Lavinia-Dan merged commit d02447a into puppetlabs:master Oct 8, 2018
@cjepeway cjepeway deleted the MODULES-1821-empty-sections branch October 29, 2018 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants