Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't fail due to stderr output in tests
Use -ignorestderr flag with exec so any output to stderr is not
interpreted as the command having failed.

(cherry picked from commit eaaba18)
  • Loading branch information
jmroot committed Feb 17, 2017
1 parent 9e75ff0 commit 3741e56
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 38 deletions.
12 changes: 6 additions & 6 deletions src/macports1.0/tests/macports.test
Expand Up @@ -724,10 +724,10 @@ test GetVCSUpdateCmd-svn {
hasSvn
} -setup {
set repo [makeDirectory macports-test-svn-repo $tempdir]
exec $svnadmin create $repo
exec -ignorestderr $svnadmin create $repo
set wc [makeDirectory macports-test-svn-wc $tempdir]
# This URL should probably be encoded.
exec $svn checkout file://$repo $wc
exec -ignorestderr $svn checkout file://$repo $wc
} -body {
string map [list $svn SVN $wc WC] [macports::GetVCSUpdateCmd $wc]
} -cleanup {
Expand All @@ -739,13 +739,13 @@ test GetVCSUpdateCmd-svn {
testConstraint hasGit [expr {![catch {macports::findBinary git} git]}]
set git_vcsupdate_fixture {
set repo [makeDirectory macports-test-git-repo $tempdir]
exec $git init $repo
exec -ignorestderr $git init $repo
rename exec _save_exec

proc exec {cmd args} {
global gitversion
if {$cmd ne [macports::findBinary git] || [lindex $args 0] ne "--version"} {
return [_save_exec $cmd {*}$args]
return [_save_exec -ignorestderr $cmd {*}$args]
}
return "git version $gitversion (Apple Git-23)"
}
Expand Down Expand Up @@ -778,7 +778,7 @@ test GetVCSUpdateCmd-git-noautostash {

testConstraint hasGitSvn [expr {
![catch {macports::findBinary git} git] &&
[file readable [file join [exec $git --exec-path] git-svn]]
[file readable [file join [exec -ignorestderr $git --exec-path] git-svn]]
}]

test GetVCSUpdateCmd-gitsvn {
Expand All @@ -787,7 +787,7 @@ test GetVCSUpdateCmd-gitsvn {
hasGitSvn
} -setup {
set repo [makeDirectory macports-test-git-svn-repo $tempdir]
exec $git svn init http://localhost $repo
exec -ignorestderr $git svn init http://localhost $repo
} -body {
string map [list $git GIT $repo REPO] [macports::GetVCSUpdateCmd $repo]
} -cleanup {
Expand Down
4 changes: 2 additions & 2 deletions src/pextlib1.0/tests/fs-traverse.tcl
Expand Up @@ -163,7 +163,7 @@ proc main {pextlibname} {
fs-traverse file $root {
if {[string match "*/a" $file]} {
# use /bin/rm because on 10.3 file delete doesn't work on directories properly
exec /bin/rm -rf $file
exec -ignorestderr /bin/rm -rf $file
continue
}
lappend output $file
Expand Down Expand Up @@ -211,7 +211,7 @@ proc make_root {} {
link {
# file link doesn't let you link to files that don't exist
# so lets farm out to /bin/ln
exec /bin/ln -s $link $entry
exec -ignorestderr /bin/ln -s $link $entry
}
default {
return -code error "Unknown file map type: $typelist"
Expand Down
2 changes: 1 addition & 1 deletion src/port1.0/tests/portclean.test
Expand Up @@ -161,7 +161,7 @@ test clean_archive {
set fd [open $pwd/+CONTENTS w+]
puts $fd "@portname subport"
close $fd
exec zip $portdbpath/incoming/subport-2_0.0.0.0.zip +CONTENTS
exec -ignorestderr zip $portdbpath/incoming/subport-2_0.0.0.0.zip +CONTENTS

portclean::clean_archive

Expand Down
2 changes: 1 addition & 1 deletion src/port1.0/tests/portutil.test
Expand Up @@ -92,7 +92,7 @@ proc mtree {root spec} {
link {
# file link doesn't let you link to files that don't exist
# so lets farm out to /bin/ln
exec /bin/ln -sf $link $file
exec -ignorestderr /bin/ln -sf $link $file
}
default {
return -code return "Unknown file map type: $typelist"
Expand Down
2 changes: 1 addition & 1 deletion src/registry2.0/tests/depends.tcl
Expand Up @@ -6,7 +6,7 @@ proc main {pextlibname} {
load $pextlibname

# totally lame that file delete won't do it
exec rm -f {*}[glob -nocomplain test.db*]
exec -ignorestderr rm -f {*}[glob -nocomplain test.db*]

registry::open test.db

Expand Down
2 changes: 1 addition & 1 deletion src/registry2.0/tests/entry.tcl
Expand Up @@ -6,7 +6,7 @@ proc main {pextlibname} {
load $pextlibname

# totally lame that file delete won't do it
exec rm -f {*}[glob -nocomplain test.db*]
exec -ignorestderr rm -f {*}[glob -nocomplain test.db*]

# can't create registry in some brain-dead place or in protected place
test_throws {registry::open /some/brain/dead/place} registry::cannot-init
Expand Down
4 changes: 2 additions & 2 deletions tests/test.tcl.in
Expand Up @@ -85,14 +85,14 @@ foreach arg $argv {
if {$test_name ne ""} {
cd test/$test_name

set result [exec $tcl test.tcl {*}$arguments 2>@stderr]
set result [exec -ignorestderr $tcl test.tcl {*}$arguments 2>@stderr]
puts $result

} else {
foreach test $test_suite {
cd test/$test

set result [exec $tcl test.tcl {*}$arguments 2>@stderr]
set result [exec -ignorestderr $tcl test.tcl {*}$arguments 2>@stderr]
set lastline [lindex [split $result "\n"] end]

if {[lrange [split $lastline "\t"] 1 1] != "Total"} {
Expand Down
4 changes: 2 additions & 2 deletions tests/test/case-insensitive-deactivate/test.tcl
Expand Up @@ -19,7 +19,7 @@ port_index
proc test_exists {} {
global path testfile testport1

exec sed "s/@name@/$testport1/" $path/Portfile.in > Portfile
exec -ignorestderr sed "s/@name@/$testport1/" $path/Portfile.in > Portfile
port_install

if {[file exists $testfile]} {
Expand All @@ -32,7 +32,7 @@ proc test_exists {} {
proc test_not_exists {} {
global path testfile testport2

exec sed "s/@name@/$testport2/" $path/Portfile.in > Portfile
exec -ignorestderr sed "s/@name@/$testport2/" $path/Portfile.in > Portfile
port_uninstall

if {[file exists $testfile]} {
Expand Down
2 changes: 1 addition & 1 deletion tests/test/envvariables/test.tcl
Expand Up @@ -22,7 +22,7 @@ proc envvar_test {} {
append string "export PORTSRC=${portsrc}; "
append string "${bindir}/port test"

exec sh -c $string > output
exec -ignorestderr sh -c $string > output
set line [get_line $path/$output_file "a"]
set line2 [get_line $path/$output_file "b"]
return $line$line2
Expand Down
22 changes: 11 additions & 11 deletions tests/test/library.tcl.in
Expand Up @@ -61,9 +61,9 @@ proc port_index {} {
set path [pwd]
cd ../..
# Avoid warning about ports tree being old
exec sh -c {touch */*/Portfile}
exec -ignorestderr sh -c {touch */*/Portfile}

exec ${bindir}/portindex 2>@1
exec -ignorestderr ${bindir}/portindex 2>@1

file copy ${cpwd}/sources.conf /tmp/macports-tests/opt/local/etc/macports/
file copy ${cpwd}/PortIndex ${cpwd}/PortIndex.quick /tmp/macports-tests/ports/
Expand All @@ -78,7 +78,7 @@ proc port_clean {pwd} {
set back [pwd]
cd $pwd

catch {exec env PORTSRC=${portsrc} ${bindir}/port clean 2>@1}
catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port clean 2>@1}
cd $back
}

Expand All @@ -89,7 +89,7 @@ proc port_run {pwd} {
set back [pwd]
cd $pwd

set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port -d -N test >&output} ]
set result [catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port -d -N test >&output} ]
cd $back
return $result
}
Expand All @@ -101,7 +101,7 @@ proc port_trace {pwd} {
set back [pwd]
cd $pwd

set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port -d -N -t test >&output 2>@1} ]
set result [catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port -d -N -t test >&output 2>@1} ]
cd $back
return $result
}
Expand All @@ -110,32 +110,32 @@ proc port_trace {pwd} {
proc port_install {} {
global bindir portsrc

set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port install > output 2>@1} ]
set result [catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port install > output 2>@1} ]
}

# Run configure command.
proc port_config {pwd} {
global path bindir portsrc

set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port configure 2>@1} ]
set result [catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port configure 2>@1} ]
}

# Run destroot command.
proc port_destroot {pwd} {
global path bindir portsrc work_dir output_file

file copy -force ${path}/statefile ${work_dir}/.macports.statefile-unknown-version.state
if { [exec id -u] == 0 } {
exec chown macports ${work_dir}/.macports.statefile-unknown-version.state
if { [exec -ignorestderr id -u] == 0 } {
exec -ignorestderr chown macports ${work_dir}/.macports.statefile-unknown-version.state
}
set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port destroot >$output_file 2>@1} ]
set result [catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port destroot >$output_file 2>@1} ]
}

# Uninstalls portfile.
proc port_uninstall {} {
global bindir portsrc

set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port uninstall > output 2>@1} ]
set result [catch {exec -ignorestderr env PORTSRC=${portsrc} ${bindir}/port uninstall > output 2>@1} ]
}

# Returns the line containint a given string
Expand Down
2 changes: 1 addition & 1 deletion tests/test/statefile-version1-outdated/test.tcl
Expand Up @@ -13,7 +13,7 @@ port_index
port_config $path
file copy -force $path/statefile $work_dir/.macports.statefile-version1-outdated.state
file attributes $work_dir/.macports.statefile-version1-outdated.state -permissions 0664
exec touch -t 197001010000.09 $work_dir/.macports.statefile-version1-outdated.state
exec -ignorestderr touch -t 197001010000.09 $work_dir/.macports.statefile-version1-outdated.state
port_destroot $path
port_clean $path

Expand Down
2 changes: 1 addition & 1 deletion tests/test/statefile-version2/test.tcl
Expand Up @@ -14,7 +14,7 @@ set_dir
port_index
port_config $path
file copy -force $path/statefile $work_dir/.macports.statefile-version2.state
exec sed -i'' -E "s/@CHECKSUM@/`openssl dgst -sha256 Portfile | \
exec -ignorestderr sed -i'' -E "s/@CHECKSUM@/`openssl dgst -sha256 Portfile | \
awk '{print \$\$2}'`/" $work_dir/.macports.statefile-version2.state
port_destroot $path
port_clean $path
Expand Down
2 changes: 1 addition & 1 deletion tests/test/svn-and-patchsites/test.tcl
Expand Up @@ -15,7 +15,7 @@ proc svn-patch {} {
return "No error found."
} else {
set ret "Errors found in output file:\n"
append ret [exec cat $path/$output_file]
append ret [exec -ignorestderr cat $path/$output_file]
return $ret
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/test/trace/test.tcl.in
Expand Up @@ -29,15 +29,15 @@ proc test_trace {} {
makeDirectory ../tracetesttmp
if {[getuid] == 0} {
file attributes ../tracetesttmp -owner $user
exec chown -h $user /tmp/link-trace2
exec -ignorestderr chown -h $user /tmp/link-trace2
}

if {[getuid] == 0} {
seteuid [name_to_uid $user]
}
exec touch ../tracetesttmp/delete-trace
exec touch ../tracetesttmp/rename-trace
exec mkdir ../tracetesttmp/rmdir-trace
exec -ignorestderr touch ../tracetesttmp/delete-trace
exec -ignorestderr touch ../tracetesttmp/rename-trace
exec -ignorestderr mkdir ../tracetesttmp/rmdir-trace
if {[getuid] == 0} {
seteuid 0
}
Expand Down
6 changes: 3 additions & 3 deletions tests/test/universal/test.tcl
Expand Up @@ -19,17 +19,17 @@ proc univ_test {opt} {
# Modify Porfile.in for variants.
if {$opt ne "yes"} {
# No universal variant
exec sed "s/@option@/universal_variant\ no/" $path/Portfile.in > Portfile
exec -ignorestderr sed "s/@option@/universal_variant\ no/" $path/Portfile.in > Portfile
} else {
# Add universal variant
exec sed "s/@option@/default_variants\ +universal/" $path/Portfile.in > Portfile
exec -ignorestderr sed "s/@option@/default_variants\ +universal/" $path/Portfile.in > Portfile
}
port_clean $path

# Build helping string
set string "export PORTSRC=${portsrc} ; ${bindir}/port info --variants"

exec sh -c $string > output 2>@1
exec -ignorestderr sh -c $string > output 2>@1
set var "variants:*"
set line [get_line $path/$output_file $var]
return $line
Expand Down

0 comments on commit 3741e56

Please sign in to comment.