File tree Expand file tree Collapse file tree 8 files changed +74
-6
lines changed 
jvmTest/kotlin/test/assertk Expand file tree Collapse file tree 8 files changed +74
-6
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,7 @@ kotlin {
6464        }
6565    }
6666}
67+ 
68+ tasks.withType<Test >().configureEach {
69+     useJUnitPlatform()
70+ }
Original file line number Diff line number Diff line change 1+ package  assertk 
2+ 
3+ /* *
4+  * Aborts the test instead of failing it, this gives you a way to skip tests based on a dynamic assertion. 
5+  * 
6+  * ``` 
7+  * // only run test on windows 
8+  * assume { 
9+  *     assertThat(System.getProperty("os.name")).startsWith("Windows") 
10+  * } 
11+  * ``` 
12+  */  
13+ fun  assume (f :  () ->  Unit ) {
14+     AssumptionFailure .run  { f() }
15+ }
Original file line number Diff line number Diff line change 33
44package  assertk 
55
6+ import  com.willowtreeapps.opentest4k.AssertionFailedError 
7+ import  com.willowtreeapps.opentest4k.TestAbortedException 
8+ 
69internal  actual  inline  fun  failWithNotInStacktrace (error :  Throwable ): Nothing  {
710    val  filtered =  error.stackTrace
8-              .dropWhile { it.className.startsWith(" assertk" 
9-              .toTypedArray()
11+         .dropWhile { it.className.startsWith(" assertk" 
12+         .toTypedArray()
1013    @Suppress(" PLATFORM_CLASS_MAPPED_TO_KOTLIN" " UnsafeCast" 
1114    error.stackTrace =  filtered
1215    throw  error
@@ -18,3 +21,21 @@ internal actual inline fun Throwable.addSuppressed(error: Throwable) {
1821}
1922
2023internal  actual  inline  fun  Throwable.isOutOfMemory (): Boolean  =  this  is  OutOfMemoryError 
24+ 
25+ internal  object  AssumptionFailure : Failure {
26+     override  fun  fail (error :  Throwable ) {
27+         failWithNotInStacktrace(
28+             TestAbortedException (
29+                 buildString {
30+                     append(" Assumption failed" 
31+                     error.message?.let  { message -> 
32+                         append(" : " 
33+                         append(message)
34+                     }
35+                 },
36+                 //  unwrap assertion errors
37+                 if  (error is  AssertionFailedError ) error.cause else  error
38+             )
39+         )
40+     }
41+ }
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import assertk.all
44import  assertk.assertAll 
55import  assertk.assertThat 
66import  assertk.assertions.* 
7- import  org.junit.Test 
87import  java.util.concurrent.Executors 
98import  java.util.concurrent.TimeUnit 
9+ import  kotlin.test.Test 
1010import  kotlin.test.assertEquals 
1111import  kotlin.test.assertFailsWith 
1212import  kotlin.test.assertFalse 
Original file line number Diff line number Diff line change 1+ package  test.assertk.assertions 
2+ 
3+ import  assertk.assertThat 
4+ import  assertk.assertions.isFalse 
5+ import  assertk.assume 
6+ import  com.willowtreeapps.opentest4k.TestAbortedException 
7+ import  kotlin.test.Test 
8+ import  kotlin.test.assertEquals 
9+ import  kotlin.test.assertFailsWith 
10+ 
11+ class  AssumeTest  {
12+     @Test
13+     fun  assume_throws_TestAbortedException () {
14+         val  error =  assertFailsWith<TestAbortedException > {
15+             assume {
16+                 assertThat(true ).isFalse()
17+             }
18+         }
19+ 
20+         assertEquals(" Assumption failed: expected to be false" 
21+     }
22+ 
23+     @Test
24+     fun  assume_aborts_instead_of_fails_test () {
25+         //  this test should be skipped instead of failing
26+         assume { assertThat(true ).isFalse() }
27+     }
28+ }
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ package test.assertk.assertions
22
33import  assertk.assertThat 
44import  assertk.assertions.isSuccess 
5- import  org.junit.Test 
65import  test.assertk.exceptionPackageName 
6+ import  kotlin.test.Test 
77import  kotlin.test.assertEquals 
88import  kotlin.test.assertFailsWith 
99import  kotlin.test.assertNotNull 
Original file line number Diff line number Diff line change @@ -4,10 +4,10 @@ import assertk.all
44import  assertk.assertAll 
55import  assertk.assertThat 
66import  assertk.assertions.* 
7- import  org.junit.Test 
87import  java.time.LocalDate 
98import  java.time.Month 
109import  java.util.* 
10+ import  kotlin.test.Test 
1111import  kotlin.test.assertEquals 
1212import  kotlin.test.assertFailsWith 
1313
Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import assertk.assertThat
44import  assertk.assertions.isNegative 
55import  assertk.assertions.isPositive 
66import  assertk.assertions.isZero 
7- import  org.junit.Test 
87import  java.math.BigDecimal 
98import  java.math.BigInteger 
9+ import  kotlin.test.Test 
1010import  kotlin.test.assertEquals 
1111import  kotlin.test.assertFailsWith 
1212
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments