linter: Migrate fixnum-related tests to be reflective

Change-Id: I2dbe12c2d2c66d08a2439a37c112cd08e5414204
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/325902
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Auto-Submit: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/linter/test/rule_test_support.dart b/pkg/linter/test/rule_test_support.dart
index 653907c..4f1359a 100644
--- a/pkg/linter/test/rule_test_support.dart
+++ b/pkg/linter/test/rule_test_support.dart
@@ -159,6 +159,8 @@
 class PubPackageResolutionTest extends _ContextResolutionTest {
   final List<String> _lintRules = const [];
 
+  bool get addFixnumPackageDep => false;
+
   bool get addFlutterPackageDep => false;
 
   bool get addJsPackageDep => false;
@@ -384,6 +386,14 @@
       languageVersion: testPackageLanguageVersion,
     );
 
+    if (addFixnumPackageDep) {
+      var fixnumPath = '/packages/fixnum';
+      addFixnumPackageFiles(
+        getFolder(fixnumPath),
+      );
+      configCopy.add(name: 'fixnum', rootPath: fixnumPath);
+    }
+
     if (addFlutterPackageDep) {
       var flutterPath = '/packages/flutter';
       addFlutterPackageFiles(
@@ -447,6 +457,18 @@
     return [...listener.errors];
   }
 
+  /// Creates a fake 'fixnum' package that can be used by tests.
+  static void addFixnumPackageFiles(Folder rootFolder) {
+    var libFolder = rootFolder.getChildAssumingFolder('lib');
+    libFolder.getChildAssumingFile('fixnum.dart').writeAsStringSync(r'''
+library fixnum;
+
+class Int32 {}
+
+class Int64 {}
+''');
+  }
+
   /// Create a fake 'flutter' package that can be used by tests.
   static void addFlutterPackageFiles(Folder rootFolder) {
     var libFolder = rootFolder.getChildAssumingFolder('lib');
diff --git a/pkg/linter/test/rules/unrelated_type_equality_checks_test.dart b/pkg/linter/test/rules/unrelated_type_equality_checks_test.dart
index 93404cb..f70f829 100644
--- a/pkg/linter/test/rules/unrelated_type_equality_checks_test.dart
+++ b/pkg/linter/test/rules/unrelated_type_equality_checks_test.dart
@@ -15,6 +15,9 @@
 @reflectiveTest
 class UnrelatedTypeEqualityChecksTest extends LintRuleTest {
   @override
+  bool get addFixnumPackageDep => true;
+
+  @override
   String get lintRule => 'unrelated_type_equality_checks';
 
   test_assignment_ok() async {
@@ -26,6 +29,50 @@
 ''');
   }
 
+  test_fixnum_int32_leftSide() async {
+    await assertNoDiagnostics(r'''
+import 'package:fixnum/fixnum.dart';
+
+void f(Int32 p) {
+  if (p == 0) {}
+}
+''');
+  }
+
+  test_fixnum_int32_rightSide() async {
+    await assertDiagnostics(r'''
+import 'package:fixnum/fixnum.dart';
+
+void f(Int32 p) {
+  if (0 == p) {}
+}
+''', [
+      lint(64, 2),
+    ]);
+  }
+
+  test_fixnum_int64_leftSide() async {
+    await assertNoDiagnostics(r'''
+import 'package:fixnum/fixnum.dart';
+
+void f(Int64 p) {
+  if (p == 0) {}
+}
+''');
+  }
+
+  test_fixnum_int64_rightSide() async {
+    await assertDiagnostics(r'''
+import 'package:fixnum/fixnum.dart';
+
+void f(Int64 p) {
+  if (0 == p) {}
+}
+''', [
+      lint(64, 2),
+    ]);
+  }
+
   test_recordAndInterfaceType_unrelated() async {
     await assertDiagnostics(r'''
 bool f((int, int) a, String b) => a == b;
diff --git a/pkg/linter/test_data/mock_packages/fixnum/lib/fixnum.dart b/pkg/linter/test_data/mock_packages/fixnum/lib/fixnum.dart
deleted file mode 100644
index 7b41c95..0000000
--- a/pkg/linter/test_data/mock_packages/fixnum/lib/fixnum.dart
+++ /dev/null
@@ -1,5 +0,0 @@
-library fixnum;
-
-class Int32 {}
-
-class Int64 {}
diff --git a/pkg/linter/test_data/mock_packages/fixnum/pubspec.yaml b/pkg/linter/test_data/mock_packages/fixnum/pubspec.yaml
deleted file mode 100644
index 3c5f856..0000000
--- a/pkg/linter/test_data/mock_packages/fixnum/pubspec.yaml
+++ /dev/null
@@ -1,4 +0,0 @@
-name: fixnum
-
-environment:
-  sdk: '>=2.2.2 <3.0.0'
diff --git a/pkg/linter/test_data/rules/.dart_tool/package_config.json b/pkg/linter/test_data/rules/.dart_tool/package_config.json
index feb30da..9d5fbe5 100644
--- a/pkg/linter/test_data/rules/.dart_tool/package_config.json
+++ b/pkg/linter/test_data/rules/.dart_tool/package_config.json
@@ -2,12 +2,6 @@
   "configVersion": 2,
   "packages": [
     {
-      "name": "fixnum",
-      "rootUri": "../../mock_packages/fixnum/",
-      "packageUri": "lib/",
-      "languageVersion": "2.17"
-    },
-    {
       "name": "flutter",
       "rootUri": "../../mock_packages/flutter/",
       "packageUri": "lib/",
diff --git a/pkg/linter/test_data/rules/unrelated_type_equality_checks.dart b/pkg/linter/test_data/rules/unrelated_type_equality_checks.dart
index c0dfdc5..2eeeef0 100644
--- a/pkg/linter/test_data/rules/unrelated_type_equality_checks.dart
+++ b/pkg/linter/test_data/rules/unrelated_type_equality_checks.dart
@@ -4,8 +4,6 @@
 
 // test w/ `dart test -N unrelated_type_equality_checks`
 
-import 'package:fixnum/fixnum.dart';
-
 void someFunction() {
   var x = '1';
   if (x == 1) print('someFunction'); // LINT
@@ -98,30 +96,6 @@
   if (other == instance) print('someFunction15'); // LINT
 }
 
-void someFunction15() {
-  var x = new Int32();
-
-  if (x == 0) print('someFunction15'); // OK
-}
-
-void someFunction16() {
-  var x = new Int32();
-
-  if (0 == x) print('someFunction16'); // LINT
-}
-
-void someFunction17() {
-  var x = new Int64();
-
-  if (x == 0) print('someFunction17'); // OK
-}
-
-void someFunction18() {
-  var x = new Int64();
-
-  if (0 == x) print('someFunction18'); // LINT
-}
-
 void someFunction19<A, B>(A a, B b) {
   if (a == b) print('someFunction19'); // OK
   if (<A>[a] == <B>[b]) print('someFunction19'); // OK