Skip to content

ensure-lib-src-rs-exist: Updated the script to check if the stub file is empty#616

Merged
coriolinus merged 3 commits intoexercism:masterfrom
ZapAnton:ensure_stub_exists
Aug 30, 2018
Merged

ensure-lib-src-rs-exist: Updated the script to check if the stub file is empty#616
coriolinus merged 3 commits intoexercism:masterfrom
ZapAnton:ensure_stub_exists

Conversation

@ZapAnton
Copy link
Copy Markdown
Contributor

@ZapAnton ZapAnton commented Aug 9, 2018

As discussed in #551 the script in this PR now has a check to ensure that the stub files of the exercises
are not empty.

The reasons why ensure-lib-src-rs-exist.sh was chosen for this PR and not ensure-stubs-compile.sh are:

  • The content of the stub file is not a concern of ensure-stubs-compile.sh - it should check if the stub compiles, even if it is empty
  • When ensure-lib-src-rs-exist.sh checks for the stub and thinks it exists only because the file exists (even though it could be empty) is sort of false-positive

The [ "$(cat "$dir/src/lib.rs")" == "" ] line was added for the check, because when rustfmt works on an empty file it inserts the 0a symbol in it, and the -s flag check is useless in this case.

In case this PR is merged, closes #551

@ZapAnton
Copy link
Copy Markdown
Contributor Author

ZapAnton commented Aug 9, 2018

Seems like the script could not be run, because of the syntax error in the list creation.
Is it a shell syntax conflict? Because the script worked in my shell.

@coriolinus
Copy link
Copy Markdown
Member

Arrays are bash syntax not available in sh. This script is currently being run via sh. Recommended fix: run it with bash.

@ZapAnton
Copy link
Copy Markdown
Contributor Author

For consistency perhaps every other script should be run with the bash too?

@coriolinus
Copy link
Copy Markdown
Member

coriolinus commented Aug 18, 2018 via email

@ZapAnton
Copy link
Copy Markdown
Contributor Author

ZapAnton commented Aug 20, 2018

The script now works as intended, and Travis fails because there are still exercises which lack the template in the stub file.

For now I will wait for a comment from maintainers whether this should be rebased or simply merged when other templates are added (or any more changes should be made).

Making the syntax and calls of the Travis shell scripts consistent would be moved to the other issue, since they are not a concern in this specific PR.

Copy link
Copy Markdown
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

Making the syntax and calls of the Travis shell scripts consistent would be moved to the other issue, since they are not a concern in this specific PR.

Yup.

If this were a computer where performance were important, I would only use bash where bash-specific features are necessary, and use sh for all other instances. Since this is not one such context, I suppose I don't care. So whoever chooses to do the work gets to choose.

)

for dir in $repo/exercises/*/; do
exercise=$(basename "$dir")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are these changes purely for re-indenting the lines?

I would ask that re-indent be its own commit (or not included at all)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

May I ask why?
The lines I have added for this PR have their own indent and if i leave the above line as they were, it would hurt readability.

Copy link
Copy Markdown
Member

@petertseng petertseng Aug 21, 2018

Choose a reason for hiding this comment

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

May I ask why?

Well, I thought that if a line is changed in a way that isn't consistent with the commit message, it would cause confusion, make it harder to understand the git history, and make it harder to review. Now a reviewer needs to think to see whether a line was changed only for reindenting, or if it has a change other than reindent. A separate commit makes it clear to the reviewer.

if i leave the above line as they were, it would hurt readability.

indeed, so I think I should not suggest they are left as they are. Putting the indentation change in its own commit should accomplish both the goals though (understand history, and keep the indentation consistent)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note that I understand I am causing non-trivial hardship here, by asking for the re-indenting be its own commit. It is not necessarily the most pleasant experience to have to redo the commits to split them in two.

I offer this remedy:

Since I'm the one who cares most about this, I offer to make it happen. However I can only execute this offer at a time more convenient to me. Luckily we still have time before all exercises have their stubs, so we are not in a huge hurry.

There is no obligation to accept this offer, of course.

missing="$missing\n$exercise"
else
#Check if the stub file is empty
if [ ! -s "$dir/src/lib.rs" ] || [ "$(cat "$dir/src/lib.rs")" == "" ] && [[ " ${IGNORED_EXERCISES[*]} " != *"$exercise"* ]]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(despite the above comment, I understand that these are new lines)

check_status=1
fi

if [ "$check_status" -ne 0 ]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this could potentially be written as exit $check_status - was this intentionally written the proposed way for clarity, or some other reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Two reasons actually:

  • For clarity
  • Separation of concern: check_status is used for internal script logic exit 0/1 is used for external system(Travis in this case)

If this feels like unnecessary logic to you I will change it to exit $check_status

@ZapAnton ZapAnton force-pushed the ensure_stub_exists branch 3 times, most recently from 32ce5cd to a5a33bc Compare August 22, 2018 09:12
@ZapAnton
Copy link
Copy Markdown
Contributor Author

@petertseng I have rewritten my commits to extract the indenting changes into separate commit. Does it look good to you?

Copy link
Copy Markdown
Member

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

I have a mild preference in favor of exit $check_status, but it's not strong enough to preclude approval.

I will not merge this until it passes Travis. It will be necessary to merge master or rebase as we add exercise stubs in order to trigger reruns with appropriate context.

@ZapAnton ZapAnton force-pushed the ensure_stub_exists branch from a5a33bc to 3a1aea4 Compare August 30, 2018 20:53
@ZapAnton
Copy link
Copy Markdown
Contributor Author

I have rebased against the master brach and now Travis is all good

@coriolinus coriolinus merged commit 0fbbcba into exercism:master Aug 30, 2018
@ZapAnton ZapAnton deleted the ensure_stub_exists branch August 30, 2018 21:16
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.

Some exercises are missing templates in lib.rs

3 participants