Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
test: add pre generation tests (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Nov 28, 2023
1 parent a4a3cb4 commit 3e63e30
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 1 deletion.
4 changes: 3 additions & 1 deletion brick/hooks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ dependencies:
mason: ^0.1.0-dev.50

dev_dependencies:
very_good_analysis: ^5.1.0
mocktail: ^1.0.0
test: ^1.19.2
very_good_analysis: ^5.1.0
173 changes: 173 additions & 0 deletions brick/hooks/test/pre_gen_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import 'package:mason/mason.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import '../pre_gen.dart' as pre_gen;

class _MockHookContext extends Mock implements HookContext {}

void main() {
group('pre_gen', () {
late HookContext context;

setUp(() {
context = _MockHookContext();
});

group('android variable', () {
const androidVariable = 'android';

test('is set to true if it is in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': [androidVariable],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[androidVariable], isTrue);
});

test('is set to false if it is not in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': <String>[],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[androidVariable], isFalse);
});
});

group('ios variable', () {
const iosVariable = 'ios';

test('is set to true if it is in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': [iosVariable],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[iosVariable], isTrue);
});

test('is set to false if it is not in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': <String>[],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[iosVariable], isFalse);
});
});

group('macos variable', () {
const macOsVariable = 'macos';

test('is set to true if it is in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': [macOsVariable],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[macOsVariable], isTrue);
});

test('is set to false if it is not in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': <String>[],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[macOsVariable], isFalse);
});
});

group('linux variable', () {
const linuxVariable = 'linux';

test('is set to true if it is in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': [linuxVariable],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[linuxVariable], isTrue);
});

test('is set to false if it is not in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': <String>[],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[linuxVariable], isFalse);
});
});

group('web variable', () {
const webVariable = 'web';

test('is set to true if it is in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': [webVariable],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[webVariable], isTrue);
});

test('is set to false if it is not in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': <String>[],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[webVariable], isFalse);
});
});

group('windows variable', () {
const windowsVariable = 'windows';

test('is set to true if it is in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': [windowsVariable],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[windowsVariable], isTrue);
});

test('is set to false if it is not in `platforms` variable', () {
final vars = <String, dynamic>{
'platforms': <String>[],
};
when(() => context.vars).thenReturn(vars);

pre_gen.run(context);

expect(vars[windowsVariable], isFalse);
});
});
});
}

0 comments on commit 3e63e30

Please sign in to comment.