2010-04-20 07:00:08 +08:00
/ *
2013-01-11 06:04:08 +08:00
* Copyright ( c ) 2012 The Broad Institute
*
* Permission is hereby granted , free of charge , to any person
* obtaining a copy of this software and associated documentation
* files ( the "Software" ) , to deal in the Software without
* restriction , including without limitation the rights to use ,
* copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the
* Software is furnished to do so , subject to the following
* conditions :
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED "AS IS" , WITHOUT WARRANTY OF ANY KIND ,
* EXPRESS OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY , FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT . IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY ,
* WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING
* FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE .
* /
2010-04-20 07:00:08 +08:00
2009-09-05 03:13:37 +08:00
package org.broadinstitute.sting ;
2011-05-24 22:34:55 +08:00
import org.apache.commons.lang.StringUtils ;
2010-10-09 03:53:21 +08:00
import org.broad.tribble.Tribble ;
2011-07-15 03:12:28 +08:00
import org.broad.tribble.index.Index ;
2010-10-09 03:53:21 +08:00
import org.broad.tribble.index.IndexFactory ;
2009-09-09 09:02:04 +08:00
import org.broadinstitute.sting.gatk.CommandLineExecutable ;
import org.broadinstitute.sting.gatk.CommandLineGATK ;
2011-04-08 01:03:48 +08:00
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine ;
2012-04-13 02:42:40 +08:00
import org.broadinstitute.sting.gatk.phonehome.GATKRunReport ;
2009-09-09 09:02:04 +08:00
import org.broadinstitute.sting.utils.Utils ;
2012-12-19 03:56:48 +08:00
import org.broadinstitute.variant.bcf2.BCF2Utils ;
2013-01-30 02:57:39 +08:00
import org.broadinstitute.sting.utils.collections.Pair ;
2012-12-19 03:56:48 +08:00
import org.broadinstitute.variant.vcf.VCFCodec ;
2012-04-13 02:42:40 +08:00
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException ;
2010-10-09 03:53:21 +08:00
import org.broadinstitute.sting.utils.exceptions.StingException ;
2012-12-19 03:56:48 +08:00
import org.broadinstitute.variant.variantcontext.VariantContextTestProvider ;
2010-11-02 05:31:44 +08:00
import org.testng.Assert ;
2012-06-07 02:02:01 +08:00
import org.testng.annotations.AfterSuite ;
2011-04-08 01:03:48 +08:00
import org.testng.annotations.BeforeMethod ;
2009-09-05 03:13:37 +08:00
2012-09-06 04:35:00 +08:00
import java.io.ByteArrayOutputStream ;
import java.io.File ;
import java.io.PrintStream ;
2012-05-29 08:20:05 +08:00
import java.text.SimpleDateFormat ;
2010-03-05 00:02:21 +08:00
import java.util.* ;
2009-09-05 03:13:37 +08:00
public class WalkerTest extends BaseTest {
Phase I commit to get shadowBCFs passing tests
-- The GATK VCFWriter now enforces by default that all INFO, FILTER, and FORMAT fields be properly defined in the header. This helps avoid some of the low-level errors I saw in SelectVariants. This behavior can be disable in the engine with the --allowMissingVCFHeaders argument
-- Fixed broken annotations in TandemRepeat, which were overwriting AD instead of defining RPA
-- Optimizations to VariantEval, removing some obvious low-hanging fruit all in the subsetting of variants by sample
-- SelectVariants header fixes -- Was defining DP for the info field as a FORMAT field, as for AC, AF, and AN original
-- Performance optimizations in BCF2 codec and writer
-- using arrays not lists for intermediate data structures
-- Create once and reuse an array of GenotypeBuilders for the codec, avoiding reallocating this data structure over and over
-- VCFHeader (which needs a complete rewrite, FYI Eric)
-- Warn and fix on the way flag values with counts > 0
-- GenotypeSampleNames are now stored as a List as they are ordered, and the set iteration was slow. Duplicates are detected once at header creation.
-- Explicitly track FILTER fields for efficient lookup in their own hashmap
-- Automatically add PL field when we see a GL field and no PL field
-- Added get and has methods for INFO, FILTER, and FORMAT fields
-- No longer add AC and AF values to the INFO field when there's no ALT allele
-- Memory efficient comparison of VCF and BCF files for shadow BCF testing. Now there's no (memory) constraint on the size of the files we can compare
-- Because of VCF's limited floating point resolution we can only use 1 sig digit for comparing doubles between BCF and VCF
2012-06-16 02:25:00 +08:00
private static final boolean GENERATE_SHADOW_BCF = true ;
2012-02-23 05:45:20 +08:00
private static final boolean ENABLE_PHONE_HOME_FOR_TESTS = false ;
2012-03-18 12:53:29 +08:00
private static final boolean ENABLE_ON_THE_FLY_CHECK_FOR_VCF_INDEX = false ;
2010-03-05 04:20:58 +08:00
2012-06-07 02:02:01 +08:00
private static MD5DB md5DB = new MD5DB ( ) ;
2011-04-08 01:03:48 +08:00
@BeforeMethod
2012-06-07 02:02:01 +08:00
public void initializeWalkerTests ( ) {
logger . debug ( "Initializing walker tests" ) ;
2011-04-08 01:03:48 +08:00
GenomeAnalysisEngine . resetRandomGenerator ( ) ;
}
2012-06-07 02:02:01 +08:00
@AfterSuite
public void finalizeWalkerTests ( ) {
logger . debug ( "Finalizing walker tests" ) ;
md5DB . close ( ) ;
}
public static MD5DB getMd5DB ( ) {
return md5DB ;
}
2011-10-05 06:53:52 +08:00
public MD5DB . MD5Match assertMatchingMD5 ( final String name , final File resultsFile , final String expectedMD5 ) {
2012-06-07 02:02:01 +08:00
return getMd5DB ( ) . assertMatchingMD5 ( name , resultsFile , expectedMD5 , parameterize ( ) ) ;
2009-09-05 03:13:37 +08:00
}
2012-05-22 04:38:58 +08:00
public void validateOutputBCFIfPossible ( final String name , final File resultFile ) {
2012-05-25 01:26:05 +08:00
final File bcfFile = BCF2Utils . shadowBCF ( resultFile ) ;
2012-06-23 01:05:59 +08:00
if ( bcfFile ! = null & & bcfFile . exists ( ) ) {
2012-05-22 04:38:58 +08:00
logger . warn ( "Checking shadow BCF output file " + bcfFile + " against VCF file " + resultFile ) ;
try {
VariantContextTestProvider . assertVCFandBCFFilesAreTheSame ( resultFile , bcfFile ) ;
2012-05-31 23:20:41 +08:00
logger . warn ( " Shadow BCF PASSED!" ) ;
2012-05-22 04:38:58 +08:00
} catch ( Exception e ) {
Assert . fail ( "Exception received reading shadow BCFFile " + bcfFile + " for test " + name , e ) ;
}
}
}
public void validateOutputIndex ( final String name , final File resultFile ) {
2012-03-18 12:53:29 +08:00
if ( ! ENABLE_ON_THE_FLY_CHECK_FOR_VCF_INDEX )
return ;
2010-10-09 03:53:21 +08:00
File indexFile = Tribble . indexFile ( resultFile ) ;
//System.out.println("Putative index file is " + indexFile);
if ( indexFile . exists ( ) ) {
if ( resultFile . getAbsolutePath ( ) . contains ( ".vcf" ) ) {
// todo -- currently we only understand VCF files! Blow up since we can't test them
throw new StingException ( "Found an index created for file " + resultFile + " but we can only validate VCF files. Extend this code!" ) ;
}
2012-05-22 04:38:58 +08:00
System . out . println ( "Verifying on-the-fly index " + indexFile + " for test " + name + " using file " + resultFile ) ;
Index indexFromOutputFile = IndexFactory . createDynamicIndex ( resultFile , new VCFCodec ( ) ) ;
Index dynamicIndex = IndexFactory . loadIndex ( indexFile . getAbsolutePath ( ) ) ;
2011-07-15 03:12:28 +08:00
2012-05-22 04:38:58 +08:00
if ( ! indexFromOutputFile . equalsIgnoreProperties ( dynamicIndex ) ) {
Assert . fail ( String . format ( "Index on disk from indexing on the fly not equal to the index created after the run completed. FileIndex %s vs. on-the-fly %s%n" ,
indexFromOutputFile . getProperties ( ) ,
dynamicIndex . getProperties ( ) ) ) ;
}
2011-07-16 21:22:34 +08:00
}
2012-03-18 12:53:29 +08:00
}
2011-07-15 03:12:28 +08:00
2010-03-05 04:20:58 +08:00
public List < String > assertMatchingMD5s ( final String name , List < File > resultFiles , List < String > expectedMD5s ) {
2009-09-05 03:13:37 +08:00
List < String > md5s = new ArrayList < String > ( ) ;
2011-10-05 06:53:52 +08:00
List < MD5DB . MD5Match > fails = new ArrayList < MD5DB . MD5Match > ( ) ;
2010-03-05 04:20:58 +08:00
for ( int i = 0 ; i < resultFiles . size ( ) ; i + + ) {
2011-10-05 06:53:52 +08:00
MD5DB . MD5Match result = assertMatchingMD5 ( name , resultFiles . get ( i ) , expectedMD5s . get ( i ) ) ;
2012-05-31 23:20:41 +08:00
validateOutputBCFIfPossible ( name , resultFiles . get ( i ) ) ;
2011-10-05 06:53:52 +08:00
if ( ! result . failed ) {
2012-05-22 04:38:58 +08:00
validateOutputIndex ( name , resultFiles . get ( i ) ) ;
2012-05-24 22:50:33 +08:00
md5s . add ( result . expectedMD5 ) ;
2011-10-05 06:53:52 +08:00
} else {
fails . add ( result ) ;
}
}
if ( ! fails . isEmpty ( ) ) {
2012-05-24 22:50:33 +08:00
List < String > actuals = new ArrayList < String > ( ) ;
List < String > expecteds = new ArrayList < String > ( ) ;
2011-10-05 06:53:52 +08:00
for ( final MD5DB . MD5Match fail : fails ) {
2012-05-24 22:50:33 +08:00
actuals . add ( fail . actualMD5 ) ;
expecteds . add ( fail . expectedMD5 ) ;
2011-10-05 06:53:52 +08:00
logger . warn ( "Fail: " + fail . failMessage ) ;
}
2012-05-24 22:50:33 +08:00
final MD5Mismatch failure = new MD5Mismatch ( actuals , expecteds ) ;
Assert . fail ( failure . toString ( ) , failure ) ;
2009-09-05 03:13:37 +08:00
}
return md5s ;
}
2011-02-18 14:26:38 +08:00
public String buildCommandLine ( String . . . arguments ) {
2011-02-14 01:58:20 +08:00
String cmdline = "" ;
for ( int argIndex = 0 ; argIndex < arguments . length ; argIndex + + ) {
cmdline + = arguments [ argIndex ] ;
if ( argIndex < arguments . length - 1 ) {
cmdline + = " " ;
}
}
return cmdline ;
}
2009-09-05 03:13:37 +08:00
public class WalkerTestSpec {
2012-02-23 05:45:20 +08:00
// Arguments implicitly included in all Walker command lines, unless explicitly
// disabled using the disableImplicitArgs() method below.
2009-09-05 03:13:37 +08:00
String args = "" ;
int nOutputFiles = - 1 ;
List < String > md5s = null ;
2009-10-20 05:54:53 +08:00
List < String > exts = null ;
2010-09-12 22:02:43 +08:00
Class expectedException = null ;
2012-02-23 05:45:20 +08:00
boolean includeImplicitArgs = true ;
2012-05-22 19:14:46 +08:00
boolean includeShadowBCF = true ;
2009-09-05 03:13:37 +08:00
2011-02-01 23:25:50 +08:00
// the default output path for the integration test
private File outputFileLocation = null ;
2010-03-05 04:20:58 +08:00
protected Map < String , File > auxillaryFiles = new HashMap < String , File > ( ) ;
2010-03-05 00:02:21 +08:00
2010-11-14 00:19:56 +08:00
public WalkerTestSpec ( String args , List < String > md5s ) {
this ( args , - 1 , md5s ) ;
}
2009-09-05 03:13:37 +08:00
public WalkerTestSpec ( String args , int nOutputFiles , List < String > md5s ) {
this . args = args ;
2010-11-14 00:19:56 +08:00
this . nOutputFiles = md5s . size ( ) ;
2009-09-05 03:13:37 +08:00
this . md5s = md5s ;
}
2009-10-20 05:54:53 +08:00
2010-11-14 00:19:56 +08:00
public WalkerTestSpec ( String args , List < String > exts , List < String > md5s ) {
this ( args , - 1 , exts , md5s ) ;
}
2009-10-20 05:54:53 +08:00
public WalkerTestSpec ( String args , int nOutputFiles , List < String > exts , List < String > md5s ) {
this . args = args ;
2010-11-14 00:19:56 +08:00
this . nOutputFiles = md5s . size ( ) ;
2009-10-20 05:54:53 +08:00
this . md5s = md5s ;
this . exts = exts ;
}
2010-03-05 00:02:21 +08:00
2010-09-12 22:02:43 +08:00
public WalkerTestSpec ( String args , int nOutputFiles , Class expectedException ) {
this . args = args ;
this . nOutputFiles = nOutputFiles ;
this . expectedException = expectedException ;
}
2012-02-23 05:45:20 +08:00
public String getArgsWithImplicitArgs ( ) {
2012-05-22 04:38:58 +08:00
String args = this . args ;
if ( includeImplicitArgs ) {
args = args + ( ENABLE_PHONE_HOME_FOR_TESTS ?
String . format ( " -et %s " , GATKRunReport . PhoneHomeOption . STANDARD ) :
String . format ( " -et %s -K %s " , GATKRunReport . PhoneHomeOption . NO_ET , gatkKeyFile ) ) ;
2012-05-22 19:14:46 +08:00
if ( includeShadowBCF & & GENERATE_SHADOW_BCF )
2012-05-22 04:38:58 +08:00
args = args + " --generateShadowBCF " ;
}
return args ;
2012-02-23 05:45:20 +08:00
}
2012-05-22 19:14:46 +08:00
/ * *
* In the case where the input VCF files are malformed and cannot be fixed
* this function tells the engine to not try to generate a shadow BCF
* which will ultimately blow up . . .
* /
public void disableShadowBCF ( ) { this . includeShadowBCF = false ; }
2011-02-01 23:25:50 +08:00
public void setOutputFileLocation ( File outputFileLocation ) {
this . outputFileLocation = outputFileLocation ;
}
protected File getOutputFileLocation ( ) {
return outputFileLocation ;
}
2010-09-12 22:02:43 +08:00
public boolean expectsException ( ) {
return expectedException ! = null ;
}
public Class getExpectedException ( ) {
2010-09-12 23:07:38 +08:00
if ( ! expectsException ( ) ) throw new ReviewedStingException ( "Tried to get expection for walker test that doesn't expect one" ) ;
2010-09-12 22:02:43 +08:00
return expectedException ;
}
2010-03-05 00:02:21 +08:00
public void addAuxFile ( String expectededMD5sum , File outputfile ) {
2010-03-05 04:20:58 +08:00
auxillaryFiles . put ( expectededMD5sum , outputfile ) ;
2010-03-05 00:02:21 +08:00
}
2011-02-01 23:25:50 +08:00
2012-02-23 05:45:20 +08:00
public void disableImplicitArgs ( ) {
includeImplicitArgs = false ;
}
2009-09-05 03:13:37 +08:00
}
protected boolean parameterize ( ) {
return false ;
}
2012-09-06 04:35:00 +08:00
public enum ParallelTestType {
TREE_REDUCIBLE ,
NANO_SCHEDULED ,
BOTH
}
protected Pair < List < File > , List < String > > executeTestParallel ( final String name , WalkerTestSpec spec , ParallelTestType testType ) {
final List < Integer > ntThreads = testType = = ParallelTestType . TREE_REDUCIBLE | | testType = = ParallelTestType . BOTH ? Arrays . asList ( 1 , 4 ) : Collections . < Integer > emptyList ( ) ;
final List < Integer > cntThreads = testType = = ParallelTestType . NANO_SCHEDULED | | testType = = ParallelTestType . BOTH ? Arrays . asList ( 1 , 4 ) : Collections . < Integer > emptyList ( ) ;
return executeTest ( name , spec , ntThreads , cntThreads ) ;
}
2010-10-27 04:21:38 +08:00
protected Pair < List < File > , List < String > > executeTestParallel ( final String name , WalkerTestSpec spec ) {
2012-09-06 08:57:49 +08:00
return executeTestParallel ( name , spec , ParallelTestType . TREE_REDUCIBLE ) ;
2010-10-27 04:21:38 +08:00
}
2012-09-06 04:35:00 +08:00
protected Pair < List < File > , List < String > > executeTest ( final String name , WalkerTestSpec spec , List < Integer > ntThreads , List < Integer > cpuThreads ) {
2010-10-27 04:21:38 +08:00
String originalArgs = spec . args ;
Pair < List < File > , List < String > > results = null ;
2012-09-06 04:35:00 +08:00
boolean ran1 = false ;
for ( int nt : ntThreads ) {
2010-10-27 04:21:38 +08:00
String extra = nt = = 1 ? "" : ( " -nt " + nt ) ;
2012-09-06 04:35:00 +08:00
ran1 = ran1 | | nt = = 1 ;
2010-10-27 04:21:38 +08:00
spec . args = originalArgs + extra ;
results = executeTest ( name + "-nt-" + nt , spec ) ;
}
2012-09-06 09:13:19 +08:00
for ( int nct : cpuThreads ) {
if ( nct ! = 1 ) {
String extra = " -nct " + nct ;
2012-09-06 04:35:00 +08:00
spec . args = originalArgs + extra ;
2012-09-06 09:13:19 +08:00
results = executeTest ( name + "-cnt-" + nct , spec ) ;
2012-09-06 04:35:00 +08:00
}
}
2010-10-27 04:21:38 +08:00
return results ;
}
2009-09-05 06:26:57 +08:00
protected Pair < List < File > , List < String > > executeTest ( final String name , WalkerTestSpec spec ) {
2009-09-05 03:13:37 +08:00
List < File > tmpFiles = new ArrayList < File > ( ) ;
2010-03-05 04:20:58 +08:00
for ( int i = 0 ; i < spec . nOutputFiles ; i + + ) {
String ext = spec . exts = = null ? ".tmp" : "." + spec . exts . get ( i ) ;
File fl = createTempFile ( String . format ( "walktest.tmp_param.%d" , i ) , ext ) ;
tmpFiles . add ( fl ) ;
2009-09-05 03:13:37 +08:00
}
2012-02-23 05:45:20 +08:00
final String args = String . format ( spec . getArgsWithImplicitArgs ( ) , tmpFiles . toArray ( ) ) ;
2009-10-21 07:31:13 +08:00
System . out . println ( Utils . dupString ( '-' , 80 ) ) ;
2009-09-05 06:26:57 +08:00
2010-09-12 22:02:43 +08:00
if ( spec . expectsException ( ) ) {
// this branch handles the case were we are testing that a walker will fail as expected
2011-02-01 23:25:50 +08:00
return executeTest ( name , spec . getOutputFileLocation ( ) , null , tmpFiles , args , spec . getExpectedException ( ) ) ;
2010-09-12 22:02:43 +08:00
} else {
List < String > md5s = new LinkedList < String > ( ) ;
md5s . addAll ( spec . md5s ) ;
2010-03-05 00:02:21 +08:00
2010-09-12 22:02:43 +08:00
// check to see if they included any auxillary files, if so add them to the list
for ( String md5 : spec . auxillaryFiles . keySet ( ) ) {
md5s . add ( md5 ) ;
tmpFiles . add ( spec . auxillaryFiles . get ( md5 ) ) ;
}
2011-02-01 23:25:50 +08:00
return executeTest ( name , spec . getOutputFileLocation ( ) , md5s , tmpFiles , args , null ) ;
2010-03-05 00:02:21 +08:00
}
}
2011-05-24 22:34:55 +08:00
private void qcMD5s ( String name , List < String > md5s ) {
final String exampleMD5 = "709a1f482cce68992c637da3cff824a8" ;
for ( String md5 : md5s ) {
if ( md5 = = null )
throw new IllegalArgumentException ( "Null MD5 found in test " + name ) ;
if ( md5 . equals ( "" ) ) // ok
2011-05-27 22:00:52 +08:00
continue ;
2011-05-24 22:34:55 +08:00
if ( ! StringUtils . isAlphanumeric ( md5 ) )
throw new IllegalArgumentException ( "MD5 contains non-alphanumeric characters test " + name + " md5=" + md5 ) ;
if ( md5 . length ( ) ! = exampleMD5 . length ( ) )
throw new IllegalArgumentException ( "Non-empty MD5 of unexpected number of characters test " + name + " md5=" + md5 ) ;
}
}
2010-03-05 00:02:21 +08:00
/ * *
* execute the test , given the following :
2010-03-05 04:20:58 +08:00
* @param name the name of the test
* @param md5s the list of md5s
2010-03-05 00:02:21 +08:00
* @param tmpFiles the temp file corresponding to the md5 list
2010-03-05 04:20:58 +08:00
* @param args the argument list
2010-11-23 06:59:42 +08:00
* @param expectedException the expected exception or null
2010-03-05 00:02:21 +08:00
* @return a pair of file and string lists
* /
2011-02-01 23:25:50 +08:00
private Pair < List < File > , List < String > > executeTest ( String name , File outputFileLocation , List < String > md5s , List < File > tmpFiles , String args , Class expectedException ) {
2011-05-25 03:17:18 +08:00
if ( md5s ! = null ) qcMD5s ( name , md5s ) ;
2011-05-24 22:34:55 +08:00
2010-11-23 06:59:42 +08:00
if ( outputFileLocation ! = null )
2011-02-01 23:25:50 +08:00
args + = " -o " + outputFileLocation . getAbsolutePath ( ) ;
2010-11-23 06:59:42 +08:00
executeTest ( name , args , expectedException ) ;
if ( expectedException ! = null ) {
return null ;
} else {
// we need to check MD5s
return new Pair < List < File > , List < String > > ( tmpFiles , assertMatchingMD5s ( name , tmpFiles , md5s ) ) ;
}
}
/ * *
* execute the test , given the following :
* @param name the name of the test
* @param args the argument list
* @param expectedException the expected exception or null
* /
2012-02-23 05:45:20 +08:00
private void executeTest ( String name , String args , Class expectedException ) {
2009-09-05 03:13:37 +08:00
CommandLineGATK instance = new CommandLineGATK ( ) ;
2010-11-13 04:14:28 +08:00
String [ ] command = Utils . escapeExpressions ( args ) ;
2010-08-10 10:57:23 +08:00
// run the executable
2010-09-12 22:02:43 +08:00
boolean gotAnException = false ;
2010-09-09 19:32:20 +08:00
try {
2012-05-27 23:13:43 +08:00
final String now = new SimpleDateFormat ( "HH:mm:ss" ) . format ( new Date ( ) ) ;
2012-05-31 23:20:41 +08:00
final String cmdline = Utils . join ( " " , command ) ;
System . out . println ( String . format ( "[%s] Executing test %s with GATK arguments: %s" , now , name , cmdline ) ) ;
2012-06-10 22:53:51 +08:00
// also write the command line to the HTML log for convenient follow-up
// do the replaceAll so paths become relative to the current
2012-06-21 03:35:36 +08:00
BaseTest . log ( cmdline . replaceAll ( publicTestDirRoot , "" ) . replaceAll ( privateTestDirRoot , "" ) ) ;
2010-11-13 04:14:28 +08:00
CommandLineExecutable . start ( instance , command ) ;
2010-09-09 19:32:20 +08:00
} catch ( Exception e ) {
2010-09-12 22:02:43 +08:00
gotAnException = true ;
if ( expectedException ! = null ) {
// we expect an exception
2012-05-24 22:50:33 +08:00
//System.out.println(String.format("Wanted exception %s, saw %s", expectedException, e.getClass()));
2010-09-12 22:02:43 +08:00
if ( expectedException . isInstance ( e ) ) {
// it's the type we expected
2012-05-24 22:50:33 +08:00
//System.out.println(String.format(" => %s PASSED", name));
2010-09-12 22:02:43 +08:00
} else {
2012-07-26 10:11:10 +08:00
final String message = String . format ( "Test %s expected exception %s but instead got %s with error message %s" ,
name , expectedException , e . getClass ( ) , e . getMessage ( ) ) ;
if ( e . getCause ( ) ! = null ) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ;
final PrintStream ps = new PrintStream ( baos ) ;
e . getCause ( ) . printStackTrace ( ps ) ;
BaseTest . log ( message ) ;
BaseTest . log ( baos . toString ( ) ) ;
}
Assert . fail ( message ) ;
2010-09-12 22:02:43 +08:00
}
} else {
// we didn't expect an exception but we got one :-(
throw new RuntimeException ( e ) ;
}
2010-09-09 19:32:20 +08:00
}
2010-08-10 10:57:23 +08:00
// catch failures from the integration test
2010-09-12 22:02:43 +08:00
if ( expectedException ! = null ) {
if ( ! gotAnException )
// we expected an exception but didn't see it
Assert . fail ( String . format ( "Test %s expected exception %s but none was thrown" , name , expectedException . toString ( ) ) ) ;
} else {
if ( CommandLineExecutable . result ! = 0 ) {
throw new RuntimeException ( "Error running the GATK with arguments: " + args ) ;
}
2009-09-05 06:26:57 +08:00
}
2010-03-05 00:02:21 +08:00
}
2011-01-27 07:48:04 +08:00
protected File createTempFileFromBase ( String name ) {
File fl = new File ( name ) ;
fl . deleteOnExit ( ) ;
return fl ;
2012-05-24 22:50:33 +08:00
}
2010-09-01 00:18:57 +08:00
}