Skip to content

Command line tools for XML sync testing between languages #222

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

Merged
merged 3 commits into from
Mar 7, 2025

Conversation

alfsb
Copy link
Member

@alfsb alfsb commented Feb 14, 2025

This PR rewrites the last of old qaxml tools into something that is almost independent of "lib revcheck" code, and adapted to be run in all translations.

After this PR is merged, and new tools announced, the old tools/code removing will be possible. The only dependence renaming are /lib/RevtagParser.php, that is a isolated file, and SyncFileList calling into RevcheckRun, that can be replaced with a simple .xml listing, as the new tools now inspect all files, and does not filter for TranslatedOk anymore.

@alfsb alfsb requested review from cmb69 and Girgias February 14, 2025 16:05
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Some of the coding style choices are exotic and not even consistent within the same file.

if ( implode( "\n" , $s ) == implode( "\n" , $t ) )
continue;

$sideCount = array();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$sideCount = array();
$sideCount = [];

Copy link
Member Author

Choose a reason for hiding this comment

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

Replace all array() usage by [] on new code.


function extractPiData( array $list )
{
$ret = array();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$ret = array();
$ret = [];

Comment on lines +48 to +50
foreach( $s as $v )
$sideCount[$v] = [ 0 , 0 ];
foreach( $t as $v )
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this coding style. Usually it would be something like:

Suggested change
foreach( $s as $v )
$sideCount[$v] = [ 0 , 0 ];
foreach( $t as $v )
foreach ($s as $v)
$sideCount[$v] = [ 0 , 0 ];
foreach ($t as $v)

continue;

print "# qaxml.r: $target\n";
foreach( $revtag->errors as $error )
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

if ( implode( "\n" , $s ) == implode( "\n" , $t ) )
continue;

$sideCount = array();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$sideCount = array();
$sideCount = [];


function extractTagsInnerText( array $nodes , array $tags )
{
$ret = array();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$ret = array();
$ret = [];

if ( in_array( $tag , $tags ) == false )
continue;
$text = $node->textContent;
while( true )
Copy link
Member

Choose a reason for hiding this comment

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

Similarly CS which I don't understand.


function extractTagsInnerXmls( array $nodes , array $tags )
{
$ret = array();
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Comment on lines +278 to +280
}
else
{
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Suggested change
}
else
{
} else {


function collectTagLines( string $file , string $tag )
{
$ret = array();
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

$s = extractPiData( $s );
$t = extractPiData( $t );

if ( implode( "\n" , $s ) == implode( "\n" , $t ) )
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be ===? I think it would make more sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could do the change, but as they are direct returns of identical called function (implode), the only case where it would compare equals with different types are false like values, basically empty strings and empty arrays. And in this case, they comparing equals is correct, as this is a fast test for "same" result on each side.

Copy link
Member

Choose a reason for hiding this comment

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

Different ordered elements are what I was thinking. If there's no need for the elements to be in different orders then please use strict comparison.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

$target = $file->targetDir . '/' . $file->file;
$output = new OutputBuffer( "# qaxml.p" , $target , $ignore );

[ $s , $_ , $_ ] = XmlFrag::loadXmlFragmentFile( $source );
Copy link
Member

Choose a reason for hiding this comment

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

Why are you reusing the variable $_ twice? It's just going to overwrite it. And I don't think you are actually using this variable anywhere so why assign it at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

The function loadXmlFragmentFile() has 3 returns, but here the code is only interested on first return, so only one is "named" and all other cases are "discarded".

Replacing $_ by _ causes PHP Fatal error: Assignments can only happen to writable values.

And replacing [ $s , $_ , $_ ] by $s causes PHP Fatal error: Uncaught TypeError: XmlFrag::listNodes(): Argument #1 ($node) must be of type DOMNode, array given.

So I choose a repetitive and uninteresting name, that causes overwrite of variables that need to be positioned, but are unused.

Copy link
Member

@kamil-tekiela kamil-tekiela Mar 5, 2025

Choose a reason for hiding this comment

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

Yeah, but you don't have to assign it at all. [$source] should do fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

Comment on lines +37 to +38
$s = XmlFrag::listNodes( $s , XML_PI_NODE );
$t = XmlFrag::listNodes( $t , XML_PI_NODE );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$s = XmlFrag::listNodes( $s , XML_PI_NODE );
$t = XmlFrag::listNodes( $t , XML_PI_NODE );
$s = XmlFrag::listNodes( $s , XML_PI_NODE );
$t = XmlFrag::listNodes( $t , XML_PI_NODE );
Suggested change
$s = XmlFrag::listNodes( $s , XML_PI_NODE );
$t = XmlFrag::listNodes( $t , XML_PI_NODE );
$source = XmlFrag::listNodes( $source , XML_PI_NODE );
$target = XmlFrag::listNodes( $target , XML_PI_NODE );

Please don't use single-character variable names.

Copy link
Member Author

Choose a reason for hiding this comment

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

This would need to be also replaced in other parts of code, and will need to be tested. For a future change/rewrite of code.

@alfsb alfsb merged commit a26c5c9 into php:master Mar 7, 2025
12 checks passed
@alfsb alfsb deleted the qax7 branch March 7, 2025 11:36
@alfsb alfsb mentioned this pull request Mar 7, 2025
29 tasks
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.

3 participants