Skip to content

Commit

Permalink
Rename *Golden to *File (kevmoo#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyinkin committed Jan 21, 2023
1 parent 4e2f155 commit e0e5959
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 52 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const TestClass1NameLowerCase = 'testclass1';
class TestClass1 {}
```

Test against a golden output if you also want to write tests on the output itself.
Test against a golden output file if you also want to write tests on the output itself.

```dart
part 'goldens/testclass2.dart';
@ShouldGenerateGolden(
@ShouldGenerateFile(
'goldens/testclass2.dart',
partOfCurrent: true,
configurations: ['default', 'no-prefix-required'],
Expand Down
2 changes: 1 addition & 1 deletion lib/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
library source_gen_test.annotations;

export 'src/annotations.dart'
show ShouldGenerate, ShouldGenerateGolden, ShouldThrow;
show ShouldGenerate, ShouldGenerateFile, ShouldThrow;
6 changes: 3 additions & 3 deletions lib/src/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ class ShouldGenerate extends TestExpectation {
/// To update a golden, the directory for its file must exist.
///
/// Must be used with [testAnnotatedElements].
class ShouldGenerateGolden extends TestExpectation {
class ShouldGenerateFile extends TestExpectation {
final String expectedOutputFileName;
final bool contains;
final String? partOf;
final bool partOfCurrent;

const ShouldGenerateGolden(
const ShouldGenerateFile(
this.expectedOutputFileName, {
this.contains = false,
this.partOf,
Expand All @@ -84,7 +84,7 @@ class ShouldGenerateGolden extends TestExpectation {

@override
TestExpectation replaceConfiguration(Iterable<String> newConfiguration) =>
ShouldGenerateGolden(
ShouldGenerateFile(
expectedOutputFileName,
contains: contains,
partOf: partOf,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/expectation_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ List<ExpectationElement> genAnnotatedElements(

const _mappers = {
TypeChecker.fromRuntime(ShouldGenerate): _shouldGenerate,
TypeChecker.fromRuntime(ShouldGenerateGolden): _shouldGenerateGolden,
TypeChecker.fromRuntime(ShouldGenerateFile): _shouldGenerateFile,
TypeChecker.fromRuntime(ShouldThrow): _shouldThrow,
};

Expand Down Expand Up @@ -95,11 +95,11 @@ ShouldGenerate _shouldGenerate(DartObject obj) {
);
}

ShouldGenerateGolden _shouldGenerateGolden(DartObject obj) {
ShouldGenerateFile _shouldGenerateFile(DartObject obj) {
final reader = ConstantReader(obj);
final partOf = reader.read('partOf');
final partOfCurrent = reader.read('partOfCurrent');
return ShouldGenerateGolden(
return ShouldGenerateFile(
reader.read('expectedOutputFileName').stringValue,
contains: reader.read('contains').boolValue,
partOf: partOf.isString ? partOf.stringValue : null,
Expand Down
14 changes: 7 additions & 7 deletions lib/src/test_annotated_classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class AnnotatedTest<T> {
if (expectation is ShouldGenerate) {
test(_testName, _shouldGenerateTest);
return;
} else if (expectation is ShouldGenerateGolden) {
test(_testName, _shouldGenerateGoldenTest);
} else if (expectation is ShouldGenerateFile) {
test(_testName, _shouldGenerateFileTest);
return;
} else if (expectation is ShouldThrow) {
test(_testName, _shouldThrowTest);
Expand Down Expand Up @@ -267,9 +267,9 @@ class AnnotatedTest<T> {
clearBuildLog();
}

Future<void> _shouldGenerateGoldenTest() async {
Future<void> _shouldGenerateFileTest() async {
final output = await _generate();
final exp = expectation as ShouldGenerateGolden;
final exp = expectation as ShouldGenerateFile;

if (_libraryReader is! PathAwareLibraryReader) {
throw TestFailure(
Expand All @@ -281,7 +281,7 @@ class AnnotatedTest<T> {

final reader = _libraryReader as PathAwareLibraryReader;
final path = p.join(reader.directory, exp.expectedOutputFileName);
final testOutput = _padOutputForGolden(output);
final testOutput = _padOutputForFile(output);

try {
if (Platform.environment[_updateGoldensVariable] == '1') {
Expand Down Expand Up @@ -319,8 +319,8 @@ class AnnotatedTest<T> {
clearBuildLog();
}

String _padOutputForGolden(String output) {
final exp = expectation as ShouldGenerateGolden;
String _padOutputForFile(String output) {
final exp = expectation as ShouldGenerateFile;

if (exp.partOf != null) {
return "part of '${exp.partOf}';\n\n$output";
Expand Down
18 changes: 9 additions & 9 deletions test/generate_for_element_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ const TestClass2NameLowerCase = 'testclass2';
'TestClass1',
'TestClass2',
'TestClass2',
'TestClassGoldenNoPart',
'TestClassGoldenNoPart',
'TestClassGoldenPartOf',
'TestClassGoldenPartOf',
'TestClassGoldenPartOfCurrent',
'TestClassGoldenPartOfCurrent',
'TestClassFileNoPart',
'TestClassFileNoPart',
'TestClassFilePartOf',
'TestClassFilePartOf',
'TestClassFilePartOfCurrent',
'TestClassFilePartOfCurrent',
'TestClassWithBadMember',
'badTestField',
'badTestField',
Expand Down Expand Up @@ -311,9 +311,9 @@ const TestClass2NameLowerCase = 'testclass2';
'`BadTestClass`: "no-prefix-required", "vague"; '
'`TestClass1`: "no-prefix-required", "vague"; '
'`TestClass2`: "vague"; '
'`TestClassGoldenNoPart`: "no-prefix-required", "vague"; '
'`TestClassGoldenPartOf`: "no-prefix-required", "vague"; '
'`TestClassGoldenPartOfCurrent`: "no-prefix-required", "vague"; '
'`TestClassFileNoPart`: "no-prefix-required", "vague"; '
'`TestClassFilePartOf`: "no-prefix-required", "vague"; '
'`TestClassFilePartOfCurrent`: "no-prefix-required", "vague"; '
'`badTestField`: "vague"; '
'`badTestFunc`: "vague"',
),
Expand Down
6 changes: 3 additions & 3 deletions test/init_library_reader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ void main() {
'badTestFunc',
'TestClass1',
'TestClass2',
'TestClassGoldenNoPart',
'TestClassGoldenPartOf',
'TestClassGoldenPartOfCurrent',
'TestClassFileNoPart',
'TestClassFilePartOf',
'TestClassFilePartOfCurrent',
'TestClassWithBadMember',
]),
);
Expand Down
3 changes: 3 additions & 0 deletions test/src/goldens/test_library_file_no_part.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const TestClassFileNoPartNameLength = 19;

const TestClassFileNoPartNameLowerCase = 'testclassfilenopart';
5 changes: 5 additions & 0 deletions test/src/goldens/test_library_file_part_of.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
part of 'test_part_owner.dart';

const TestClassFilePartOfNameLength = 19;

const TestClassFilePartOfNameLowerCase = 'testclassfilepartof';
5 changes: 5 additions & 0 deletions test/src/goldens/test_library_file_part_of_current.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
part of '../test_library.dart';

const TestClassFilePartOfCurrentNameLength = 26;

const TestClassFilePartOfCurrentNameLowerCase = 'testclassfilepartofcurrent';
3 changes: 0 additions & 3 deletions test/src/goldens/test_library_golden_no_part.dart

This file was deleted.

5 changes: 0 additions & 5 deletions test/src/goldens/test_library_golden_part_of.dart

This file was deleted.

6 changes: 0 additions & 6 deletions test/src/goldens/test_library_golden_part_of_current.dart

This file was deleted.

20 changes: 10 additions & 10 deletions test/src/test_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:source_gen_test/annotations.dart';
import 'test_annotation.dart';

part 'test_part.dart';
part 'goldens/test_library_golden_part_of_current.dart';
part 'goldens/test_library_file_part_of_current.dart';

@ShouldGenerate(
r'''
Expand All @@ -21,8 +21,8 @@ const TestClass1NameLowerCase = 'testclass1';
@TestAnnotation()
class TestClass1 {}

@ShouldGenerateGolden(
'goldens/test_library_golden_no_part.dart',
@ShouldGenerateFile(
'goldens/test_library_file_no_part.dart',
configurations: ['default', 'no-prefix-required'],
)
@ShouldThrow(
Expand All @@ -31,10 +31,10 @@ class TestClass1 {}
element: false,
)
@TestAnnotation()
class TestClassGoldenNoPart {}
class TestClassFileNoPart {}

@ShouldGenerateGolden(
'goldens/test_library_golden_part_of.dart',
@ShouldGenerateFile(
'goldens/test_library_file_part_of.dart',
partOf: 'test_part_owner.dart',
configurations: ['default', 'no-prefix-required'],
)
Expand All @@ -44,10 +44,10 @@ class TestClassGoldenNoPart {}
element: false,
)
@TestAnnotation()
class TestClassGoldenPartOf {}
class TestClassFilePartOf {}

@ShouldGenerateGolden(
'goldens/test_library_golden_part_of_current.dart',
@ShouldGenerateFile(
'goldens/test_library_file_part_of_current.dart',
partOfCurrent: true,
configurations: ['default', 'no-prefix-required'],
)
Expand All @@ -57,7 +57,7 @@ class TestClassGoldenPartOf {}
element: false,
)
@TestAnnotation()
class TestClassGoldenPartOfCurrent {}
class TestClassFilePartOfCurrent {}

@ShouldGenerate(
r'''
Expand Down

0 comments on commit e0e5959

Please sign in to comment.