Skip to content

Add more test cases#37

Merged
ehwan merged 2 commits into
mainfrom
cu8_testcase
Sep 27, 2025
Merged

Add more test cases#37
ehwan merged 2 commits into
mainfrom
cu8_testcase

Conversation

@ehwan

@ehwan ehwan commented Sep 27, 2025

Copy link
Copy Markdown
Owner

Add example/calculator_u8 to bootstrap test cases

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ehwan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the project's test coverage by adding a new calculator_u8 example. The primary purpose of this addition is to showcase and integrate a build.rs script for parser generation, moving away from direct macro usage in the source file. This change streamlines the parser development workflow and ensures the new example is properly validated within the existing bootstrap test infrastructure.

Highlights

  • New Example Added: A new example, calculator_u8, has been introduced to the project, expanding the suite of test cases.
  • Build Script Integration: The calculator_u8 example now leverages a build.rs script to generate its parser, demonstrating a more robust and automated approach to parser creation.
  • Parser Definition Refactor: The parser definition for calculator_u8 has been refactored. Instead of directly using the lr1! macro in src/parser.rs, the grammar is now defined in a format that the rusty_lr build tool processes, and the generated parser is included via src/parser_expanded.rs.
  • Bootstrap Test Script Update: The scripts/bootstrap_test.sh script has been updated to incorporate the new calculator_u8 example, ensuring its generated parser is included in the automated diff checks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new example calculator_u8 to serve as a test case for the rusty_lr build script functionality. The changes are logical and correctly set up the new example with a build script to generate the parser from a grammar file. I've identified a few areas for improvement regarding code robustness in the build script and maintainability in the test script. I've also noted that a generated file is missing a final newline, which should be fixed in the generator.


fn main() {
println!("cargo::rerun-if-changed=src/parser.rs");
let output = format!("{}/parser.rs", std::env::var("OUT_DIR").unwrap());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using unwrap() can cause the build to panic with a less-than-helpful message if the OUT_DIR environment variable is not set. While Cargo always sets this for build scripts, it's better practice to use expect() with a descriptive message to aid in debugging if something goes wrong.

Suggested change
let output = format!("{}/parser.rs", std::env::var("OUT_DIR").unwrap());
let output = format!("{}/parser.rs", std::env::var("OUT_DIR").expect("OUT_DIR environment variable not set"));

Comment thread scripts/bootstrap_test.sh
Comment on lines +68 to +72
diff "$rustylr_path/scripts/diff/calculator_u8.rs" "$rustylr_path/scripts/diff/calculator_u8_new.rs" >/dev/null
if [ $? -ne 0 ]; then
echo "scripts/diff/ is not updated. Please run scripts/bootstrap_test.sh locally and commit the changes."
exit 1
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There's significant duplication in the logic for checking diffs for calculator, calculator_u8, and json. This makes the script harder to maintain. Consider refactoring this repeated logic into a shell function.

For example:

check_diff() {
    local name=$1
    local base_file="$rustylr_path/scripts/diff/${name}.rs"
    local new_file="$rustylr_path/scripts/diff/${name}_new.rs"

    diff "$base_file" "$new_file" >/dev/null
    if [ $? -ne 0 ]; then
        echo "scripts/diff/ is not updated for ${name}. Please run scripts/bootstrap_test.sh locally and commit the changes."
        exit 1
    fi
}

if [ "$is_from_github_actions" = "true" ]; then
    check_diff "calculator"
    check_diff "calculator_u8"
    check_diff "json"
fi

}

// ==============================Generated Codes End===============================

No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The generated file is missing a final newline. It's a standard convention for text files to end with a newline character, and some tools might not process the last line correctly without it. The code generator should be updated to append a newline at the end of the generated files.

@ehwan
ehwan merged commit c147f35 into main Sep 27, 2025
1 check passed
@ehwan
ehwan deleted the cu8_testcase branch September 27, 2025 14:48
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.

1 participant