unit tests: external deps are added to pc files only if found

https://github.com/mesonbuild/meson/issues/2911 was broken after 0.44,
but we add this test here anyway to ensure it doesn't break
accidentally.
diff --git a/run_unittests.py b/run_unittests.py
index c2babfb..3240381 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -455,6 +455,7 @@
         # In case the directory is inside a symlinked directory, find the real
         # path otherwise we might not find the srcdir from inside the builddir.
         self.builddir = os.path.realpath(tempfile.mkdtemp())
+        self.privatedir = os.path.join(self.builddir, 'meson-private')
         self.logdir = os.path.join(self.builddir, 'meson-logs')
         self.prefix = '/usr'
         self.libdir = os.path.join(self.prefix, 'lib')
@@ -1974,6 +1975,12 @@
         self.assertEqual(foo_dep.get_pkgconfig_variable('foo', {}), 'bar')
         self.assertPathEqual(foo_dep.get_pkgconfig_variable('datadir', {}), '/usr/data')
 
+    def test_pkg_unfound(self):
+        testdir = os.path.join(self.unit_test_dir, '22 unfound pkgconfig')
+        self.init(testdir)
+        pcfile = open(os.path.join(self.privatedir, 'somename.pc')).read()
+        self.assertFalse('blub_blob_blib' in pcfile)
+
     def test_vala_c_warnings(self):
         '''
         Test that no warnings are emitted for C code generated by Vala. This
diff --git a/test cases/unit/22 unfound pkgconfig/meson.build b/test cases/unit/22 unfound pkgconfig/meson.build
new file mode 100644
index 0000000..1285c0a
--- /dev/null
+++ b/test cases/unit/22 unfound pkgconfig/meson.build
@@ -0,0 +1,15 @@
+project('foobar', 'c')
+
+unfound = dependency('blub_blob_blib', required : false)
+
+pkgg = import('pkgconfig')
+
+l = shared_library('somename', 'some.c',
+  dependencies : unfound)
+
+pkgg.generate(
+  libraries : l,
+  name : 'somename',
+  version : '1.0.0',
+  description : 'A test library.',
+)
diff --git a/test cases/unit/22 unfound pkgconfig/some.c b/test cases/unit/22 unfound pkgconfig/some.c
new file mode 100644
index 0000000..fb765fb
--- /dev/null
+++ b/test cases/unit/22 unfound pkgconfig/some.c
@@ -0,0 +1,3 @@
+int some() {
+    return 6;
+}