Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 committed Oct 11, 2024
1 parent 586b66f commit f9cf500
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
8 changes: 6 additions & 2 deletions test/fvm_version_not_installed_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ void main() {
test('FVM version not installed', () async {
final result = await testCommand(
['get'],
// TODO: FIX THIS
// workingDirectory: 'test_resources_2/fvm_version_not_installed_test',
projects: {
'fvm_version_not_installed_test': {
'pubspec.yaml': pubspec('fvm_version_not_installed_test'),
'.fvmrc': fvmrc('1.17.0'),
},
},
);
final stdout = result.stdout;

Expand Down
13 changes: 0 additions & 13 deletions test/gen_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:io/io.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';

import 'test_utils.dart';
Expand All @@ -11,22 +10,10 @@ void main() {
final result = await testCommand(['gen']);
final stdout = result.stdout;

// Since these projects have no code generation, the command should fail
expect(result.exitCode, isNot(ExitCode.success.code));

// dart
expectLine(stdout, ['dart_puby_test', 'dart $argString']);
// Explicit exclusion
expectLine(stdout, [p.join('dart_puby_test', 'example'), 'Skip']);

// flutter
expectLine(stdout, ['flutter_puby_test', 'flutter $argString']);
// Explicit exclusion
expectLine(stdout, [p.join('flutter_puby_test', 'example'), 'Skip']);

// fvm
expectLine(stdout, ['fvm_puby_test', 'fvm flutter $argString']);
// Explicit exclusion
expectLine(stdout, [p.join('fvm_puby_test', 'example'), 'Skip']);
});
}
7 changes: 6 additions & 1 deletion test/link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ void main() {
// Ensure the correct flutter version was used
expect(
File(
path.join('test_resources', 'fvm_puby_test', '.dart_tool', 'version'),
path.join(
result.workingDirectory,
'fvm_puby_test',
'.dart_tool',
'version',
),
).readAsStringSync(),
'3.10.0',
);
Expand Down
7 changes: 6 additions & 1 deletion test/no_fvm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ void main() {
// Ensure the FVM Flutter version was not used
expect(
File(
path.join('test_resources', 'fvm_puby_test', '.dart_tool', 'version'),
path.join(
result.workingDirectory,
'fvm_puby_test',
'.dart_tool',
'version',
),
).readAsStringSync(),
isNot('3.10.0'),
);
Expand Down
4 changes: 2 additions & 2 deletions test/pub_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
);
});

test('invlaid pubspec', () async {
test('handles invlaid pubspec', () async {
final result = await testCommand(
['get'],
projects: {
Expand All @@ -37,7 +37,7 @@ void main() {
expectLine(stdout, ['invalid_pubspec_test', 'Error parsing pubspec']);
});

group('exclusions', () {
group('excludes', () {
test('project in build folder', () async {
final result = await testCommand(
['get'],
Expand Down
12 changes: 0 additions & 12 deletions test/test_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:io/io.dart';
import 'package:path/path.dart' as p;
import 'package:test/test.dart';

import 'test_utils.dart';
Expand All @@ -12,19 +11,8 @@ void main() {
// Since these projects have no tests, the command should fail
expect(result.exitCode, isNot(ExitCode.success.code));

// dart
expectLine(stdout, ['dart_puby_test', 'flutter test --coverage']);
// Explicit exclusion
expectLine(stdout, [p.join('dart_puby_test', 'example'), 'Skip']);

// flutter
expectLine(stdout, ['flutter_puby_test', 'flutter test --coverage']);
// Explicit exclusion
expectLine(stdout, [p.join('flutter_puby_test', 'example'), 'Skip']);

// fvm
expectLine(stdout, ['fvm_puby_test', 'fvm flutter test --coverage']);
// Explicit exclusion
expectLine(stdout, [p.join('fvm_puby_test', 'example'), 'Skip']);
});
}
20 changes: 17 additions & 3 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ final _decoder = Utf8Decoder();
// Map of project name to file paths to file contents
typedef TestProjects = Map<String, Map<String, String>>;

Future<ProcessResult> testCommand(
class PubyProcessResult {
final String workingDirectory;
final int exitCode;
final String stdout;
final String stderr;

PubyProcessResult(
this.workingDirectory,
this.exitCode,
this.stdout,
this.stderr,
);
}

Future<PubyProcessResult> testCommand(
List<String> arguments, {
TestProjects? projects,
bool debug = false,
Expand All @@ -33,8 +47,8 @@ Future<ProcessResult> testCommand(
final processStderr = process.stderr.map(handleLine).join('\n');

final exitCode = await process.exitCode;
return ProcessResult(
process.pid,
return PubyProcessResult(
workingDirectory,
exitCode,
await processStdout,
await processStderr,
Expand Down

0 comments on commit f9cf500

Please sign in to comment.