-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from Workiva/UIP-1638_strong_transformer/dev
UIP-1638: Make transformer output strong mode compliant Closes #14
- Loading branch information
Showing
11 changed files
with
229 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
@TestOn('vm') | ||
library over_react.strong_mode; | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:dart_dev/util.dart' show copyDirectory; | ||
import 'package:test/test.dart'; | ||
|
||
const String strongModeProject = 'test_fixtures/strong_mode'; | ||
|
||
/// Runs the dart analzyer task for the given project. | ||
Future<ProcessResult> analyzeProject(String projectPath) async { | ||
// Won't work unless all files are listed, for some reason. | ||
var files = <String>[] | ||
..addAll(new Directory(projectPath).listSync() | ||
.where((e) => FileSystemEntity.isFileSync(e.path) && e.path.endsWith('.dart')) | ||
.map((e) => e.path) | ||
); | ||
|
||
var args = ['--strong'] | ||
..addAll(files); | ||
|
||
return await Process.run('dartanalyzer', args); | ||
} | ||
|
||
// Returns the path to a new temporary copy of the [project] fixture | ||
// testing purposes, necessary since formatter may make changes to ill-formatted files. | ||
String copyProject(String project) { | ||
final String testProject = '${project}_temp'; | ||
|
||
final Directory temp = new Directory(testProject); | ||
copyDirectory(new Directory(project), temp); | ||
addTearDown(() { | ||
// Clean up the temporary test project created for this test case. | ||
temp.deleteSync(recursive: true); | ||
}); | ||
|
||
return testProject; | ||
} | ||
|
||
String getPubspec() { | ||
var lines = <String>[ | ||
'# Generated by strong_mode_test.dart', | ||
'name: test_fixture', | ||
'version: 0.0.0', | ||
'dependencies:', | ||
' over_react:', | ||
' path: ../..' | ||
]; | ||
|
||
return lines.join('\n'); | ||
} | ||
|
||
main() { | ||
group('OverReact strong mode compliance:', () { | ||
test('generates strong mode compliant code', () async { | ||
var testProject = copyProject(strongModeProject); | ||
|
||
new File('$testProject/pubspec.yaml').writeAsStringSync(getPubspec()); | ||
|
||
expect(await Process.run('pub', ['get'], workingDirectory: testProject), succeeded); | ||
expect(await Process.run('pub', ['build', '--mode="debug"'], workingDirectory: testProject), succeeded); | ||
|
||
expect(await analyzeProject('$testProject/build/web'), succeeded); | ||
}); | ||
}); | ||
} | ||
|
||
class _ProcessSucceededMatcher extends Matcher { | ||
const _ProcessSucceededMatcher(); | ||
|
||
@override | ||
Description describe(Description description) => | ||
description.add('a ProcessResult that completed successfully'); | ||
|
||
@override | ||
bool matches(covariant ProcessResult item, _) => | ||
item.exitCode == 0; | ||
|
||
@override | ||
Description describeMismatch(covariant ProcessResult item, Description mismatchDescription, _, __) => | ||
mismatchDescription.add('has exit code ${item.exitCode} and output ${{ | ||
'stdout': item.stdout.toString(), | ||
'stderr': item.stderr.toString(), | ||
}}'); | ||
} | ||
|
||
const _ProcessSucceededMatcher succeeded = const _ProcessSucceededMatcher(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import 'package:over_react/over_react.dart'; | ||
|
||
@AbstractProps() | ||
abstract class AbstractStatelessProps extends UiProps {} | ||
|
||
@AbstractComponent() | ||
abstract class AbstractStatelessComponent<T extends AbstractStatelessProps> extends UiComponent<T> { | ||
@override | ||
render() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:over_react/over_react.dart'; | ||
|
||
@Factory() | ||
UiFactory<GenericStatefulProps> GenericStateful; | ||
|
||
@Props() | ||
class GenericStatefulProps extends UiProps {} | ||
|
||
@State() | ||
class GenericStatefulState extends UiState {} | ||
|
||
@Component() | ||
class GenericStatefulComponent<T extends GenericStatefulProps, S extends GenericStatefulState> extends UiStatefulComponent<T, S> { | ||
@override | ||
render() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:over_react/over_react.dart'; | ||
|
||
@Factory() | ||
UiFactory<StatefulProps> Stateful; | ||
|
||
@Props() | ||
class StatefulProps extends UiProps {} | ||
|
||
@State() | ||
class StatefulState extends UiState {} | ||
|
||
@Component() | ||
class StatefulComponent extends UiStatefulComponent<StatefulProps, StatefulState> { | ||
@override | ||
render() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:over_react/over_react.dart'; | ||
|
||
@Factory() | ||
UiFactory<StatelessProps> Stateless; | ||
|
||
@Props() | ||
class StatelessProps extends UiProps {} | ||
|
||
@Component() | ||
class StatelessComponent extends UiComponent<StatelessProps> { | ||
@override | ||
render() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters