MDEV-40353: Add eval parameter to write_file and append_file#5382
MDEV-40353: Add eval parameter to write_file and append_file#5382KhaledR57 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for an optional 'eval' argument to the 'write_file' and 'append_file' commands in 'mysqltest', enabling variable and expression substitution within the written or appended content. It also adds comprehensive test cases and updates the command documentation. Feedback on the changes suggests improving code readability by extracting the assignment out of the 'if' condition when checking the 'eval' flag.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if ((eval_content= (ds_eval_flag.length != 0)) && | ||
| strcasecmp(ds_eval_flag.str, "eval")) | ||
| die("Invalid argument '%s' to '%.*b', only 'eval' is allowed", | ||
| ds_eval_flag.str, command->first_word_len, command->query); |
There was a problem hiding this comment.
Assigning a value within an if condition can reduce code readability and make it harder to maintain or debug. It is cleaner and less error-prone to perform the assignment beforehand and then evaluate the boolean variable in the condition.
eval_content= (ds_eval_flag.length != 0);
if (eval_content && strcasecmp(ds_eval_flag.str, "eval"))
die("Invalid argument '%s' to '%.*b', only 'eval' is allowed",
ds_eval_flag.str, command->first_word_len, command->query);There was a problem hiding this comment.
Pull request overview
This PR extends the mysqltest DSL commands write_file and append_file with an optional third argument, eval, allowing variable ($var) and expression ($(...)) substitution within the written file content (previously only the filename was evaluated). This improves test ergonomics by avoiding --exec echo ... >> file when generating computed file contents.
Changes:
- Add an optional
evalflag towrite_file/append_fileto run the content throughdo_eval()before writing. - Validate that the third argument (if provided) is exactly
eval. - Add regression coverage in
mysqltest.testand update expected output inmysqltest.result.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| mysql-test/main/mysqltest.test | Adds a new MDEV-40353 regression section covering literal vs evaluated content, custom delimiters, loop behavior, and error cases. |
| mysql-test/main/mysqltest.result | Updates expected output to reflect the new eval behavior and new regression section. |
| client/mysqltest.cc | Implements the optional eval argument for write_file/append_file and documents the updated syntax and behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sanja-byelkin
left a comment
There was a problem hiding this comment.
Generally good but need small changes
| --write_file $file | ||
| plain $var and $(1+1) | ||
| a lone dollar sign: $ | ||
| a backslash: \\! echo foo |
There was a problem hiding this comment.
Add this line to the eval version (actually it would be better to have exactly the same content here and in eval to see the difference)
| --error 1 | ||
| --exec echo "--write_file $file EOF junk" | $MYSQL_TEST 2>&1 | ||
|
|
||
| --echo End of tests |
There was a problem hiding this comment.
please change on
--echo End of 10.6 tests
| { | ||
| /* Evaluate on every execution, keep command->content unevaluated */ | ||
| DYNAMIC_STRING ds_eval_content; | ||
| init_dynamic_string(&ds_eval_content, "", ds_content.length + 256, 256); |
There was a problem hiding this comment.
Add result of init_dynamic_string check (I know it is called many cases uncheck but let us make the code better)
|
|
||
| if ((eval_content= (ds_eval_flag.length != 0)) && | ||
| strcasecmp(ds_eval_flag.str, "eval")) | ||
| die("Invalid argument '%s' to '%.*b', only 'eval' is allowed", |
There was a problem hiding this comment.
in other code used report_or_die for parameter checks (and so it can skip incorrect parameter)
0326937 to
1d22668
Compare
1d22668 to
3e58b0f
Compare
mysqltest substituted variables in the file name of write_file and append_file, but not in the content, so tests had to fall back to "exec echo ... >> file" to put a computed value into a file. Add an optional third parameter, eval, which makes the content go through do_eval(). It is off by default, because existing tests write content that contains a literal $ or backslash.
3e58b0f to
aa4f470
Compare
sanja-byelkin
left a comment
There was a problem hiding this comment.
Fix 2 small issue and OK to push (10.6 is protected so prepare the fix and tell me I will push)
| DBUG_VOID_RETURN; | ||
| } | ||
|
|
||
| if (bad_path(ds_filename.str)) |
There was a problem hiding this comment.
IMHO it is better to check arguments in order of appearance so bad path should be checked first
| --error 1 | ||
| --exec echo "--write_file $file EOF junk" | $MYSQL_TEST 2>&1 | ||
|
|
||
| --echo End of 10.6 tests |
There was a problem hiding this comment.
oops # is needed
-echo # End of 10.6 tests
Description
write_fileandappend_filesubstitute variables in the file name, but not in the content, which is written byte for byte. Tests that need a computed value in a file have to fall back on--exec echo ... >> file.This adds an optional third parameter,
eval, which sends the content through the same substitution as--echoandlet, so$varand$(expr)are substituted and\$writes a literal$.Example:
writes
server-id=13andcomment=version 10.6.How can this PR be tested?
Basing the PR against the correct MariaDB version
mainbranch.PR quality check