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

Add Travis CI check for whitespace at the ends of lines. #1477

Merged
merged 2 commits into from Feb 20, 2017

Conversation

godbyk
Copy link
Contributor

@godbyk godbyk commented Feb 18, 2017

Per @tkoeppe's suggestion.

This adds a new build type to the Travis CI build which only checks for whitespace at the ends of lines. If it finds any, it will fail the build.

Having this test as a separate 'build type' makes it easy to determine whether the whitespace test failed or whether the PDF compilation failed.

Note: If we plan on adding more tests in the future (e.g., checks for other nonconformant usage)—which I'm in favor of—then I'd recommend we migrate the code from .travis-ci.yml to a separate shell script where we can write more succinct code. (Travis CI wraps the .travis-ci.yml code in its own function and hijacks the exit code $? variable, so we have to capture it to test it later. Within our own shell script, this isn't a problem.)

@jensmaurer
Copy link
Member

jensmaurer commented Feb 18, 2017

@godbyk: And right with pull request, it's the first time I'm seeing a Travis CI failure. How's that?

@tkoeppe
Copy link
Contributor

tkoeppe commented Feb 18, 2017

@godbyk: wonderful, thanks!

@godbyk
Copy link
Contributor Author

godbyk commented Feb 18, 2017

@jensmaurer I just pushed a fix. Waiting to see if Travis CI likes it. (During my later testing, I was canceling the non-test-whitespace builds as I wasn't testing the PDF builds.)

.travis.yml Outdated
# Fail if there is whitespace at the ends of any lines
- export TEST_STATUS=0;
if [ "$BUILD_TYPE" = "check-whitespace" ]; then
grep '\s$' source/*.tex && export TEST_STATUS=1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I don't know Travis, but if this is just shell code, couldn't you just say grep '\s$' source/*.tex here and let grep's return status do the job? It seems that just false has the desired effect of failing the test, so grep should be able to d the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkoeppe I need to invert grep's exit status.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, OK, what about ! grep ... then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkoeppe When I tried that previously it didn't work, but it appears to be working now. (I guess it was a combination of bugs previously—testing the .travis-ci.yml file is a bit of trial-and-error.) Thanks for prompting me to give it another shot; it greatly simplifies the code!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less is more :-)

@tkoeppe tkoeppe merged commit 4ccff01 into cplusplus:master Feb 20, 2017
@tkoeppe
Copy link
Contributor

tkoeppe commented Feb 20, 2017

Thanks a lot! I've always wanted this to be cleaned up, and now we can prevent people from ever breaking it again!

@godbyk
Copy link
Contributor Author

godbyk commented Feb 20, 2017

@tkoeppe No problem!

@godbyk godbyk deleted the travis-ci-check-whitespace branch June 19, 2018 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants