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

Various fixes #363

Merged
merged 8 commits into from
Apr 23, 2024
Merged

Various fixes #363

merged 8 commits into from
Apr 23, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Apr 21, 2024

Addresses issues in #336

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling and testing for unset variables in scripts.
    • Fixed issues related to loop execution and parameter expansion.
  • Refactor

    • Renamed internal entities for clarity and consistency.
    • Enhanced error handling logic in various modules.
  • Tests

    • Added tests for new error handling mechanisms and variable state evaluations.

If the for loop has no words, it should return a successful exit status.
@magicant magicant added the bug Something isn't working label Apr 21, 2024
@magicant magicant added this to the POSIX 2018 scripting milestone Apr 21, 2024
@magicant magicant self-assigned this Apr 21, 2024
Copy link

coderabbitai bot commented Apr 21, 2024

Walkthrough

The updates primarily focus on refining error handling, renaming entities for better clarity, and enhancing the script's robustness in handling unset variables. Changes in yash scripts and semantics modules improve readability and functionality, ensuring smoother operations and clearer error communications in various scripting scenarios.

Changes

Files Change Summaries
.../scripted_test/for-p.sh, .../scripted_test/option-p.sh, .../scripted_test/param-p.sh Removal of TODO comments and enhancements in unset variables handling.
.../CHANGELOG.md, .../src/command/compound_command/for_loop.rs Renaming for clarity, adjustments in error handling, and loop behavior modifications.
.../src/expansion.rs, .../src/expansion/initial.rs, .../src/expansion/initial/param.rs, .../src/expansion/initial/param/switch.rs Renaming EmptyError to VacantError, reorganization of public entities, and updates in error handling logic related to unset variables.

🐇✨
In the land of code, where the yash trees grow,
A rabbit hopped by, with updates in tow.
"No more TODOs!", it cheerily said,
As clearer paths it began to tread.
With each hop and jump, the code did enhance,
In the world of yash, even rabbits can dance! 🎉🐾


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a12c23f and 82704c2.
Files selected for processing (9)
  • yash-cli/tests/scripted_test/for-p.sh (1 hunks)
  • yash-cli/tests/scripted_test/option-p.sh (1 hunks)
  • yash-cli/tests/scripted_test/param-p.sh (1 hunks)
  • yash-semantics/CHANGELOG.md (1 hunks)
  • yash-semantics/src/command/compound_command/for_loop.rs (3 hunks)
  • yash-semantics/src/expansion.rs (5 hunks)
  • yash-semantics/src/expansion/initial.rs (1 hunks)
  • yash-semantics/src/expansion/initial/param.rs (6 hunks)
  • yash-semantics/src/expansion/initial/param/switch.rs (19 hunks)
Additional Context Used
LanguageTool (15)
yash-semantics/CHANGELOG.md (15)

Near line 3: Possible spelling mistake found.
Context: # Changelog All notable changes to yash-semantics will be documented in this file. The ...


Near line 5: Only proper nouns start with an uppercase character (there are exceptions for headlines).
Context: ... in this file. The format is based on [Keep a Changelog](https://keepachangelog.com...


Near line 12: Possible spelling mistake found.
Context: ...nreleased ### Added - Support for the ErrExit shell option in multi-command pipeline...


Near line 18: This sentence does not start with an uppercase letter.
Context: ...enamed to Vacancy. - EmptyError was renamed to VacantError. - `EmptyE...


Near line 18: Possible spelling mistake found.
Context: ...ncy. - EmptyErrorwas renamed toVacantError. - EmptyError::state` was renamed...


Near line 19: This sentence does not start with an uppercase letter.
Context: ...VacantError. - EmptyError::statewas renamed toVacantError::vacancy. - e...


Near line 19: Possible spelling mistake found.
Context: ... - EmptyError::state was renamed to VacantError::vacancy. - `expansion::ErrorCause::Em...


Near line 20: This sentence does not start with an uppercase letter.
Context: ...expansion::ErrorCause::EmptyExpansion was renamed to `expansion::ErrorCause::Vaca...


Near line 20: Possible spelling mistake found.
Context: ...orCause::EmptyExpansionwas renamed toexpansion::ErrorCause::VacantExpansion. - <expansion::Error...


Near line 21: This sentence does not start with an uppercase letter.
Context: ...sion::Error as handle::Handle>::handlenow returnsDivert::Exit instead ofDi...


Near line 22: Possible spelling mistake found.
Context: ...instead of Divert::Interrupt when the ErrExit shell option is applicable. ### Fixed...


Near line 28: This sentence does not start with an uppercase letter.
Context: ...tatus. - <TextUnit as Expand>::expand now correctly expands an unset parameter wi...


Near line 29: Did you mean “she'll”?
Context: ... empty string regardless of the Unset shell option. Previously, it would expand t...


Near line 34: Unpaired symbol: ‘[’ seems to be missing
Context: ... rather than an empty string. ## [0.1.0] - 2024-04-13 ### Added - Initial impl...


Near line 38: Possible spelling mistake found.
Context: ... Added - Initial implementation of the yash-semantics crate [0.1.0]: https://github.com/mag...

ShellCheck (16)
yash-cli/tests/scripted_test/for-p.sh (2)

[error] 36-36: Couldn't parse this for loop. Fix to allow more checks.


[error] 37-37: Unexpected keyword/token. Fix any mentioned problems and try again.

yash-cli/tests/scripted_test/option-p.sh (7)

[error] 92-92: Was this intended as a comment? Use # in sh.


[error] 98-98: Was this intended as a comment? Use # in sh.


[info] 192-192: The mentioned syntax error was in this explicit subshell.


[error] 203-203: You need a space after the [ and before the ].


[error] 203-203: Couldn't parse this test expression. Fix to allow more checks.


[error] 203-203: When breaking lines in [ ], you need \ before the linefeed.


[error] 204-204: Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

yash-cli/tests/scripted_test/param-p.sh (7)

[warning] 10-10: This } is literal. Check expression (missing ;/\n?) or quote it.


[error] 14-14: You need a space after the [ and before the ].


[error] 14-14: Couldn't parse this test expression. Fix to allow more checks.


[error] 14-14: You are missing a required space here.


[warning] 14-14: This } is literal. Check expression (missing ;/\n?) or quote it.


[error] 14-14: When breaking lines in [ ], you need \ before the linefeed.


[error] 15-15: Expected test to end here (don't wrap commands in []/[[]]). Fix any mentioned problems and try again.

Learnings (1)
yash-cli/tests/scripted_test/option-p.sh (1)
User: magicant
PR: magicant/yash-rs#320
File: yash/tests/scripted_test/readonly-p.sh:0-0
Timestamp: 2023-11-23T12:47:34.276Z
Learning: The test case for verifying the behavior when attempting to reassign a read-only variable in `yash/tests/scripted_test/readonly-p.sh` has been updated to check for an error or exit status.
Additional comments not posted (18)
yash-semantics/CHANGELOG.md (1)

16-20: The renaming of entities in the expansion::initial module and the behavior change in error handling are well-documented. Ensure that all references to these entities across the project are updated to reflect these changes.

yash-semantics/src/expansion/initial.rs (1)

83-84: The export of Vacancy and VacantError from the param module aligns with the renaming strategy described. Ensure that all references to these entities in the codebase are updated accordingly.

yash-semantics/src/expansion/initial/param.rs (5)

58-59: Renaming ValueState to Vacancy and EmptyError to VacantError aligns with the broader effort to clarify the codebase.


85-90: The error handling logic for the nounset option is correctly implemented to throw an error when a parameter is unset. This aligns with the POSIX shell behavior.


102-102: Initializing value to Some(Value::scalar("0")) when it is None is a sensible default for handling unset values, especially in the context of length calculations.


192-202: The test length_of_unset effectively checks the behavior of the length modifier when the variable is unset, ensuring it returns "0" as expected.


331-345: The test nounset_option_is_ignored_if_there_is_switch verifies that the nounset option is correctly ignored when a switch modifier is used, which is a crucial behavior to test.

yash-semantics/src/command/compound_command/for_loop.rs (3)

32-32: Importing ExitStatus is necessary for the new logic to set the exit status correctly in the loop.


75-78: The addition of a check for empty values before executing the loop body and setting the exit status to SUCCESS when the body is not executed is a good practice. It prevents unnecessary execution and correctly reflects the outcome.


139-139: The test without_words_without_positional_parameters correctly verifies that the loop does not execute when there are no values and that the exit status is set to SUCCESS.

yash-semantics/src/expansion.rs (5)

86-86: Renaming EmptyError to VacantError in the import statement is consistent with the renaming throughout the codebase.


138-138: Updating the ErrorCause enum to include VacantExpansion with the new VacantError type maintains consistency in error handling.


156-156: The method message in ErrorCause now correctly refers to VacantError for generating error messages, ensuring that the error handling remains consistent and clear.


171-171: The label method update to use VacantError ensures that the error annotations are accurate and informative.


190-190: The related_location method correctly does not return a location for VacantExpansion, which is appropriate since this error type does not relate to a specific code location.

yash-semantics/src/expansion/initial/param/switch.rs (3)

38-41: LGTM! The Vacancy enum is well-defined and appropriately documented.


52-61: LGTM! The Vacancy::of function correctly categorizes the vacancy states and uses good encapsulation practices.


106-106: LGTM! The message_or_default method provides a sensible default message handling.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@magicant magicant marked this pull request as ready for review April 23, 2024 14:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Out of diff range and nitpick comments (3)
yash-cli/tests/scripted_test/for-p.sh (1)

Line range hint 36-37: The syntax for the for loop seems incorrect or unconventional, which might be causing parsing issues. Please verify the syntax especially around the use of semicolons and newlines in loop declarations to ensure compatibility and readability.

yash-cli/tests/scripted_test/option-p.sh (1)

Line range hint 92-92: The line intended as a comment should start with a #. This will prevent it from being executed as a command.

- : TODO not yet implemented <<\__OUT__
+ # TODO not yet implemented <<\__OUT__
yash-semantics/src/expansion/initial/param/switch.rs (1)

254-263: LGTM! The apply function handles various switch types and conditions effectively. Consider adding more detailed comments to explain the logic for each case.

yash-semantics/CHANGELOG.md Show resolved Hide resolved
@magicant magicant merged commit b9e09e9 into master Apr 23, 2024
6 checks passed
@magicant magicant deleted the fixes branch April 23, 2024 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant