Skip to content

Commit 945a27c

Browse files
committed
@ F maybe must split to flutter impl
1 parent 1c8219d commit 945a27c

File tree

85 files changed

+1838
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1838
-110
lines changed

bin/review.dart

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// ignore_for_file: avoid_print
2+
3+
import 'dart:io';
4+
5+
import 'package:approval_tests/src/widget/src/common.dart';
6+
import 'package:approval_tests/src/widget/src/git_diffs.dart';
7+
8+
void main() async {
9+
final searchDirectory = Directory.current;
10+
11+
final List<Future<void>> tasks = [];
12+
13+
/// Recursively search for current files
14+
await for (final file in searchDirectory.list(recursive: true)) {
15+
if (file.path.endsWith('.unapproved.txt')) {
16+
final reviewFile = file;
17+
final approvedFileName = file.path.replaceAll('.unapproved.txt', '.approved.txt');
18+
final approvedFile = File(approvedFileName);
19+
20+
if (approvedFile.existsSync()) {
21+
tasks.add(processFile(approvedFile, reviewFile));
22+
}
23+
}
24+
}
25+
26+
await Future.wait(tasks);
27+
28+
print('Review process completed.');
29+
}
30+
31+
/// Check of the files are different using "git diff"
32+
Future<void> processFile(File approvedFile, FileSystemEntity reviewFile) async {
33+
final resultString = gitDiffFiles(approvedFile, reviewFile);
34+
35+
if (resultString.isNotEmpty || resultString.isNotEmpty) {
36+
final String fileNameWithoutExtension = approvedFile.path.split('/').last.split('.').first;
37+
printGitDiffs(fileNameWithoutExtension, resultString);
38+
39+
String? firstCharacter;
40+
41+
do {
42+
stdout.write('Accept changes? (y/N/[v]iew): ');
43+
final response = stdin.readLineSync()?.trim().toLowerCase();
44+
45+
if (response == null || response.isEmpty) {
46+
firstCharacter = null;
47+
} else {
48+
firstCharacter = response[0];
49+
}
50+
51+
if (firstCharacter == 'y') {
52+
await approvedFile.delete();
53+
await reviewFile.rename(approvedFile.path);
54+
print('Approval test approved');
55+
} else if (firstCharacter == 'v') {
56+
if (isCodeCommandAvailable()) {
57+
final approvedFilename = approvedFile.path;
58+
final reviewFilename = reviewFile.path;
59+
60+
print("Executing 'code --diff $approvedFilename $reviewFilename'");
61+
final processResult = Process.runSync('code', ['--diff', approvedFilename, reviewFilename]);
62+
print('processResult: ${processResult.toString()}');
63+
} else {
64+
print('''
65+
$topBar
66+
To enable the 'v' command, your system must be configured to run VSCode from the command line:
67+
0. Install VSCode (if you haven't already)
68+
1. Open Visual Studio Code.
69+
2. Open the Command Palette by pressing Cmd + Shift + P.
70+
3. Type ‘Shell Command’ into the Command Palette and look for the option ‘Install ‘code’ command in PATH’.
71+
4. Select it and it should install the necessary scripts so that you can use code from the terminal.
72+
$bottomBar''');
73+
}
74+
} else {
75+
print('Approval test rejected');
76+
}
77+
} while (firstCharacter == 'v');
78+
}
79+
}
80+
81+
bool isCodeCommandAvailable() {
82+
final result = Process.runSync('which', ['code']);
83+
return result.exitCode == 0;
84+
}

example/dart_application/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/

example/dart_application/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

example/dart_application/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A sample command-line application with an entrypoint in `bin/`, library code
2+
in `lib/`, and example unit test in `test/`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file configures the static analysis results for your project (errors,
2+
# warnings, and lints).
3+
#
4+
# This enables the 'recommended' set of lints from `package:lints`.
5+
# This set helps identify many issues that may lead to problems when running
6+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
7+
# style and format.
8+
#
9+
# If you want a smaller set of lints you can change this to specify
10+
# 'package:lints/core.yaml'. These are just the most critical lints
11+
# (the recommended set includes the core lints).
12+
# The core lints are also what is used by pub.dev for scoring packages.
13+
14+
include: package:lints/recommended.yaml
15+
16+
# Uncomment the following section to specify additional rules.
17+
18+
# linter:
19+
# rules:
20+
# - camel_case_types
21+
22+
# analyzer:
23+
# exclude:
24+
# - path/to/excluded/files/**
25+
26+
# For more information about the core and recommended set of lints, see
27+
# https://dart.dev/go/core-lints
28+
29+
# For additional information about configuring this file, see
30+
# https://dart.dev/guides/language/analysis-options
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'package:dart_application/dart_application.dart' as dart_application;
2+
3+
void main(List<String> arguments) {
4+
print('Fizz Buzz for 5: ${dart_application.fizzBuzz(5)}!');
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/// Fizz Buzz kata implementation
2+
List<String> fizzBuzz(int n) {
3+
final List<String> result = [];
4+
5+
for (int i = 1; i <= n; i++) {
6+
// If the current number (`i`) is divisible by both 3 and 5 (or equivalently 15),
7+
// add the string "FizzBuzz" to the `result` list.
8+
if (i % 15 == 0) {
9+
result.add("FizzBuzz");
10+
11+
// Else, if the current number (`i`) is only divisible by 3,
12+
// add the string "Fizz" to the `result` list.
13+
} else if (i % 3 == 0) {
14+
result.add("Fizz");
15+
16+
// Else, if the current number (`i`) is only divisible by 5,
17+
// add the string "Buzz" to the `result` list.
18+
} else if (i % 5 == 0) {
19+
result.add("Buzz");
20+
21+
// If the current number (`i`) is neither divisible by 3 nor 5,
22+
// add the string representation of that number to the `result` list.
23+
} else {
24+
result.add(i.toString());
25+
}
26+
}
27+
28+
return result;
29+
}

example/dart_application/pubspec.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: dart_application
2+
description: A sample command-line application.
3+
version: 1.0.0
4+
publish_to: 'none'
5+
6+
environment:
7+
sdk: ^3.4.0
8+
9+
# Add regular dependencies here.
10+
dependencies:
11+
approval_tests:
12+
path: ../../
13+
14+
dev_dependencies:
15+
lints: ^3.0.0
16+
test: ^1.24.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:approval_tests/approval_tests.dart';
2+
import 'package:dart_application/dart_application.dart';
3+
import 'package:test/test.dart';
4+
5+
void main() {
6+
group('Fizz Buzz', () {
7+
test("verify combinations", () {
8+
Approvals.verifyAll(
9+
[3, 5, 15],
10+
options: const Options(
11+
reporter: DiffReporter(),
12+
deleteReceivedFile: true,
13+
),
14+
processor: (items) => fizzBuzz(items).toString(),
15+
);
16+
});
17+
});
18+
}

example/flutter_project/.gitignore

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
**/ios/Flutter/.last_build_id
27+
.dart_tool/
28+
.flutter-plugins
29+
.flutter-plugins-dependencies
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Symbolication related
35+
app.*.symbols
36+
37+
# Obfuscation related
38+
app.*.map.json
39+
40+
# Android Studio will place build artifacts here
41+
/android/app/debug
42+
/android/app/profile
43+
/android/app/release

example/flutter_project/.metadata

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "761747bfc538b5af34aa0d3fac380f1bc331ec49"
8+
channel: "stable"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
17+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
18+
- platform: android
19+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
20+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
21+
- platform: ios
22+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
23+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
24+
- platform: linux
25+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
26+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
27+
- platform: macos
28+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
29+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
30+
- platform: web
31+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
32+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
33+
- platform: windows
34+
create_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
35+
base_revision: 761747bfc538b5af34aa0d3fac380f1bc331ec49
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'

example/flutter_project/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# example_project
2+
3+
A new Flutter project.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:flutter_lints/flutter.yaml
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id "dev.flutter.flutter-gradle-plugin"
6+
}
7+
8+
def localProperties = new Properties()
9+
def localPropertiesFile = rootProject.file("local.properties")
10+
if (localPropertiesFile.exists()) {
11+
localPropertiesFile.withReader("UTF-8") { reader ->
12+
localProperties.load(reader)
13+
}
14+
}
15+
16+
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
17+
if (flutterVersionCode == null) {
18+
flutterVersionCode = "1"
19+
}
20+
21+
def flutterVersionName = localProperties.getProperty("flutter.versionName")
22+
if (flutterVersionName == null) {
23+
flutterVersionName = "1.0"
24+
}
25+
26+
android {
27+
namespace = "com.example.example_project"
28+
compileSdk = flutter.compileSdkVersion
29+
ndkVersion = flutter.ndkVersion
30+
31+
compileOptions {
32+
sourceCompatibility = JavaVersion.VERSION_1_8
33+
targetCompatibility = JavaVersion.VERSION_1_8
34+
}
35+
36+
defaultConfig {
37+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
38+
applicationId = "com.example.example_project"
39+
// You can update the following values to match your application needs.
40+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
41+
minSdk = flutter.minSdkVersion
42+
targetSdk = flutter.targetSdkVersion
43+
versionCode = flutterVersionCode.toInteger()
44+
versionName = flutterVersionName
45+
}
46+
47+
buildTypes {
48+
release {
49+
// TODO: Add your own signing config for the release build.
50+
// Signing with the debug keys for now, so `flutter run --release` works.
51+
signingConfig = signingConfigs.debug
52+
}
53+
}
54+
}
55+
56+
flutter {
57+
source = "../.."
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>

0 commit comments

Comments
 (0)