Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve testing of the 'dart fix' data #166

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ analyzer:
# necessary
camel_case_types: ignore
non_constant_identifier_names: ignore
# Consider removing from dart_flutter_team_lints.
unreachable_from_main: ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this lint. How'd you hit it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the test_fixes/renames.dart file (which to be honest isn't really intended to be best practice dart code). From memory, I've also hit it a few other times where it was false positives.


linter:
rules:
Expand Down
117 changes: 0 additions & 117 deletions lib/fix_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ transforms:
changes:
- kind: 'rename'
newName: 'HTMLBaseElement'
# BluetoothRemoteGattDescriptor => BluetoothRemoteGATTDescriptor
- title: "Rename to 'BluetoothRemoteGATTDescriptor'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'BluetoothRemoteGattDescriptor'
changes:
- kind: 'rename'
newName: 'BluetoothRemoteGATTDescriptor'
# BodyElement => HTMLBodyElement
- title: "Rename to 'HTMLBodyElement'"
date: 2024-01-12
Expand Down Expand Up @@ -98,15 +89,6 @@ transforms:
changes:
- kind: 'rename'
newName: 'CDATASection'
# Css => CSS
- title: "Rename to 'CSS'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'Css'
changes:
- kind: 'rename'
newName: 'CSS'
# CssConditionRule => CSSConditionRule
- title: "Rename to 'CSSConditionRule'"
date: 2024-01-12
Expand Down Expand Up @@ -647,15 +629,6 @@ transforms:
changes:
- kind: 'rename'
newName: 'HTMLHtmlElement'
# HtmlHyperlinkElementUtils => HTMLHyperlinkElementUtils
- title: "Rename to 'HTMLHyperlinkElementUtils'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'HtmlHyperlinkElementUtils'
changes:
- kind: 'rename'
newName: 'HTMLHyperlinkElementUtils'
# HtmlOptionsCollection => HTMLOptionsCollection
- title: "Rename to 'HTMLOptionsCollection'"
date: 2024-01-12
Expand Down Expand Up @@ -800,78 +773,6 @@ transforms:
changes:
- kind: 'rename'
newName: 'HTMLMeterElement'
# MidiAccess => MIDIAccess
- title: "Rename to 'MIDIAccess'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiAccess'
changes:
- kind: 'rename'
newName: 'MIDIAccess'
# MidiConnectionEvent => MIDIConnectionEvent
- title: "Rename to 'MIDIConnectionEvent'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiConnectionEvent'
changes:
- kind: 'rename'
newName: 'MIDIConnectionEvent'
# MidiInput => MIDIInput
- title: "Rename to 'MIDIInput'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiInput'
changes:
- kind: 'rename'
newName: 'MIDIInput'
# MidiInputMap => MIDIInputMap
- title: "Rename to 'MIDIInputMap'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiInputMap'
changes:
- kind: 'rename'
newName: 'MIDIInputMap'
# MidiMessageEvent => MIDIMessageEvent
- title: "Rename to 'MIDIMessageEvent'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiMessageEvent'
changes:
- kind: 'rename'
newName: 'MIDIMessageEvent'
# MidiOutput => MIDIOutput
- title: "Rename to 'MIDIOutput'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiOutput'
changes:
- kind: 'rename'
newName: 'MIDIOutput'
# MidiOutputMap => MIDIOutputMap
- title: "Rename to 'MIDIOutputMap'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiOutputMap'
changes:
- kind: 'rename'
newName: 'MIDIOutputMap'
# MidiPort => MIDIPort
- title: "Rename to 'MIDIPort'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'MidiPort'
changes:
- kind: 'rename'
newName: 'MIDIPort'
# ModElement => HTMLModElement
- title: "Rename to 'HTMLModElement'"
date: 2024-01-12
Expand Down Expand Up @@ -1277,24 +1178,6 @@ transforms:
changes:
- kind: 'rename'
newName: 'HTMLTrackElement'
# TrustedHtml => TrustedHTML
- title: "Rename to 'TrustedHTML'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'TrustedHtml'
changes:
- kind: 'rename'
newName: 'TrustedHTML'
# TrustedScriptUrl => TrustedScriptURL
- title: "Rename to 'TrustedScriptURL'"
date: 2024-01-12
element:
uris: [ 'package:web/web.dart' ]
class: 'TrustedScriptUrl'
changes:
- kind: 'rename'
newName: 'TrustedScriptURL'
# UListElement => HTMLUListElement
- title: "Rename to 'HTMLUListElement'"
date: 2024-01-12
Expand Down
101 changes: 101 additions & 0 deletions test/dart_fix_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';

// Used for debugging the test.
const keepTempDir = false;

void main() {
test("'dart fix' integration", () {
// create temp dir
final tempDir = Directory.systemTemp.createTempSync('test');

var sdkVersion = Platform.version;
if (sdkVersion.contains(' ')) {
sdkVersion = sdkVersion.substring(0, sdkVersion.indexOf(' '));
}

try {
// set up project
writeFile(tempDir, 'pubspec.yaml', '''
name: test_project
environment:
sdk: '^$sdkVersion'
dependencies:
web:
path: ${Directory.current.path}
''');
final sourceFile = File(p.join('test_fixes', 'renames.dart'));
writeFile(
tempDir,
p.join('lib', sourceFile.name),
sourceFile.readAsStringSync(),
);

// run pub get
pubGet(tempDir);

// dart fix
dartFix(tempDir);

// verify no analysis issues
dartAnalyze(tempDir);
} finally {
// ignore: dead_code
if (keepTempDir) {
print('dart fix test temp dir: ${tempDir.path}');
} else {
tempDir.deleteSync(recursive: true);
}
}
});
}

void writeFile(Directory dir, String filePath, String contents) {
final file = File(p.join(dir.path, filePath));
file.parent.createSync();
file.writeAsStringSync(contents);
}

void pubGet(Directory dir) {
exec('pub', ['get'], cwd: dir);
}

void dartFix(Directory dir) {
exec('fix', ['--apply'], cwd: dir);
}

void dartAnalyze(Directory dir) {
exec('analyze', [], cwd: dir);
}

void exec(String command, List<String> args, {required Directory cwd}) {
printOnFailure('dart $command ${args.join(', ')}');

final result = Process.runSync(
Platform.resolvedExecutable,
[command, ...args],
workingDirectory: cwd.path,
);

var out = result.stdout as String;
if (out.isNotEmpty) printOnFailure(out);
out = result.stderr as String;
if (out.isNotEmpty) printOnFailure(out);

if (result.exitCode != 0) {
fail('dart $command: exitCode ${result.exitCode}');
}
}

extension on File {
String get name => p.basename(path);
}
3 changes: 3 additions & 0 deletions test/scrape_mdn_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')
library;

import 'package:test/test.dart';

import '../tool/scrape_mdn.dart';
Expand Down
15 changes: 0 additions & 15 deletions test_fixes/renames.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: unreachable_from_main

import 'package:web/web.dart';

late AnchorElement $0;
late AreaElement $1;
late AudioElement $2;
late BaseElement $3;
late BluetoothRemoteGattDescriptor $4;
late BodyElement $5;
late BRElement $6;
late ButtonElement $7;
late CanvasElement $8;
late CDataSection $9;
late Css $10;
late CssConditionRule $11;
late CssFontFaceRule $12;
late CssGroupingRule $13;
Expand Down Expand Up @@ -77,7 +73,6 @@ late HtmlDocument $67;
late HtmlElement $68;
late HtmlFormControlsCollection $69;
late HtmlHtmlElement $70;
late HtmlHyperlinkElementUtils $71;
late HtmlOptionsCollection $72;
// late HttpRequest/XMLHttpRequest $73;
late HttpRequestEventTarget $74;
Expand All @@ -94,14 +89,6 @@ late MediaElement $84;
late MenuElement $85;
late MetaElement $86;
late MeterElement $87;
late MidiAccess $88;
late MidiConnectionEvent $89;
late MidiInput $90;
late MidiInputMap $91;
late MidiMessageEvent $92;
late MidiOutput $93;
late MidiOutputMap $94;
late MidiPort $95;
late ModElement $96;
late ObjectElement $97;
late OListElement $98;
Expand Down Expand Up @@ -147,8 +134,6 @@ late TextAreaElement $137;
late TimeElement $138;
late TitleElement $139;
late TrackElement $140;
late TrustedHtml $141;
late TrustedScriptUrl $142;
late UListElement $143;
late UnderlyingSourceBase $144;
late UnknownElement $145;
Expand Down
15 changes: 0 additions & 15 deletions test_fixes/renames.dart.expect
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// ignore_for_file: unreachable_from_main

import 'package:web/web.dart';

late HTMLAnchorElement $0;
late HTMLAreaElement $1;
late HTMLAudioElement $2;
late HTMLBaseElement $3;
late BluetoothRemoteGATTDescriptor $4;
late HTMLBodyElement $5;
late HTMLBRElement $6;
late HTMLButtonElement $7;
late HTMLCanvasElement $8;
late CDATASection $9;
late CSS $10;
late CSSConditionRule $11;
late CSSFontFaceRule $12;
late CSSGroupingRule $13;
Expand Down Expand Up @@ -77,7 +73,6 @@ late Document $67;
late HTMLElement $68;
late HTMLFormControlsCollection $69;
late HTMLHtmlElement $70;
late HTMLHyperlinkElementUtils $71;
late HTMLOptionsCollection $72;
// late HttpRequest/XMLHttpRequest $73;
late XMLHttpRequestEventTarget $74;
Expand All @@ -94,14 +89,6 @@ late HTMLMediaElement $84;
late HTMLMenuElement $85;
late HTMLMetaElement $86;
late HTMLMeterElement $87;
late MIDIAccess $88;
late MIDIConnectionEvent $89;
late MIDIInput $90;
late MIDIInputMap $91;
late MIDIMessageEvent $92;
late MIDIOutput $93;
late MIDIOutputMap $94;
late MIDIPort $95;
late HTMLModElement $96;
late HTMLObjectElement $97;
late HTMLOListElement $98;
Expand Down Expand Up @@ -147,8 +134,6 @@ late HTMLTextAreaElement $137;
late HTMLTimeElement $138;
late HTMLTitleElement $139;
late HTMLTrackElement $140;
late TrustedHTML $141;
late TrustedScriptURL $142;
late HTMLUListElement $143;
late UnderlyingSource $144;
late HTMLUnknownElement $145;
Expand Down
Loading
Loading