summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-11-28 10:05:30 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-03-25 12:28:50 +0100
commit69bb186dc5b1962be317bf5ee88077c7fac35214 (patch)
treeb72b926a1297367e7b268dab43603323da7dc2cb
parent0c1eaeabd1067480eba617fd249d8846afa11afb (diff)
downloadvala-69bb186dc5b1962be317bf5ee88077c7fac35214.tar.gz
tests: Add "throw in loops" tests to increase coverage
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/errors/loops.vala119
2 files changed, 120 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c19df41e4..0eaa2376a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -490,6 +490,7 @@ TESTS = \
errors/errordomain-instance-method.test \
errors/errordomain-static-method.vala \
errors/invalid-type-check.test \
+ errors/loops.vala \
errors/method-throws.vala \
errors/bug567181.vala \
errors/bug579101.vala \
diff --git a/tests/errors/loops.vala b/tests/errors/loops.vala
new file mode 100644
index 000000000..552865224
--- /dev/null
+++ b/tests/errors/loops.vala
@@ -0,0 +1,119 @@
+errordomain FooError {
+ FAIL
+}
+
+string[] get_array () throws Error {
+ throw new FooError.FAIL ("foo");
+}
+
+bool get_bool () throws Error {
+ throw new FooError.FAIL ("foo");
+}
+
+int get_int () throws Error {
+ throw new FooError.FAIL ("foo");
+}
+
+void error_in_for () {
+ try {
+ for (var i = get_int (); i < 2; i++) {
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+
+ try {
+ for (var i = 0; get_bool (); i++) {
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+
+ try {
+ bool reached = false;
+ for (var i = 0; i < 2; i += get_int ()) {
+ if (reached) {
+ assert_not_reached ();
+ } else {
+ reached = true;
+ }
+ }
+ assert_not_reached ();
+ } catch {
+ }
+
+ try {
+ for (var i = 0; i < 2; i++) {
+ throw new FooError.FAIL ("foo");
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+}
+
+void error_in_foreach () {
+ try {
+ foreach (var s in get_array ()) {
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+
+ try {
+ string[] array = { "bar" };
+ foreach (var s in array) {
+ throw new FooError.FAIL ("foo");
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+}
+
+void error_in_do () {
+ try {
+ do {
+ } while (get_bool ());
+ assert_not_reached ();
+ } catch {
+ }
+
+ try {
+ do {
+ throw new FooError.FAIL ("foo");
+ assert_not_reached ();
+ } while (true);
+ assert_not_reached ();
+ } catch {
+ }
+}
+
+void error_in_while () {
+ try {
+ while (get_bool ()) {
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+
+ try {
+ while (true) {
+ throw new FooError.FAIL ("foo");
+ assert_not_reached ();
+ }
+ assert_not_reached ();
+ } catch {
+ }
+}
+
+void main () {
+ error_in_for ();
+ error_in_foreach ();
+ error_in_do ();
+ error_in_while ();
+}