Nurhan Turgut 48902d146a
Felt add integration (#17190)
* adding arguments to felt for running different type of tests

* adding test type enums to felt

* more changes to felt for testing branches

* more additions to code

* more changes to felt

* adding code for cloning web_drivers

* validating test directories. running the integration tests. update the readme file partially

* Removing todo lists used for development

* addressing reviewers comments

* remove unused imports

* addressing more reviewer comments

* addressing more reviewer comments

* addressing reviewer comments.

* addressing reviewer comments.

* fixing typos

* using chromedriverinstaller as a library. Fixing the commit number used from web_installers repo

* clean drivers directory after tests finish

* addressing more reviewer comments

* throwing all critical exceptions instead of logging and returning boolean flags

* adding todos for items we can do for making felt easier to use for local development

* do not run integration tests on CIs. Added an issue to the TODO.

* changing todo's with issues.
2020-03-20 19:24:13 -07:00

137 lines
3.7 KiB
Dart

// Copyright 2013 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.
// @dart = 2.6
import 'dart:async';
import 'dart:io' as io;
import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'common.dart';
import 'environment.dart';
class FilePath {
FilePath.fromCwd(String relativePath)
: _absolutePath = path.absolute(relativePath);
FilePath.fromWebUi(String relativePath)
: _absolutePath = path.join(environment.webUiRootDir.path, relativePath);
final String _absolutePath;
String get absolute => _absolutePath;
String get relativeToCwd => path.relative(_absolutePath);
String get relativeToWebUi =>
path.relative(_absolutePath, from: environment.webUiRootDir.path);
@override
bool operator ==(dynamic other) {
return other is FilePath && _absolutePath == other._absolutePath;
}
@override
String toString() => _absolutePath;
}
/// Runs [executable] merging its output into the current process' standard out and standard error.
Future<int> runProcess(
String executable,
List<String> arguments, {
String workingDirectory,
bool mustSucceed: false,
}) async {
final io.Process process = await io.Process.start(
executable,
arguments,
workingDirectory: workingDirectory,
// Running the process in a system shell for Windows. Otherwise
// the process is not able to get Dart from path.
runInShell: io.Platform.isWindows,
mode: io.ProcessStartMode.inheritStdio,
);
final int exitCode = await process.exitCode;
if (mustSucceed && exitCode != 0) {
throw ProcessException(
description: 'Sub-process failed.',
executable: executable,
arguments: arguments,
workingDirectory: workingDirectory,
exitCode: exitCode,
);
}
return exitCode;
}
/// Runs [executable]. Do not follow the exit code or the output.
void startProcess(
String executable,
List<String> arguments, {
String workingDirectory,
bool mustSucceed: false,
}) async {
final io.Process process = await io.Process.start(
executable,
arguments,
workingDirectory: workingDirectory,
// Running the process in a system shell for Windows. Otherwise
// the process is not able to get Dart from path.
runInShell: io.Platform.isWindows,
mode: io.ProcessStartMode.inheritStdio,
);
processesToCleanUp.add(process);
}
/// Runs [executable] and returns its standard output as a string.
///
/// If the process fails, throws a [ProcessException].
Future<String> evalProcess(
String executable,
List<String> arguments, {
String workingDirectory,
}) async {
final io.ProcessResult result = await io.Process.run(
executable,
arguments,
workingDirectory: workingDirectory,
);
if (result.exitCode != 0) {
throw ProcessException(
description: result.stderr,
executable: executable,
arguments: arguments,
workingDirectory: workingDirectory,
exitCode: result.exitCode,
);
}
return result.stdout;
}
@immutable
class ProcessException implements Exception {
ProcessException({
@required this.description,
@required this.executable,
@required this.arguments,
@required this.workingDirectory,
@required this.exitCode,
});
final String description;
final String executable;
final List<String> arguments;
final String workingDirectory;
final int exitCode;
@override
String toString() {
final StringBuffer message = StringBuffer();
message
..writeln(description)
..writeln('Command: $executable ${arguments.join(' ')}')
..writeln('Working directory: ${workingDirectory ?? io.Directory.current.path}')
..writeln('Exit code: $exitCode');
return '$message';
}
}