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
b5f0f971
Commit
b5f0f971
authored
Oct 08, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up TestCommand paraphenalia
parent
1ce13cc2
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
314 additions
and
332 deletions
+314
-332
pom.xml
spring-boot-cli/pom.xml
+1
-11
book.groovy
spring-boot-cli/samples/book.groovy
+0
-0
book_and_tests.groovy
spring-boot-cli/samples/book_and_tests.groovy
+0
-0
empty.groovy
spring-boot-cli/samples/empty.groovy
+0
-0
spock.groovy
spring-boot-cli/samples/spock.groovy
+0
-0
test.groovy
spring-boot-cli/samples/test.groovy
+0
-0
junit.groovy
spring-boot-cli/src/main/groovy/testers/junit.groovy
+0
-0
spock.groovy
spring-boot-cli/src/main/groovy/testers/spock.groovy
+0
-0
tester.groovy
spring-boot-cli/src/main/groovy/testers/tester.groovy
+0
-0
TestCommand.java
...ava/org/springframework/boot/cli/command/TestCommand.java
+231
-225
springcli.properties
...boot-cli/src/main/resources/META-INF/springcli.properties
+0
-14
TestCommandIntegrationTests.java
...springframework/boot/cli/TestCommandIntegrationTests.java
+80
-79
handler.groovy
spring-boot-cli/src/test/resources/commands/handler.groovy
+2
-3
No files found.
spring-boot-cli/pom.xml
View file @
b5f0f971
...
...
@@ -33,10 +33,6 @@
<groupId>
org.codehaus.groovy
</groupId>
<artifactId>
groovy
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-core
</artifactId>
</dependency>
<!-- Optional -->
<dependency>
<groupId>
org.codehaus.groovy
</groupId>
...
...
@@ -48,11 +44,6 @@
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.spockframework
</groupId>
<artifactId>
spock-core
</artifactId>
<scope>
test
</scope>
</dependency>
<!-- Provided (to ensure in m2 repo for @grab to resolve) -->
<dependency>
<groupId>
org.springframework.integration
</groupId>
...
...
@@ -87,8 +78,7 @@
<filtering>
true
</filtering>
</resource>
<resource>
<directory>
testers
</directory>
<targetPath>
testers
</targetPath>
<directory>
src/main/groovy
</directory>
</resource>
</resources>
<plugins>
...
...
spring-boot-cli/
testscript
s/book.groovy
→
spring-boot-cli/
sample
s/book.groovy
View file @
b5f0f971
File moved
spring-boot-cli/
testscript
s/book_and_tests.groovy
→
spring-boot-cli/
sample
s/book_and_tests.groovy
View file @
b5f0f971
File moved
spring-boot-cli/
testscript
s/empty.groovy
→
spring-boot-cli/
sample
s/empty.groovy
View file @
b5f0f971
File moved
spring-boot-cli/
testscript
s/spock.groovy
→
spring-boot-cli/
sample
s/spock.groovy
View file @
b5f0f971
File moved
spring-boot-cli/
testscript
s/test.groovy
→
spring-boot-cli/
sample
s/test.groovy
View file @
b5f0f971
File moved
spring-boot-cli/testers/junit.groovy
→
spring-boot-cli/
src/main/groovy/
testers/junit.groovy
View file @
b5f0f971
File moved
spring-boot-cli/testers/spock.groovy
→
spring-boot-cli/
src/main/groovy/
testers/spock.groovy
View file @
b5f0f971
File moved
spring-boot-cli/testers/tester.groovy
→
spring-boot-cli/
src/main/groovy/
testers/tester.groovy
View file @
b5f0f971
File moved
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/TestCommand.java
View file @
b5f0f971
...
...
@@ -17,248 +17,254 @@
package
org
.
springframework
.
boot
.
cli
.
command
;
import
groovy.lang.GroovyObject
;
import
joptsimple.OptionSet
;
import
org.apache.ivy.util.FileUtil
;
import
org.springframework.boot.cli.Log
;
import
org.springframework.boot.cli.command.tester.Failure
;
import
org.springframework.boot.cli.command.tester.TestResults
;
import
org.springframework.boot.cli.compiler.GroovyCompiler
;
import
org.springframework.boot.cli.compiler.GroovyCompilerConfiguration
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.PrintWriter
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Scanner
;
import
java.util.Set
;
import
java.util.logging.Level
;
import
joptsimple.OptionSet
;
import
org.apache.ivy.util.FileUtil
;
import
org.springframework.boot.cli.Log
;
import
org.springframework.boot.cli.command.tester.Failure
;
import
org.springframework.boot.cli.command.tester.TestResults
;
import
org.springframework.boot.cli.compiler.GroovyCompiler
;
import
org.springframework.boot.cli.compiler.GroovyCompilerConfiguration
;
/**
* Invokes testing for autocompiled scripts
*
*
* @author Greg Turnquist
*/
public
class
TestCommand
extends
OptionParsingCommand
{
private
TestOptionHandler
testOptionHandler
;
public
TestCommand
()
{
super
(
"test"
,
"Test a groovy script"
,
new
TestOptionHandler
());
this
.
testOptionHandler
=
(
TestOptionHandler
)
this
.
getHandler
();
}
@Override
public
String
getUsageHelp
()
{
return
"[options] <files>"
;
}
public
TestResults
getResults
()
{
return
testOptionHandler
.
results
;
}
private
static
class
TestGroovyCompilerConfiguration
implements
GroovyCompilerConfiguration
{
@Override
public
boolean
isGuessImports
()
{
return
true
;
}
@Override
public
boolean
isGuessDependencies
()
{
return
true
;
}
@Override
public
String
getClasspath
()
{
return
""
;
}
public
Level
getLogLevel
()
{
return
Level
.
INFO
;
}
}
private
static
class
TestOptionHandler
extends
OptionHandler
{
private
final
GroovyCompiler
compiler
;
private
TestResults
results
;
public
TestOptionHandler
()
{
TestGroovyCompilerConfiguration
configuration
=
new
TestGroovyCompilerConfiguration
();
this
.
compiler
=
new
GroovyCompiler
(
configuration
);
if
(
configuration
.
getLogLevel
().
intValue
()
<=
Level
.
FINE
.
intValue
())
{
System
.
setProperty
(
"groovy.grape.report.downloads"
,
"true"
);
}
}
@Override
protected
void
run
(
OptionSet
options
)
throws
Exception
{
List
<?>
nonOptionArguments
=
options
.
nonOptionArguments
();
Set
<
File
>
testerFiles
=
new
HashSet
<
File
>();
File
[]
files
=
getFileArguments
(
nonOptionArguments
,
testerFiles
);
/*
* Need to compile the code twice: The first time automatically
* pulls in autoconfigured libraries including test tools. Then
* the compiled code can be scanned to see what libraries were
* activated. Then it can be recompiled, with appropriate tester
* groovy scripts included in the same classloading context. Then
* the testers can be fetched and invoked through reflection against
* the composite AST.
*/
// Compile - Pass 1
Object
[]
sources
=
this
.
compiler
.
sources
(
files
);
boolean
testing
=
false
;
try
{
check
(
"org.junit.Test"
,
sources
);
testerFiles
.
add
(
locateSourceFromUrl
(
"junit"
,
"testers/junit.groovy"
));
testing
=
true
;
}
catch
(
ClassNotFoundException
e
)
{
}
try
{
check
(
"spock.lang.Specification"
,
sources
);
testerFiles
.
add
(
locateSourceFromUrl
(
"spock"
,
"testers/spock.groovy"
));
testing
=
true
;
}
catch
(
ClassNotFoundException
e
)
{
}
if
(
testing
)
{
testerFiles
.
add
(
locateSourceFromUrl
(
"tester"
,
"testers/tester.groovy"
));
}
// Compile - Pass 2 - with appropriate testers added in
files
=
getFileArguments
(
nonOptionArguments
,
testerFiles
);
sources
=
this
.
compiler
.
sources
(
files
);
if
(
sources
.
length
==
0
)
{
throw
new
RuntimeException
(
"No classes found in '"
+
files
+
"'"
);
}
List
<
Class
<?>>
testers
=
new
ArrayList
<
Class
<?>>();
// Extract list of compiled classes
List
<
Class
<?>>
compiled
=
new
ArrayList
<
Class
<?>>();
for
(
Object
source
:
sources
)
{
if
(
source
.
getClass
()
==
Class
.
class
)
{
Class
<?>
sourceClass
=
(
Class
<?>)
source
;
if
(
sourceClass
.
getSuperclass
().
getName
().
equals
(
"AbstractTester"
))
{
testers
.
add
(
sourceClass
);
}
else
{
compiled
.
add
((
Class
<?>)
source
);
}
}
}
this
.
results
=
new
TestResults
();
for
(
Class
<?>
tester
:
testers
)
{
GroovyObject
obj
=
(
GroovyObject
)
tester
.
newInstance
();
this
.
results
.
add
((
TestResults
)
obj
.
invokeMethod
(
"findAndTest"
,
compiled
));
}
printReport
(
this
.
results
);
}
private
File
locateSourceFromUrl
(
String
name
,
String
path
)
{
try
{
File
file
=
File
.
createTempFile
(
name
,
".groovy"
);
file
.
deleteOnExit
();
FileUtil
.
copy
(
getClass
().
getClassLoader
().
getResourceAsStream
(
path
),
file
,
null
);
return
file
;
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Could not create temp file for source: "
+
name
);
}
}
private
Class
<?>
check
(
String
className
,
Object
[]
sources
)
throws
ClassNotFoundException
{
Class
<?>
classToReturn
=
null
;
ClassNotFoundException
classNotFoundException
=
null
;
for
(
Object
source
:
sources
)
{
try
{
classToReturn
=
((
Class
<?>)
source
).
getClassLoader
().
loadClass
(
className
);
}
catch
(
ClassNotFoundException
e
)
{
classNotFoundException
=
e
;
}
}
if
(
classToReturn
!=
null
)
{
return
classToReturn
;
}
throw
classNotFoundException
;
}
private
File
[]
getFileArguments
(
List
<?>
nonOptionArguments
,
Set
<
File
>
testerFiles
)
{
List
<
File
>
files
=
new
ArrayList
<
File
>();
for
(
Object
option
:
nonOptionArguments
)
{
if
(
option
instanceof
String
)
{
String
filename
=
(
String
)
option
;
if
(
"--"
.
equals
(
filename
))
{
break
;
}
if
(
filename
.
endsWith
(
".groovy"
)
||
filename
.
endsWith
(
".java"
))
{
File
file
=
new
File
(
filename
);
if
(
file
.
isFile
()
&&
file
.
canRead
())
{
files
.
add
(
file
);
}
else
{
URL
url
=
getClass
().
getClassLoader
().
getResource
(
filename
);
if
(
url
!=
null
)
{
if
(
url
.
toString
().
startsWith
(
"file:"
))
{
files
.
add
(
new
File
(
url
.
toString
().
substring
(
"file:"
.
length
())));
}
}
else
{
throw
new
RuntimeException
(
"Can't find "
+
filename
);
}
}
}
}
}
if
(
files
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"Please specify a file to run"
);
}
for
(
File
testerFile
:
testerFiles
)
{
files
.
add
(
testerFile
);
}
return
files
.
toArray
(
new
File
[
files
.
size
()]);
}
private
void
printReport
(
TestResults
results
)
throws
FileNotFoundException
{
PrintWriter
writer
=
new
PrintWriter
(
"results.txt"
);
String
header
=
"Total: "
+
results
.
getRunCount
()
+
", Success: "
+
(
results
.
getRunCount
()-
results
.
getFailureCount
())
+
", : Failures: "
+
results
.
getFailureCount
()
+
"\n"
+
"Passed? "
+
results
.
wasSuccessful
();
String
trailer
=
""
;
String
trace
=
""
;
for
(
Failure
failure
:
results
.
getFailures
())
{
trailer
+=
failure
.
getDescription
().
toString
();
trace
+=
failure
.
getTrace
()
+
"\n"
;
}
writer
.
println
(
header
);
writer
.
println
(
trace
);
writer
.
close
();
Log
.
info
(
header
);
Log
.
info
(
trailer
);
}
}
private
TestOptionHandler
testOptionHandler
;
public
TestCommand
()
{
super
(
"test"
,
"Test a groovy script"
,
new
TestOptionHandler
());
this
.
testOptionHandler
=
(
TestOptionHandler
)
this
.
getHandler
();
}
@Override
public
String
getUsageHelp
()
{
return
"[options] <files>"
;
}
public
TestResults
getResults
()
{
return
this
.
testOptionHandler
.
results
;
}
private
static
class
TestGroovyCompilerConfiguration
implements
GroovyCompilerConfiguration
{
@Override
public
boolean
isGuessImports
()
{
return
true
;
}
@Override
public
boolean
isGuessDependencies
()
{
return
true
;
}
@Override
public
String
getClasspath
()
{
return
""
;
}
public
Level
getLogLevel
()
{
return
Level
.
INFO
;
}
}
private
static
class
TestOptionHandler
extends
OptionHandler
{
private
final
GroovyCompiler
compiler
;
private
TestResults
results
;
public
TestOptionHandler
()
{
TestGroovyCompilerConfiguration
configuration
=
new
TestGroovyCompilerConfiguration
();
this
.
compiler
=
new
GroovyCompiler
(
configuration
);
if
(
configuration
.
getLogLevel
().
intValue
()
<=
Level
.
FINE
.
intValue
())
{
System
.
setProperty
(
"groovy.grape.report.downloads"
,
"true"
);
}
}
@Override
protected
void
run
(
OptionSet
options
)
throws
Exception
{
List
<?>
nonOptionArguments
=
options
.
nonOptionArguments
();
Set
<
File
>
testerFiles
=
new
HashSet
<
File
>();
File
[]
files
=
getFileArguments
(
nonOptionArguments
,
testerFiles
);
/*
* Need to compile the code twice: The first time automatically pulls in
* autoconfigured libraries including test tools. Then the compiled code can
* be scanned to see what libraries were activated. Then it can be recompiled,
* with appropriate tester groovy scripts included in the same classloading
* context. Then the testers can be fetched and invoked through reflection
* against the composite AST.
*/
// Compile - Pass 1
Object
[]
sources
=
this
.
compiler
.
sources
(
files
);
boolean
testing
=
false
;
try
{
check
(
"org.junit.Test"
,
sources
);
testerFiles
.
add
(
locateSourceFromUrl
(
"junit"
,
"testers/junit.groovy"
));
testing
=
true
;
}
catch
(
ClassNotFoundException
e
)
{
}
try
{
check
(
"spock.lang.Specification"
,
sources
);
testerFiles
.
add
(
locateSourceFromUrl
(
"spock"
,
"testers/spock.groovy"
));
testing
=
true
;
}
catch
(
ClassNotFoundException
e
)
{
}
if
(
testing
)
{
testerFiles
.
add
(
locateSourceFromUrl
(
"tester"
,
"testers/tester.groovy"
));
}
// Compile - Pass 2 - with appropriate testers added in
files
=
getFileArguments
(
nonOptionArguments
,
testerFiles
);
sources
=
this
.
compiler
.
sources
(
files
);
if
(
sources
.
length
==
0
)
{
throw
new
RuntimeException
(
"No classes found in '"
+
files
+
"'"
);
}
List
<
Class
<?>>
testers
=
new
ArrayList
<
Class
<?>>();
// Extract list of compiled classes
List
<
Class
<?>>
compiled
=
new
ArrayList
<
Class
<?>>();
for
(
Object
source
:
sources
)
{
if
(
source
.
getClass
()
==
Class
.
class
)
{
Class
<?>
sourceClass
=
(
Class
<?>)
source
;
if
(
sourceClass
.
getSuperclass
().
getName
().
equals
(
"AbstractTester"
))
{
testers
.
add
(
sourceClass
);
}
else
{
compiled
.
add
((
Class
<?>)
source
);
}
}
}
this
.
results
=
new
TestResults
();
for
(
Class
<?>
tester
:
testers
)
{
GroovyObject
obj
=
(
GroovyObject
)
tester
.
newInstance
();
this
.
results
.
add
((
TestResults
)
obj
.
invokeMethod
(
"findAndTest"
,
compiled
));
}
printReport
(
this
.
results
);
}
private
File
locateSourceFromUrl
(
String
name
,
String
path
)
{
try
{
File
file
=
File
.
createTempFile
(
name
,
".groovy"
);
file
.
deleteOnExit
();
FileUtil
.
copy
(
getClass
().
getClassLoader
().
getResourceAsStream
(
path
),
file
,
null
);
return
file
;
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Could not create temp file for source: "
+
name
);
}
}
private
Class
<?>
check
(
String
className
,
Object
[]
sources
)
throws
ClassNotFoundException
{
Class
<?>
classToReturn
=
null
;
ClassNotFoundException
classNotFoundException
=
null
;
for
(
Object
source
:
sources
)
{
try
{
classToReturn
=
((
Class
<?>)
source
).
getClassLoader
().
loadClass
(
className
);
}
catch
(
ClassNotFoundException
e
)
{
classNotFoundException
=
e
;
}
}
if
(
classToReturn
!=
null
)
{
return
classToReturn
;
}
throw
classNotFoundException
;
}
private
File
[]
getFileArguments
(
List
<?>
nonOptionArguments
,
Set
<
File
>
testerFiles
)
{
List
<
File
>
files
=
new
ArrayList
<
File
>();
for
(
Object
option
:
nonOptionArguments
)
{
if
(
option
instanceof
String
)
{
String
filename
=
(
String
)
option
;
if
(
"--"
.
equals
(
filename
))
{
break
;
}
if
(
filename
.
endsWith
(
".groovy"
)
||
filename
.
endsWith
(
".java"
))
{
File
file
=
new
File
(
filename
);
if
(
file
.
isFile
()
&&
file
.
canRead
())
{
files
.
add
(
file
);
}
else
{
URL
url
=
getClass
().
getClassLoader
().
getResource
(
filename
);
if
(
url
!=
null
)
{
if
(
url
.
toString
().
startsWith
(
"file:"
))
{
files
.
add
(
new
File
(
url
.
toString
().
substring
(
"file:"
.
length
())));
}
}
else
{
throw
new
RuntimeException
(
"Can't find "
+
filename
);
}
}
}
}
}
if
(
files
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"Please specify a file to run"
);
}
for
(
File
testerFile
:
testerFiles
)
{
files
.
add
(
testerFile
);
}
return
files
.
toArray
(
new
File
[
files
.
size
()]);
}
private
void
printReport
(
TestResults
results
)
throws
FileNotFoundException
{
PrintWriter
writer
=
new
PrintWriter
(
"results.txt"
);
String
header
=
"Total: "
+
results
.
getRunCount
()
+
", Success: "
+
(
results
.
getRunCount
()
-
results
.
getFailureCount
())
+
", : Failures: "
+
results
.
getFailureCount
()
+
"\n"
+
"Passed? "
+
results
.
wasSuccessful
();
String
trailer
=
""
;
String
trace
=
""
;
for
(
Failure
failure
:
results
.
getFailures
())
{
trailer
+=
failure
.
getDescription
().
toString
();
trace
+=
failure
.
getTrace
()
+
"\n"
;
}
writer
.
println
(
header
);
writer
.
println
(
trace
);
writer
.
close
();
Log
.
info
(
header
);
Log
.
info
(
trailer
);
}
}
}
spring-boot-cli/src/main/resources/META-INF/springcli.properties
deleted
100644 → 0
View file @
1ce13cc2
groovy.version
:
${groovy.version}
hamcrest.version
:
${hamcrest.version}
jetty.version
:
${jetty.version}
junit.version
:
${junit.version}
reactor.version
:
${reactor.version}
spock.version
:
${spock.version}
spring.version
:
${spring.version}
spring-batch.version
:
${spring-batch.version}
spring-boot.version
:
${project.version}
spring-rabbit.version
:
${spring-rabbit.version}
spring-security.version
:
${spring-security.version}
spring-integration.version
:
${spring-integration.version}
spring-integration-groovydsl.version
:
${spring-integration-groovydsl.version}
tomcat.version
:
${tomcat.version}
spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java
View file @
b5f0f971
...
...
@@ -29,97 +29,98 @@ import static org.junit.Assert.assertTrue;
/**
* Integration tests to exercise the CLI's test command.
*
*
* @author Greg Turnquist
*/
public
class
TestCommandIntegrationTests
{
@BeforeClass
public
static
void
cleanGrapes
()
throws
Exception
{
GrapesCleaner
.
cleanIfNecessary
();
// System.setProperty("ivy.message.logger.level", "3");
}
@BeforeClass
public
static
void
cleanGrapes
()
throws
Exception
{
GrapesCleaner
.
cleanIfNecessary
();
// System.setProperty("ivy.message.logger.level", "3");
}
@Before
public
void
setup
()
throws
Exception
{
System
.
setProperty
(
"disableSpringSnapshotRepos"
,
"true"
);
new
CleanCommand
().
run
(
"org.springframework"
);
}
@Before
public
void
setup
()
throws
Exception
{
System
.
setProperty
(
"disableSpringSnapshotRepos"
,
"true"
);
new
CleanCommand
().
run
(
"org.springframework"
);
}
@After
public
void
teardown
()
{
System
.
clearProperty
(
"disableSpringSnapshotRepos"
);
}
@After
public
void
teardown
()
{
System
.
clearProperty
(
"disableSpringSnapshotRepos"
);
}
@Test
public
void
noTests
()
throws
Throwable
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscript
s/book.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
0
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
noTests
()
throws
Throwable
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"sample
s/book.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
0
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
empty
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscript
s/empty.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
0
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
empty
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"sample
s/empty.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
0
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
(
expected
=
RuntimeException
.
class
)
public
void
noFile
()
throws
Exception
{
try
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscripts/nothing.groovy"
);
}
catch
(
RuntimeException
e
)
{
assertEquals
(
"Can't find testscripts/nothing.groovy"
,
e
.
getMessage
());
throw
e
;
}
}
@Test
(
expected
=
RuntimeException
.
class
)
public
void
noFile
()
throws
Exception
{
try
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"samples/nothing.groovy"
);
}
catch
(
RuntimeException
e
)
{
assertEquals
(
"Can't find samples/nothing.groovy"
,
e
.
getMessage
());
throw
e
;
}
}
@Test
public
void
appAndTestsInOneFile
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscript
s/book_and_tests.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
1
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
appAndTestsInOneFile
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"sample
s/book_and_tests.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
1
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
appInOneFileTestsInAnotherFile
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscripts/book.groovy"
,
"testscript
s/test.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
1
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
appInOneFileTestsInAnotherFile
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"samples/book.groovy"
,
"sample
s/test.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
1
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
spockTester
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscript
s/spock.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
1
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
spockTester
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"sample
s/spock.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
1
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
spockAndJunitTester
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"testscripts/spock.groovy"
,
"testscript
s/book_and_tests.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
2
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
@Test
public
void
spockAndJunitTester
()
throws
Exception
{
TestCommand
command
=
new
TestCommand
();
command
.
run
(
"samples/spock.groovy"
,
"sample
s/book_and_tests.groovy"
);
TestResults
results
=
command
.
getResults
();
assertEquals
(
2
,
results
.
getRunCount
());
assertEquals
(
0
,
results
.
getFailureCount
());
assertTrue
(
results
.
wasSuccessful
());
}
}
spring-boot-cli/src/test/resources/commands/handler.groovy
View file @
b5f0f971
package
org.test.command
import
joptsimple.OptionSet
@Grab
(
"org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r"
)
import
org.eclipse.jgit.api.Git
@Grab
(
"org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r"
)
@Grab
(
"org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r"
)
@Grab
(
"org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r"
)
@Grab
(
"org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r"
)
@Grab
(
"org.eclipse.jgit:org.eclipse.jgit:2.3.1.201302201838-r"
)
import
java.lang.Object
class
TestCommand
extends
OptionHandler
{
void
options
()
{
...
...
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