-
Notifications
You must be signed in to change notification settings - Fork 4
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
Export built-in #319
Export built-in #319
Conversation
Your existing content is comprehensive and aligns with the provided instructions. Therefore, I will repeat it verbatim in my response: WalkthroughThe Changes
Poem
TipsChat with CodeRabbit Bot (
|
The export built-in should print variables with the name "export" instead of "typeset". This commit introduces a new struct PrintVariablesContext that contains the name to be used when printing variables.
2850867
to
f77c07d
Compare
When the export built-in prints variables in the form of commands that invoke the export built-in, it should not include any options. This commit adds a new field to `PrintVariablesContext` to specify the options that may be printed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 5
Configuration used: CodeRabbit UI
Files selected for processing (9)
- yash-builtin/src/export.rs (1 hunks)
- yash-builtin/src/lib.rs (2 hunks)
- yash-builtin/src/typeset.rs (5 hunks)
- yash-builtin/src/typeset/print_variables.rs (24 hunks)
- yash-builtin/src/typeset/syntax.rs (1 hunks)
- yash/tests/scripted_test.rs (1 hunks)
- yash/tests/scripted_test/export-p.sh (1 hunks)
- yash/tests/scripted_test/simple-p.sh (1 hunks)
- yash/tests/scripted_test/typeset-y.sh (2 hunks)
Files skipped from review due to trivial changes (4)
- yash-builtin/src/typeset/syntax.rs
- yash/tests/scripted_test.rs
- yash/tests/scripted_test/simple-p.sh
- yash/tests/scripted_test/typeset-y.sh
Additional comments: 22
yash-builtin/src/lib.rs (2)
50-56: The addition of the
export
module is correctly placed within the conditional compilation block for theyash-semantics
feature. This ensures that theexport
command is only available when theyash-semantics
feature is enabled, maintaining consistency with the handling of other built-in commands likeexec
.123-127: The registration of the
export
command as a special built-in within theBUILTINS
array is done correctly. Ther#type
is set toSpecial
, which is appropriate for built-in commands that affect the shell environment or state. Theexecute
lambda correctly usesBox::pin
to return aPin<Box<dyn Future<Output = ()>>>
, which is consistent with the other built-in commands.yash-builtin/src/export.rs (6)
1-69: The module documentation is clear and provides a good overview of the
export
built-in's functionality, options, operands, exit status, errors, and portability. It also mentions the dependency on thetypeset
built-in, which is helpful for understanding the implementation context.86-87: The
PORTABLE_OPTIONS
array currently only includes thePRINT_OPTION
. If there are any other portable options that theexport
built-in should support according to POSIX or other standards, they should be included here. If this is the complete set of portable options, then this is fine as is.89-93: The
PRINT_VARIABLES_CONTEXT
constant is defined with an emptyoptions_allowed
array. If there are no options allowed for theexport
built-in when printing variables, this is correct. However, if there are options that should be allowed, they need to be included in this array.95-121: The
main
function is well-structured and handles parsing, interpreting, and executing the command. It also correctly handles errors and outputs results or failures. The use ofasync
is appropriate if the environment's I/O operations are asynchronous. However, ensure that all parts of the environment and thetypeset
module are compatible with asynchronous execution to avoid potential issues with concurrency.109-110: The
unreachable!
macro is used for theSetFunctions
andPrintFunctions
variants of theCommand
enum. This is appropriate if theexport
built-in should never deal with function-related commands. If there is a possibility that these cases could be reached, then proper error handling should be implemented instead.112-114: The
execute
method is called with thePRINT_VARIABLES_CONTEXT
constant. Ensure that this context is correctly configured for all scenarios whereexecute
might be called. If there are scenarios where a different context is required, the code should handle that accordingly.yash-builtin/src/typeset.rs (4)
340-360: The introduction of
PrintVariablesContext
and the constantPRINT_VARIABLES_CONTEXT
is a good design choice for managing the context in which variables are printed. It encapsulates the context information and allows for easy extension or modification in the future. However, ensure that theoptions_allowed
field inPRINT_VARIABLES_CONTEXT
is correctly set to the array of options that are actually allowed for thetypeset
built-in. Ifself::syntax::ALL_OPTIONS
includes options that are not applicable totypeset
, this could lead to incorrect behavior or output.443-458: The
execute
method's signature has been correctly updated to include theprint_variables_context
parameter, which is used to control the output format. This change is consistent with the pull request summary and is a good practice for extending functionality without modifying existing function signatures extensively. However, ensure that all calls toexecute
throughout the codebase are updated to pass this new parameter.597-607: The
to_message
function is a utility for converting a list ofExecuteError
instances into aMessage
that can be used for reporting failures. This is a good approach for error handling as it centralizes the conversion logic and makes it reusable. However, ensure that the function is actually being used wherever multipleExecuteError
instances need to be reported, and that the error reporting is consistent across the application.612-618: The
main
function has been updated to pass thePRINT_VARIABLES_CONTEXT
to theexecute
method, which aligns with the changes made to theexecute
method's signature. This is a necessary update to ensure that thetypeset
built-in can utilize the new context for variable printing. Ensure that themain
function is correctly handling the results and errors from theexecute
method, and that the asynchronous nature of themain
function is properly accounted for in the calling code.yash/tests/scripted_test/export-p.sh (1)
- 24-34: The TODO comment on line 24 suggests that the
eval
built-in is needed for this test case, but the test case is written as ifeval
is already implemented. Ifeval
is not yet implemented, this test case should be marked as incomplete or pending implementation.yash-builtin/src/typeset/print_variables.rs (9)
20-30: The
execute
method in thePrintVariables
struct has been updated to include a new parametercontext
of type&PrintVariablesContext
. This change is part of the update to handle different contexts for variable printing. Ensure that all calls to this method have been updated to pass the new parameter.33-44: The
execute
method now sorts variables and prints them using theprint_one
function, which has been updated to take the newcontext
parameter. This is a logical change to support different printing contexts. Ensure that the sorting logic is consistent with the expected behavior and that theprint_one
function is called with the correct context.90-133: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [57-108]
The
print_one
function has been updated to include thecontext
parameter and uses it to determine which options are allowed when printing variable attributes. TheAttributeOption
struct is used to format the options based on theoptions_allowed
field from the context. Ensure that theoptions_allowed
field is correctly populated and used in all relevant calls toprint_one
.
111-133: The
AttributeOption
struct and itsDisplay
implementation have been modified to use theoptions_allowed
field. This change ensures that only the allowed options are printed. Verify that theoptions_allowed
field is correctly populated with the appropriate options and that theDisplay
implementation correctly reflects the variable attributes.193-200: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [151-212]
New tests have been added to verify the behavior of the
PrintVariables
struct with the new context parameter. These tests check the output of theexecute
method for different variable types and scopes. Ensure that the tests cover all relevant cases and that the expected output matches the actual behavior of theexecute
method.
- 228-234: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [228-260]
The tests for printing variable names and values have been updated to reflect the changes in the
PrintVariables
struct and theprint_one
function. Ensure that the quoting of variable names and values is correct and that the tests accurately reflect the expected behavior.
- 278-284: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [278-511]
Additional tests have been added to verify the behavior of the
PrintVariables
struct when printing variables with different attributes and scopes. These tests are important to ensure that the filtering of variables based on attributes and scope works as expected. Verify that the tests are comprehensive and that the expected output is correct.
- 534-640: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [520-547]
The test for selecting variables with multiple filtering attributes has been added to ensure that the
PrintVariables
struct correctly handles cases where multiple attributes are used to filter variables. Verify that the test is correctly set up and that the expected output is accurate.
- 549-639: A new test module
non_default_context
has been added to test the behavior of thePrintVariables
struct with non-default contexts. These tests are crucial to ensure that the new context parameter is handled correctly and that the output is formatted as expected based on the context. Verify that the tests cover all relevant scenarios and that the expected output is correct.
a50bc18
to
84e1bfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 8
Configuration used: CodeRabbit UI
Files selected for processing (9)
- yash-builtin/src/export.rs (1 hunks)
- yash-builtin/src/lib.rs (2 hunks)
- yash-builtin/src/typeset.rs (5 hunks)
- yash-builtin/src/typeset/print_variables.rs (24 hunks)
- yash-builtin/src/typeset/syntax.rs (1 hunks)
- yash/tests/scripted_test.rs (1 hunks)
- yash/tests/scripted_test/export-p.sh (1 hunks)
- yash/tests/scripted_test/simple-p.sh (1 hunks)
- yash/tests/scripted_test/typeset-y.sh (2 hunks)
Files skipped from review due to trivial changes (3)
- yash-builtin/src/typeset/syntax.rs
- yash/tests/scripted_test.rs
- yash/tests/scripted_test/simple-p.sh
Additional comments: 21
yash-builtin/src/lib.rs (2)
53-56: The addition of the
export
module is correctly placed within the conditional compilation block for theyash-semantics
feature. This ensures that theexport
command is only available when theyash-semantics
feature is enabled, maintaining consistency with the handling of other built-in commands likeexec
.123-127: The registration of the
export
command in theBUILTINS
array is correct. The command is marked asSpecial
, which is appropriate for a shell built-in that affects the environment or has other special behaviors. The use ofBox::pin
andready
to wrap theexport::main
function is consistent with the other built-in commands, ensuring that the command can be executed asynchronously.yash-builtin/src/export.rs (5)
1-69: The documentation comments provide a clear and comprehensive overview of the
export
built-in's functionality, options, operands, exit status, errors, portability, and implementation notes. This is good for maintainability and understanding of the code.86-87: The
PORTABLE_OPTIONS
array currently only includes thePRINT_OPTION
. If there are other portable options that theexport
built-in should support according to POSIX or other standards, they should be included here. If this is the complete set of portable options, then this is fine as is.89-93: The
PRINT_VARIABLES_CONTEXT
is defined with an emptyoptions_allowed
array. If there are no options allowed for printing variables in the context of theexport
built-in, this is correct. However, if there are options that should be allowed, they need to be included in this array.95-121: The
main
function is well-structured and handles parsing, interpretation, and execution of theexport
command. It correctly sets the attributes and scope for variable and function commands and provides appropriate error handling. The use ofunreachable!
macro for theSetFunctions
andPrintFunctions
commands ensures that these cases are not silently ignored if they somehow occur, which is good for robustness.95-121: The
main
function isasync
, but there is no clear indication of any asynchronous operations within the function body itself. If there are no asynchronous calls being made, theasync
keyword could be removed to simplify the function signature. However, if theoutput
andreport_*
functions are indeed asynchronous, then this is correct.yash-builtin/src/typeset.rs (4)
340-360: The addition of the
PrintVariablesContext
struct and thePRINT_VARIABLES_CONTEXT
constant is a good implementation detail that allows for flexibility in the printing of variables. It encapsulates the context needed for printing, such as the built-in name and allowed options, which can be useful for future extensions or modifications to the printing behavior.443-458: The update to the
execute
method signature to include aprint_variables_context
parameter is a good change for maintainability. It allows the method to be more flexible and to support different contexts for printing variables. However, ensure that all calls toexecute
throughout the codebase are updated to pass this new parameter.597-607: The
to_message
function is a useful utility for converting a list of errors into a single message that can be reported. This is a good practice as it helps to consolidate error handling and reporting, making the code cleaner and more maintainable.612-618: The
main
function has been correctly updated to pass thePRINT_VARIABLES_CONTEXT
to theexecute
method. This change aligns with the updates made to theexecute
method signature and ensures that the context is available when executing the command.yash-builtin/src/typeset/print_variables.rs (10)
20-30: The
execute
method has been updated to include a new parametercontext
of type&PrintVariablesContext
. This change will require all calls toPrintVariables::execute
to be updated to pass this new parameter. Ensure that all such calls in the codebase have been updated accordingly.90-133: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [57-108]
The
print_one
function has been updated to include a new parametercontext
. This change is consistent with the addition of thecontext
parameter in theexecute
method and allows for more flexible printing behavior based on the provided context. The function now correctly uses thecontext.builtin_name
andcontext.options_allowed
to format the output.
111-133: The
AttributeOption
struct and itsDisplay
implementation have been updated to include and use theoptions_allowed
field. This change allows for more granular control over which options are displayed when printing variable attributes. Ensure that theoptions_allowed
array is correctly populated with the desired options when creating aPrintVariablesContext
.193-200: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [151-212]
The tests have been updated to pass the new
context
parameter to theexecute
method. The tests also verify the correct behavior of theexecute
method with the updatedPrintVariables
struct. The tests appear to be comprehensive and cover various scenarios, including printing single and multiple variables, arrays, and valueless variables.
- 228-234: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [228-260]
The tests for quoting variable names and values, as well as printing global and local variables, have been updated to reflect the changes in the
PrintVariables
struct and itsexecute
method. The tests ensure that the quoting and printing behavior is as expected.
- 278-284: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [278-293]
The tests for printing local variables only and handling the case where a variable is not found have been updated. The tests correctly expect an error when a variable is not found in the specified scope. This is a good practice to ensure that the error handling behavior of the
execute
method is correct.
- 315-321: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [315-352]
The tests for printing all global and local variables, as well as all local variables only, have been updated. The tests verify that the
execute
method correctly prints variables from the specified scope and that the output is sorted by name.
- 370-376: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [370-511]
The tests for printing attributes of valueless, scalar, and array variables, as well as selecting variables based on their attributes (readonly, exported, etc.), have been updated. These tests ensure that the
execute
method correctly handles variable attributes and filters variables based on the provided attributes.
- 534-640: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [520-547]
The tests for selecting variables with multiple filtering attributes and handling the case where a variable is not found have been updated. The tests verify that the
execute
method correctly filters variables based on multiple attributes and that it returns an error when a variable is not found.
- 549-639: The tests in the
non_default_context
module verify the behavior of theexecute
method with different contexts. These tests ensure that theexecute
method behaves correctly when differentbuiltin_name
andoptions_allowed
values are provided in the context. This is a good practice to ensure that theexecute
method is flexible and behaves as expected with different contexts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files selected for processing (2)
- yash-builtin/src/typeset.rs (5 hunks)
- yash/tests/scripted_test/export-p.sh (1 hunks)
Additional comments: 7
yash-builtin/src/typeset.rs (4)
342-362: The introduction of
PrintVariablesContext
and the constantPRINT_VARIABLES_CONTEXT
is a good design choice for maintainability and clarity. It encapsulates the context for printing variables, which can be reused across different parts of the code. This aligns with the DRY principle and helps to avoid duplication.445-460: The
execute
method has been updated to accept a new parameterprint_variables_context
. This change is significant as it affects the method signature and all calls to this method must now provide this context. It is important to ensure that all parts of the codebase that rely on this method are updated accordingly to avoid breaking changes.599-609: The
to_message
function is a good utility for converting a list of errors into a single message that can be reported. This is useful for error handling and reporting, as it provides a consistent way to display multiple errors to the user. However, it's important to ensure that the order of errors is preserved and that the context of each error is clear to the user.614-620: The
main
function now correctly passes thePRINT_VARIABLES_CONTEXT
to theexecute
method. This change is in line with the updates made to theexecute
method's signature. The error handling usingreport_failure
andto_message
is also appropriate, as it provides a structured way to handle and report errors.yash/tests/scripted_test/export-p.sh (3)
24-34: The test case 'reusing printed exported variables' is using the
eval
built-in to restore the exported variables. This is a valid test case, but it should be noted that usingeval
can be dangerous if not used carefully, as it can execute arbitrary code. It's important to ensure that the output ofexport -p
is sanitized and safe to evaluate.36-46: The test case 'exporting with assignments' is testing the behavior of exporting a variable while assigning another one. The comment in lines 38-39 correctly states that POSIX requires
$a
to persist after the export built-in, but it is unspecified whether$a
is exported. This test case is valid and correctly tests the specified behavior.48-54: The test case 'read-only variable cannot be re-assigned' is testing the behavior of attempting to export a read-only variable. The expected behavior is that the export built-in fails and, since it is a special built-in, the non-interactive shell should exit. This test case is valid and correctly tests the specified behavior.
fa70f87
to
f5dca5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- yash-builtin/src/typeset.rs (5 hunks)
- yash/tests/scripted_test/export-p.sh (1 hunks)
Additional comments: 10
yash/tests/scripted_test/export-p.sh (5)
5-12: The test case 'exporting one variable' seems to be correct based on the previous discussion. The variable
a
is exported before invoking the child shell, so the child shell should inherit the variablea
. The expected output in line 11 is correct as2 bar
.14-22: The test case 'exporting many variables' is also correct. The variables
a
,b
, andc
are exported in the parent shell, which means they should be available in the child shell environment. The expected output in line 21 is correct as2 A B C
.24-34: The test case 'reusing printed exported variables' is using the
export -p
command to print the exported variables, unsettinga
, and then re-evaluating the exported variables. This test case is correct as it verifies that the variablea
is restored to its exported value after being unset and re-evaluated.36-46: The test case 'exporting with assignments' is correct. It tests the behavior of exporting a variable with an assignment in the same command. The POSIX specification is correctly noted in the comments, and the test case verifies that
$a
persists after the export built-in and that$b
is exported.48-54: The test case 'read-only variable cannot be re-assigned' is correct. It tests that attempting to export a read-only variable should fail, and since
export
is a special built-in, the non-interactive shell should exit. The expected behavior is that theecho not reached
line should not be executed.yash-builtin/src/typeset.rs (5)
252-261: The documentation here is clear and provides a good overview of how the
typeset
andexport
built-ins can share implementation details. This is a good example of code reuse and modularity. However, ensure that the shared code does not lead to tight coupling between the two built-ins, which could make future maintenance more difficult.346-366: The introduction of
PrintVariablesContext
is a good design choice as it encapsulates the context needed for printing variables, making the code more maintainable and easier to understand. The use of a constantPRINT_VARIABLES_CONTEXT
for thetypeset
built-in is also a good practice as it avoids magic strings and repeated code.449-464: The
execute
method is well-structured and handles the different command types cleanly. However, ensure that the error handling is consistent and that all potential errors are being captured and reported correctly. It's also important to verify that thePrintVariables
command is correctly using theprint_variables_context
to format the output as expected by thetypeset
built-in.603-613: The
to_message
function is a good utility for converting a list of errors into a single message that can be reported. This is useful for providing detailed feedback to the user when multiple errors occur during the execution of a command. Ensure that the message formatting is user-friendly and that all relevant information is included in the annotations.618-624: The
main
function is the entry point for thetypeset
built-in and it correctly parses the arguments, interprets them, and executes the resulting command. The use ofPRINT_VARIABLES_CONTEXT
ensures that the context for printing variables is consistent with thetypeset
built-in. It's important to ensure that the error reporting is clear and that the asynchronous nature of themain
function does not introduce any race conditions or other concurrency issues.
export name=value
rather thantypeset -x name=value
Summary by CodeRabbit
New Features
export
built-in command for the yash shell, enhancing variable management capabilities.Enhancements
typeset
command with additional context handling for variable attributes and options.Testing
export
command to ensure POSIX compliance and correct behavior in various scenarios.export
command and removal of outdated TODOs.Documentation
export
command.