Test terminal can set dimensions

- ShellTest now has fields which can be used to
  change terminal default widht/height.
- Backed by properties so can be used with
  `spring.shell.test.terminal-width` and
  `spring.shell.test.terminal-height`.
- Backport #656
- Fixes #659
This commit is contained in:
Janne Valkealahti
2023-02-05 15:24:36 +00:00
parent 3ed49d1bd6
commit edfe67c00d
10 changed files with 234 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
[[using-shell-testing-basics]]
==== Basics
=== Basics
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Spring Shell provides a number of utilities and annotations to help when testing your application.

View File

@@ -0,0 +1,27 @@
[[using-shell-testing-settings]]
=== Settings
ifndef::snippets[:snippets: ../../test/java/org/springframework/shell/docs]
Built in emulation uses terminal width 80 and height 24 on default.
Changing dimensions is useful if output would span into multiple
lines and you don't want to handle those cases in a tests.
These can be changed using properties `spring.shell.test.terminal-width`
or `spring.shell.test.terminal-height`.
====
[source, java, indent=0]
----
include::{snippets}/TestingSnippets.java[tag=testing-shelltest-dimensions-props]
----
====
`ShellTest` annotation have fields `terminalWidth` and `terminalHeight`
which can also be used to change dimensions.
====
[source, java, indent=0]
----
include::{snippets}/TestingSnippets.java[tag=testing-shelltest-dimensions-field]
----
====

View File

@@ -16,3 +16,5 @@ NOTE: Testing support is currently under development and will be
unstable for various parts.
include::using-shell-testing-basics.adoc[]
include::using-shell-testing-settings.adoc[]

View File

@@ -81,4 +81,23 @@ class TestingSnippets {
}
}
// end::testing-shelltest-noninteractive[]
class Dump1 {
// tag::testing-shelltest-dimensions-props[]
@ShellTest(properties = {
"spring.shell.test.terminal-width=120",
"spring.shell.test.terminal-height=40"
})
class ShellSettingsSample {}
// end::testing-shelltest-dimensions-props[]
}
class Dump2 {
// tag::testing-shelltest-dimensions-field[]
@ShellTest(terminalWidth = 120, terminalHeight = 40)
class ShellSettingsSample {}
// end::testing-shelltest-dimensions-field[]
}
}