Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
dbcbebca
Commit
dbcbebca
authored
Dec 02, 2014
by
Graeme Rocher
Committed by
Dave Syer
Dec 02, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Propagate exception / test failures so that the correct status code is returned.
Fixes gh-2048 and fixes gh-2051
parent
1611e631
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
11 deletions
+83
-11
CommandRunner.java
...a/org/springframework/boot/cli/command/CommandRunner.java
+4
-0
TestFailedException.java
...gframework/boot/cli/command/test/TestFailedException.java
+28
-0
TestRunner.java
...org/springframework/boot/cli/command/test/TestRunner.java
+42
-8
DelegateTestRunner.java
...a/org/springframework/boot/groovy/DelegateTestRunner.java
+3
-1
CliTester.java
...src/test/java/org/springframework/boot/cli/CliTester.java
+6
-2
No files found.
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/CommandRunner.java
View file @
dbcbebca
...
...
@@ -25,6 +25,7 @@ import java.util.List;
import
java.util.Set
;
import
org.springframework.boot.cli.command.status.ExitStatus
;
import
org.springframework.boot.cli.command.test.TestFailedException
;
import
org.springframework.boot.cli.util.Log
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
...
...
@@ -178,6 +179,9 @@ public class CommandRunner implements Iterable<Command> {
showUsage
();
return
1
;
}
catch
(
TestFailedException
e
)
{
return
1
;
}
catch
(
Exception
ex
)
{
return
handleError
(
debug
,
ex
);
}
...
...
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestFailedException.java
0 → 100644
View file @
dbcbebca
/*
* Copyright 2014 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
cli
.
command
.
test
;
/**
* Thrown when tests fail to execute
*
* @author Graeme Rocher
* @since 1.2
*/
public
class
TestFailedException
extends
RuntimeException
{
public
TestFailedException
(
Throwable
cause
)
{
super
(
cause
);
}
}
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunner.java
View file @
dbcbebca
...
...
@@ -17,6 +17,7 @@
package
org
.
springframework
.
boot
.
cli
.
command
.
test
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -37,6 +38,8 @@ public class TestRunner {
private
final
GroovyCompiler
compiler
;
private
volatile
Throwable
threadException
;
/**
* Create a new {@link TestRunner} instance.
* @param configuration
...
...
@@ -58,7 +61,20 @@ public class TestRunner {
// Run in new thread to ensure that the context classloader is setup
RunThread
runThread
=
new
RunThread
(
sources
);
runThread
.
start
();
runThread
.
setUncaughtExceptionHandler
(
new
Thread
.
UncaughtExceptionHandler
()
{
@Override
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
// rethrow exception
threadException
=
e
;
}
});
runThread
.
join
();
if
(
threadException
!=
null
)
{
Throwable
t
=
threadException
;
threadException
=
null
;
throw
new
TestFailedException
(
t
);
}
}
/**
...
...
@@ -131,15 +147,33 @@ public class TestRunner {
System
.
out
.
println
(
"No tests found"
);
}
else
{
Class
<?>
delegateClass
=
Thread
.
currentThread
()
.
getContextClassLoader
()
ClassLoader
contextClassLoader
=
Thread
.
currentThread
()
.
getContextClassLoader
();
Class
<?>
delegateClass
=
contextClassLoader
.
loadClass
(
DelegateTestRunner
.
class
.
getName
());
Method
runMethod
=
delegateClass
.
getMethod
(
"run"
,
Class
[].
class
);
runMethod
.
invoke
(
null
,
new
Object
[]
{
this
.
testClasses
});
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
Class
resultClass
=
contextClassLoader
.
loadClass
(
"org.junit.runner.Result"
);
Method
runMethod
=
delegateClass
.
getMethod
(
"run"
,
Class
[].
class
,
resultClass
);
Object
result
=
resultClass
.
newInstance
();
runMethod
.
invoke
(
null
,
this
.
testClasses
,
result
);
Boolean
wasSuccessful
=
(
Boolean
)
resultClass
.
getMethod
(
"wasSuccessful"
).
invoke
(
result
);
if
(!
wasSuccessful
)
{
try
{
throw
new
RuntimeException
(
"Tests Failed."
);
}
catch
(
Throwable
throwable
)
{
throw
new
RuntimeException
(
throwable
);
}
}
}
}
catch
(
ClassNotFoundException
e
)
{
throw
new
RuntimeException
(
"Exception occurred running tests: "
+
e
.
getMessage
(),
e
);
}
catch
(
NoSuchMethodException
e
)
{
throw
new
RuntimeException
(
"Exception occurred running tests: "
+
e
.
getMessage
(),
e
);
}
catch
(
InstantiationException
e
)
{
throw
new
RuntimeException
(
"Exception occurred running tests: "
+
e
.
getMessage
(),
e
);
}
catch
(
IllegalAccessException
e
)
{
throw
new
RuntimeException
(
"Exception occurred running tests: "
+
e
.
getMessage
(),
e
);
}
catch
(
InvocationTargetException
e
)
{
throw
new
RuntimeException
(
"Exception occurred running tests: "
+
e
.
getMessage
(),
e
);
}
}
}
...
...
spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java
View file @
dbcbebca
...
...
@@ -18,6 +18,7 @@ package org.springframework.boot.groovy;
import
org.junit.internal.TextListener
;
import
org.junit.runner.JUnitCore
;
import
org.junit.runner.Result
;
import
org.springframework.boot.cli.command.test.TestRunner
;
/**
...
...
@@ -28,9 +29,10 @@ import org.springframework.boot.cli.command.test.TestRunner;
*/
public
class
DelegateTestRunner
{
public
static
void
run
(
Class
<?>[]
testClasses
)
{
public
static
void
run
(
Class
<?>[]
testClasses
,
Result
result
)
{
JUnitCore
jUnitCore
=
new
JUnitCore
();
jUnitCore
.
addListener
(
new
TextListener
(
System
.
out
));
jUnitCore
.
addListener
(
result
.
createListener
());
jUnitCore
.
run
(
testClasses
);
}
...
...
spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java
View file @
dbcbebca
...
...
@@ -78,8 +78,12 @@ public class CliTester implements TestRule {
public
String
test
(
String
...
args
)
throws
Exception
{
Future
<
TestCommand
>
future
=
submitCommand
(
new
TestCommand
(),
args
);
try
{
this
.
commands
.
add
(
future
.
get
(
this
.
timeout
,
TimeUnit
.
MILLISECONDS
));
return
getOutput
();
}
catch
(
Exception
e
)
{
return
getOutput
();
}
}
public
String
grab
(
String
...
args
)
throws
Exception
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment