test: robustly resolve valid_yaml and invalid_yaml test directories
diff --git a/pkgs/yaml/test/data_driven_test.dart b/pkgs/yaml/test/data_driven_test.dart
index b9368f9..126f320 100644
--- a/pkgs/yaml/test/data_driven_test.dart
+++ b/pkgs/yaml/test/data_driven_test.dart
@@ -8,24 +8,27 @@
 
 void main() {
   group('Valid YAML', () {
-    var validDir = Directory('valid_yaml'); // run from 'test/' or package root
-    // we use relative paths safely
     var rootValidDir = Directory('test/valid_yaml');
-    if (rootValidDir.existsSync()) {
-      for (var file in rootValidDir.listSync(recursive: true).whereType<File>()) {
+    if (!rootValidDir.existsSync()) {
+      rootValidDir = Directory('valid_yaml');
+    }
+    if (!rootValidDir.existsSync()) throw StateError("valid_yaml directory not found");
+    for (var file in rootValidDir.listSync(recursive: true).whereType<File>()) {
         if (!file.path.endsWith('.yaml')) continue;
         test(file.path, () {
           var content = file.readAsStringSync();
           expect(() => loadYaml(content), returnsNormally);
         });
-      }
     }
   });
 
   group('Invalid YAML', () {
     var rootInvalidDir = Directory('test/invalid_yaml');
-    if (rootInvalidDir.existsSync()) {
-      for (var file in rootInvalidDir.listSync(recursive: true).whereType<File>()) {
+    if (!rootInvalidDir.existsSync()) {
+      rootInvalidDir = Directory('invalid_yaml');
+    }
+    if (!rootInvalidDir.existsSync()) throw StateError("invalid_yaml directory not found");
+    for (var file in rootInvalidDir.listSync(recursive: true).whereType<File>()) {
         if (!file.path.endsWith('.yaml')) continue;
         test(file.path, () {
           var content = file.readAsStringSync();
@@ -39,7 +42,6 @@
           }
           expect(err, isNotNull, reason: 'Expected a YamlException to be thrown');
         });
-      }
     }
   });
 }