Skip to content

Commit

Permalink
problem was not in myTestHelpers: I was searching for title='prompt' …
Browse files Browse the repository at this point in the history
…instead of title='title'; works again
  • Loading branch information
pryrt committed Jun 20, 2020
1 parent bb1bd21 commit 0e932fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
17 changes: 5 additions & 12 deletions t/myTestHelpers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ sub __runCodeAndClickPopup {
my ($cref, $re, $n, $xtraDelay) = @_;
$xtraDelay ||= 0;

#if($DEBUG_INFO){
#print "\n"x10;
#note "__run($re,$n,$xtraDelay)\n";
#}

my $pid = fork();
if(!defined $pid) { # failed
die "fork failed: $!";
Expand All @@ -122,12 +117,9 @@ sub __runCodeAndClickPopup {
}
# Because localization, cannot assume YES button will match qr/\&Yes/
# instead, assume $n-th child of spawned dialog is always the one that you want
#if($DEBUG_INFO){
#sleep(2);
#my @subwin = FindWindowLike($f, undef, undef, undef, undef); # parent, title, class, id, depth
#note sprintf "- sub: %d t:'%s' c:'%s'\n", $_, GetWindowText($_), GetClassName($_) for @subwin;
#}
my @buttons = FindWindowLike( $f, undef, qr/^Button$/, undef, 2);

WaitWindowLike($f, undef, qr/^Button$/, undef, 2, 2); # parent, title, class, id, depth, wait -- wait up to 2s for Button
my @buttons = FindWindowLike( $f, undef, qr/^Button$/, undef, 2); # then list all the buttons
if($DEBUG_INFO) {
note sprintf "\tbutton:\t%d t:'%s' c:'%s' id=%d vis:%d grey:%d chkd:%d\n", $_,
GetWindowText($_), GetClassName($_), GetWindowID($_),
Expand All @@ -144,6 +136,7 @@ sub __runCodeAndClickPopup {
print "caller($i): ", join(', ', @c), $/;
}
}

my $h = $buttons[$n] // 0;
my $id = GetWindowID($h);
if($DEBUG_INFO) { note sprintf "\tCHOSEN:\t%d t:'%s' c:'%s' id=%d\n", $h, GetWindowText($h), GetClassName($h), $id; }
Expand All @@ -156,7 +149,7 @@ sub __runCodeAndClickPopup {
exit; # terminate the child process once I've clicked
} else { # parent
undef $IAMCHILDDONOTRESTORE;
$cref->();
$cref->(); # run the process
my $t0 = time;
while(waitpid(-1, WNOHANG) > 0) {
last if time()-$t0 > 30; # no more than 30sec waiting for end
Expand Down
7 changes: 2 additions & 5 deletions t/npp-gui.t
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,14 @@ local $TODO = undef;
runCodeAndClickPopup( sub { $ret = notepad()->messageBox(); }, qr/^\QWin32::Mechanize::NotepadPlusPlus\E$/, 0 );
is $ret, 1, 'messageBox(): retval = OK'; note sprintf qq(\t=> "%s"\n), $ret // '<undef>';

local $TODO = "updated prompt test suite no longer works";
myTestHelpers::setDebugInfo(1);
# prompt
runCodeAndClickPopup( sub { $ret = notepad()->prompt('prompt', 'title', 'default'); }, qr/^\Qprompt\E$/, 0 );
runCodeAndClickPopup( sub { $ret = notepad()->prompt('prompt', 'title', 'default'); }, qr/^\Qtitle\E$/, 0 );
is $ret, 'default', 'prompt(): retval = "default"'; note sprintf qq(\t=> "%s"\n), $ret // '<undef>';

# prompt: cancel
runCodeAndClickPopup( sub { $ret = notepad()->prompt('prompt', 'title', 'default'); }, qr/^\Qprompt\E$/, 1 );
runCodeAndClickPopup( sub { $ret = notepad()->prompt('prompt', 'title', 'default'); }, qr/^\Qtitle\E$/, 1 );
is $ret, undef, 'prompt(): cancel: retval is undef'; note sprintf qq(\t=> "%s"\n), $ret // '<undef>';

myTestHelpers::setDebugInfo(0);
}

# moved to npp-menucmd.t:
Expand Down

0 comments on commit 0e932fd

Please sign in to comment.