From: Rico Tzschichholz Date: Tue, 27 Nov 2018 10:08:15 +0000 (+0100) Subject: tests: Add and improve "foreach iterator" tests to increase coverage X-Git-Tag: 0.43.1~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0615a4d7e74de4c9db9ab8f8ef26c5896b609846;p=thirdparty%2Fvala.git tests: Add and improve "foreach iterator" tests to increase coverage --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 3284569d7..61ad4bbb8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -559,6 +559,7 @@ TESTS = \ semantic/field-void.test \ semantic/floating-reference.vala \ semantic/foreach-iterator-args.test \ + semantic/foreach-iterator-element-owned.test \ semantic/foreach-iterator-void.test \ semantic/foreach-iterator-wrong-types.test \ semantic/foreach-missing-generic-type.test \ diff --git a/tests/semantic/foreach-iterator-element-owned.test b/tests/semantic/foreach-iterator-element-owned.test new file mode 100644 index 000000000..b647a9e2c --- /dev/null +++ b/tests/semantic/foreach-iterator-element-owned.test @@ -0,0 +1,23 @@ +Invalid Code + +public class Iterator { + public bool next () { + return true; + } + + public G get () { + return (G) null; + } +} + +public class Test { + public Iterator iterator () { + return new Iterator (); + } +} + +void main () { + Test test = null; + foreach (unowned string? t in test) { + } +} diff --git a/tests/semantic/foreach-iterator-wrong-types.test b/tests/semantic/foreach-iterator-wrong-types.test index eb4374172..e7824a81e 100644 --- a/tests/semantic/foreach-iterator-wrong-types.test +++ b/tests/semantic/foreach-iterator-wrong-types.test @@ -1,7 +1,23 @@ Invalid Code +public class Iterator { + public bool next () { + return true; + } + + public G get () { + return (G) null; + } +} + +public class Test { + public Iterator iterator () { + return new Iterator (); + } +} + void main () { - var test = new GLib.List (); - foreach (string t in test) { + Test test = null; + foreach (int t in test) { } }