Fix analysis script to run from anywhere (#86683)

Fixes a small problem with the analyze.dart script that fixes it so that it can be invoked from any directory, not just the Flutter root.
diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart
index e24c1fd5..0b1de1a 100644
--- a/dev/bots/analyze.dart
+++ b/dev/bots/analyze.dart
@@ -70,7 +70,7 @@
   await verifyNoBadImportsInFlutterTools(flutterRoot);
 
   print('$clock Internationalization...');
-  await verifyInternationalizations();
+  await verifyInternationalizations(flutterRoot, dart);
 
   print('$clock Integration test timeouts...');
   await verifyIntegrationTestTimeouts(flutterRoot);
@@ -422,26 +422,26 @@
   }
 }
 
-Future<void> verifyInternationalizations() async {
+Future<void> verifyInternationalizations(String workingDirectory, String dartExecutable) async {
   final EvalResult materialGenResult = await _evalCommand(
-    dart,
+    dartExecutable,
     <String>[
       path.join('dev', 'tools', 'localization', 'bin', 'gen_localizations.dart'),
       '--material',
     ],
-    workingDirectory: flutterRoot,
+    workingDirectory: workingDirectory,
   );
   final EvalResult cupertinoGenResult = await _evalCommand(
-    dart,
+    dartExecutable,
     <String>[
       path.join('dev', 'tools', 'localization', 'bin', 'gen_localizations.dart'),
       '--cupertino',
     ],
-    workingDirectory: flutterRoot,
+    workingDirectory: workingDirectory,
   );
 
-  final String materialLocalizationsFile = path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'generated_material_localizations.dart');
-  final String cupertinoLocalizationsFile = path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'generated_cupertino_localizations.dart');
+  final String materialLocalizationsFile = path.join(workingDirectory, 'packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'generated_material_localizations.dart');
+  final String cupertinoLocalizationsFile = path.join(workingDirectory, 'packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'generated_cupertino_localizations.dart');
   final String expectedMaterialResult = await File(materialLocalizationsFile).readAsString();
   final String expectedCupertinoResult = await File(cupertinoLocalizationsFile).readAsString();
 
diff --git a/dev/bots/test/analyze-test-input/root/dev/tools/localization/bin/gen_localizations.dart b/dev/bots/test/analyze-test-input/root/dev/tools/localization/bin/gen_localizations.dart
new file mode 100644
index 0000000..8505054
--- /dev/null
+++ b/dev/bots/test/analyze-test-input/root/dev/tools/localization/bin/gen_localizations.dart
@@ -0,0 +1,22 @@
+// Copyright 2014 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+void main(List<String> args) {
+  String type = '';
+  if (args[0] == '--material') {
+    type = 'material';
+  }
+  if (args[0] == '--cupertino') {
+    type = 'cupertino';
+  }
+  print('''
+// Copyright 2014 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+void main(List<String> args) {
+  print('Expected output $type');
+}
+''');
+}
diff --git a/dev/bots/test/analyze-test-input/root/packages/flutter_localizations/lib/src/l10n/generated_cupertino_localizations.dart b/dev/bots/test/analyze-test-input/root/packages/flutter_localizations/lib/src/l10n/generated_cupertino_localizations.dart
new file mode 100644
index 0000000..ee328ba
--- /dev/null
+++ b/dev/bots/test/analyze-test-input/root/packages/flutter_localizations/lib/src/l10n/generated_cupertino_localizations.dart
@@ -0,0 +1,7 @@
+// Copyright 2014 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+void main(List<String> args) {
+  print('Unexpected output cupertino');
+}
diff --git a/dev/bots/test/analyze-test-input/root/packages/flutter_localizations/lib/src/l10n/generated_material_localizations.dart b/dev/bots/test/analyze-test-input/root/packages/flutter_localizations/lib/src/l10n/generated_material_localizations.dart
new file mode 100644
index 0000000..db40bf2
--- /dev/null
+++ b/dev/bots/test/analyze-test-input/root/packages/flutter_localizations/lib/src/l10n/generated_material_localizations.dart
@@ -0,0 +1,7 @@
+// Copyright 2014 The Flutter Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+void main(List<String> args) {
+  print('Unexpected output material');
+}
diff --git a/dev/bots/test/analyze_test.dart b/dev/bots/test/analyze_test.dart
index 1bffc6c..2dc53d4 100644
--- a/dev/bots/test/analyze_test.dart
+++ b/dev/bots/test/analyze_test.dart
@@ -38,6 +38,8 @@
 
 void main() {
   final String testRootPath = path.join('test', 'analyze-test-input', 'root');
+  final String dartName = Platform.isWindows ? 'dart.exe' : 'dart';
+  final String dartPath = path.canonicalize(path.join('..', '..', 'bin', 'cache', 'dart-sdk', 'bin', dartName));
 
   test('analyze.dart - verifyDeprecations', () async {
     final String result = await capture(() => verifyDeprecations(testRootPath, minimumMatches: 2), exitCode: 1);
@@ -124,6 +126,21 @@
     }
   });
 
+  test('analyze.dart - verifyInternationalizations - comparison fails', () async {
+    final String result = await capture(() => verifyInternationalizations(testRootPath, dartPath), exitCode: 1);
+    final String genLocalizationsScript = path.join('dev', 'tools', 'localization', 'bin', 'gen_localizations.dart');
+    expect(result,
+        contains('$dartName $genLocalizationsScript --cupertino'));
+    expect(result,
+        contains('$dartName $genLocalizationsScript --material'));
+    final String generatedFile = path.join(testRootPath, 'packages', 'flutter_localizations',
+        'lib', 'src', 'l10n', 'generated_material_localizations.dart');
+    expect(result,
+        contains('The contents of $generatedFile are different from that produced by gen_localizations.'));
+    expect(result,
+        contains(r'Did you forget to run gen_localizations.dart after updating a .arb file?'));
+  });
+
   test('analyze.dart - verifyNoBinaries - negative', () async {
     await capture(() => verifyNoBinaries(
       testRootPath,