Format, improve travis testing

This commit is contained in:
Simon Binder 2019-02-14 17:55:31 +01:00
parent e4f733119d
commit 700a21d29e
22 changed files with 58 additions and 51 deletions

View File

@ -6,7 +6,7 @@
<value> <value>
<list> <list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.34.3/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.34.3/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.35.0/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.35.1/lib" />
</list> </list>
</value> </value>
</entry> </entry>
@ -191,7 +191,7 @@
<value> <value>
<list> <list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.9+1/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.9+1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.10/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.11/lib" />
</list> </list>
</value> </value>
</entry> </entry>
@ -269,7 +269,7 @@
<value> <value>
<list> <list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.9+1/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.9+1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.10/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.11/lib" />
</list> </list>
</value> </value>
</entry> </entry>
@ -486,7 +486,6 @@
<entry key="stream_transform"> <entry key="stream_transform">
<value> <value>
<list> <list>
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.14+1/lib" />
<option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.15/lib" /> <option value="$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.15/lib" />
</list> </list>
</value> </value>
@ -597,7 +596,7 @@
</properties> </properties>
<CLASSES> <CLASSES>
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.34.3/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.34.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.35.0/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer-0.35.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer_plugin-0.0.1-alpha.6/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/analyzer_plugin-0.0.1-alpha.6/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/args-1.5.1/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/args-1.5.1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/async-2.0.8/lib" />
@ -625,7 +624,7 @@
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/csslib-0.14.6/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/csslib-0.14.6/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/dart_style-1.2.3/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/dart_style-1.2.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/fixnum-0.10.9/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/fixnum-0.10.9/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.10/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.11/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.9+1/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/front_end-0.1.9+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/glob-1.1.7/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/glob-1.1.7/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/graphs-0.2.0/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/graphs-0.2.0/lib" />
@ -637,7 +636,7 @@
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/js-0.6.1+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_annotation-2.0.0/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_annotation-2.0.0/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.9/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/json_rpc_2-2.0.9/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.10/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.11/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.9+1/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/kernel-0.3.9+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/logging-0.11.3+2/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/logging-0.11.3+2/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.3+1/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.3+1/lib" />
@ -666,7 +665,6 @@
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/source_span-1.5.4/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/source_span-1.5.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.9.3/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.8/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_channel-1.6.8/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.14+1/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.15/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/stream_transform-0.0.15/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.0.4/lib" />
<root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib" /> <root url="file://$USER_HOME$/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.1.0/lib" />

View File

@ -7,7 +7,7 @@ env:
- PKG="sally" - PKG="sally"
- PKG="sally_generator" - PKG="sally_generator"
script: ./tool/travis.sh dartfmt dartanalyzer test script: ./tool/mono_repo_wrapper.sh
# Only building master means that we don't run two builds for each pull request. # Only building master means that we don't run two builds for each pull request.
branches: branches:

View File

@ -14,7 +14,8 @@ class StreamQueryStore {
} }
Future<void> handleTableUpdates(String table) async { Future<void> handleTableUpdates(String table) async {
final affectedStreams = _activeStreams.where((stream) => stream.isAffectedByTableChange(table)); final affectedStreams =
_activeStreams.where((stream) => stream.isAffectedByTableChange(table));
for (var stream in affectedStreams) { for (var stream in affectedStreams) {
await stream.fetchAndEmitData(); await stream.fetchAndEmitData();

View File

@ -16,7 +16,8 @@ class DeleteStatement<UserTable> extends Query<UserTable, dynamic> {
Future<int> go() async { Future<int> go() async {
final ctx = constructQuery(); final ctx = constructQuery();
final rows = await ctx.database.executor.runDelete(ctx.sql, ctx.boundVariables); final rows =
await ctx.database.executor.runDelete(ctx.sql, ctx.boundVariables);
if (rows > 0) { if (rows > 0) {
database.markTableUpdated(table.$tableName); database.markTableUpdated(table.$tableName);

View File

@ -12,7 +12,8 @@ class InsertStatement<DataClass> {
Future<void> insert(DataClass entity) async { Future<void> insert(DataClass entity) async {
if (!table.validateIntegrity(entity, true)) { if (!table.validateIntegrity(entity, true)) {
throw InvalidDataException('Invalid data: $entity cannot be written into ${table.$tableName}'); throw InvalidDataException(
'Invalid data: $entity cannot be written into ${table.$tableName}');
} }
final map = table.entityToSql(entity) final map = table.entityToSql(entity)

View File

@ -39,11 +39,13 @@ class UpdateStatement<T, D> extends Query<T, D> {
Future<int> write(D entity) async { Future<int> write(D entity) async {
_updateReference = entity; _updateReference = entity;
if (!table.validateIntegrity(_updateReference, false)) { if (!table.validateIntegrity(_updateReference, false)) {
throw InvalidDataException('Invalid data: $entity cannot be written into ${table.$tableName}'); throw InvalidDataException(
'Invalid data: $entity cannot be written into ${table.$tableName}');
} }
final ctx = constructQuery(); final ctx = constructQuery();
final rows = await ctx.database.executor.runUpdate(ctx.sql, ctx.boundVariables); final rows =
await ctx.database.executor.runUpdate(ctx.sql, ctx.boundVariables);
if (rows > 0) { if (rows > 0) {
database.markTableUpdated(table.$tableName); database.markTableUpdated(table.$tableName);

View File

@ -75,15 +75,11 @@ class GeneratedTextColumn extends GeneratedColumn<String, StringType>
if (value == null) return nullOk; if (value == null) return nullOk;
final length = value.length; final length = value.length;
if (minTextLength != null && minTextLength > length) if (minTextLength != null && minTextLength > length) return false;
return false; if (maxTextLength != null && maxTextLength < length) return false;
if (maxTextLength != null && maxTextLength < length)
return false;
return true; return true;
} }
} }
class GeneratedBoolColumn extends GeneratedColumn<bool, BoolType> class GeneratedBoolColumn extends GeneratedColumn<bool, BoolType>

View File

@ -17,7 +17,7 @@ abstract class TableInfo<TableDsl, DataClass> {
/// that it respects all constraints (nullability, text length, etc.). /// that it respects all constraints (nullability, text length, etc.).
/// During insertion mode, fields that have a default value or are /// During insertion mode, fields that have a default value or are
/// auto-incrementing are allowed to be null as they will be set by sqlite. /// auto-incrementing are allowed to be null as they will be set by sqlite.
bool validateIntegrity(DataClass instance, bool isInserting) => null; bool validateIntegrity(DataClass instance, bool isInserting);
/// Maps the given data class into a map that can be inserted into sql. The /// Maps the given data class into a map that can be inserted into sql. The
/// keys should represent the column name in sql, the values the corresponding /// keys should represent the column name in sql, the values the corresponding

View File

@ -3,7 +3,7 @@ dart:
stages: stages:
- analyze: - analyze:
- dartanalyzer - dartanalyzer: --fatal-infos --fatal-warnings .
- dartfmt - dartfmt
- unit_test: - unit_test:
- test - command: pub run build_runner test

View File

@ -14,5 +14,6 @@ dev_dependencies:
sally_generator: sally_generator:
path: ../sally_generator path: ../sally_generator
build_runner: ^1.2.6 build_runner: ^1.2.6
build_test: ^0.10.6
test: ^1.5.3 test: ^1.5.3
mockito: ^4.0.0 mockito: ^4.0.0

View File

@ -24,8 +24,8 @@ void main() {
test('for complex components', () async { test('for complex components', () async {
await (db.delete(db.users) await (db.delete(db.users)
..where((u) => or(not(u.isAwesome), u.id.isSmallerThan(100))) ..where((u) => or(not(u.isAwesome), u.id.isSmallerThan(100)))
..limit(10, offset: 100)) ..limit(10, offset: 100))
.go(); .go();
verify(executor.runDelete( verify(executor.runDelete(
@ -51,4 +51,4 @@ void main() {
verifyNever(streamQueries.handleTableUpdates(any)); verifyNever(streamQueries.handleTableUpdates(any));
}); });
}); });
} }

View File

@ -53,12 +53,7 @@ void main() {
group('SELECT results are parsed', () { group('SELECT results are parsed', () {
test('when all fields are non-null', () { test('when all fields are non-null', () {
final data = [ final data = [
{ {'id': 10, 'title': 'A todo title', 'content': 'Content', 'category': 3}
'id': 10,
'title': 'A todo title',
'content': 'Content',
'category': 3
}
]; ];
final resolved = TodoEntry( final resolved = TodoEntry(
id: 10, id: 10,

View File

@ -49,4 +49,4 @@ void main() {
verifyNever(executor.runSelect(any, any)); verifyNever(executor.runSelect(any, any));
}); });
}); });
} }

View File

@ -4,7 +4,6 @@ part 'todos.g.dart';
@DataClassName('TodoEntry') @DataClassName('TodoEntry')
class TodosTable extends Table { class TodosTable extends Table {
@override @override
String get tableName => 'todos'; String get tableName => 'todos';
@ -13,7 +12,6 @@ class TodosTable extends Table {
TextColumn get content => text()(); TextColumn get content => text()();
IntColumn get category => integer().nullable()(); IntColumn get category => integer().nullable()();
} }
class Users extends Table { class Users extends Table {
@ -24,10 +22,8 @@ class Users extends Table {
@DataClassName('Category') @DataClassName('Category')
class Categories extends Table { class Categories extends Table {
IntColumn get id => integer().autoIncrement()(); IntColumn get id => integer().autoIncrement()();
TextColumn get description => text().named('desc')(); TextColumn get description => text().named('desc')();
} }
@UseSally(tables: [TodosTable, Categories, Users]) @UseSally(tables: [TodosTable, Categories, Users])
@ -39,5 +35,4 @@ class TodoDb extends _$TodoDb {
@override @override
int get schemaVersion => 1; int get schemaVersion => 1;
}
}

View File

@ -5,14 +5,12 @@ import 'package:sally/src/runtime/executor/stream_queries.dart';
export 'package:mockito/mockito.dart'; export 'package:mockito/mockito.dart';
class MockExecutor extends Mock implements QueryExecutor { class MockExecutor extends Mock implements QueryExecutor {
MockExecutor() { MockExecutor() {
when(runSelect(any, any)).thenAnswer((_) => Future.value([])); when(runSelect(any, any)).thenAnswer((_) => Future.value([]));
when(runUpdate(any, any)).thenAnswer((_) => Future.value(0)); when(runUpdate(any, any)).thenAnswer((_) => Future.value(0));
when(runDelete(any, any)).thenAnswer((_) => Future.value(0)); when(runDelete(any, any)).thenAnswer((_) => Future.value(0));
when(runInsert(any, any)).thenAnswer((_) => Future.value(0)); when(runInsert(any, any)).thenAnswer((_) => Future.value(0));
} }
} }
class MockStreamQueries extends Mock implements StreamQueryStore {} class MockStreamQueries extends Mock implements StreamQueryStore {}
@ -22,4 +20,4 @@ abstract class SqlExecutorAsClass {
Future<void> call(String sql); Future<void> call(String sql);
} }
class MockQueryExecutor extends Mock implements SqlExecutorAsClass {} class MockQueryExecutor extends Mock implements SqlExecutorAsClass {}

View File

@ -43,10 +43,13 @@ class SpecifiedColumn {
/// as getter name in the TableInfo class (as it needs to override the field) /// as getter name in the TableInfo class (as it needs to override the field)
/// and in the generated data class that will be generated for each table. /// and in the generated data class that will be generated for each table.
final String dartGetterName; final String dartGetterName;
/// The sql type of this column /// The sql type of this column
final ColumnType type; final ColumnType type;
/// The name of this column, as chosen by the user /// The name of this column, as chosen by the user
final ColumnName name; final ColumnName name;
/// Whether the user has explicitly declared this column to be nullable, the /// Whether the user has explicitly declared this column to be nullable, the
/// default is false /// default is false
final bool nullable; final bool nullable;

View File

@ -15,6 +15,7 @@ class TableParser extends ParserBase {
SpecifiedTable parse(ClassElement element) { SpecifiedTable parse(ClassElement element) {
final sqlName = _parseTableName(element); final sqlName = _parseTableName(element);
if (sqlName == null) return null;
return SpecifiedTable( return SpecifiedTable(
fromClass: element, fromClass: element,

View File

@ -141,7 +141,6 @@ const sqliteKeywords = [
bool isSqliteKeyword(String s) => sqliteKeywords.contains(s.toUpperCase()); bool isSqliteKeyword(String s) => sqliteKeywords.contains(s.toUpperCase());
String escapeIfNeeded(String s) { String escapeIfNeeded(String s) {
if (isSqliteKeyword(s)) if (isSqliteKeyword(s)) return '`$s`';
return '`$s`';
return s; return s;
} }

View File

@ -76,8 +76,8 @@ class TableWriter {
final resolver = '${ReCase(usedType).camelCase}Type'; final resolver = '${ReCase(usedType).camelCase}Type';
dartTypeToResolver[usedType] = resolver; dartTypeToResolver[usedType] = resolver;
buffer buffer.write(
.write('final $resolver = _db.typeSystem.forDartType<$usedType>();\n'); 'final $resolver = _db.typeSystem.forDartType<$usedType>();\n');
} }
// finally, the mighty constructor invocation: // finally, the mighty constructor invocation:
@ -146,7 +146,8 @@ class TableWriter {
void _writeValidityCheckMethod(StringBuffer buffer) { void _writeValidityCheckMethod(StringBuffer buffer) {
final dataClass = table.dartTypeName; final dataClass = table.dartTypeName;
buffer.write('@override\nbool validateIntegrity($dataClass instance, bool isInserting) => '); buffer.write(
'@override\nbool validateIntegrity($dataClass instance, bool isInserting) => ');
final validationCode = table.columns.map((column) { final validationCode = table.columns.map((column) {
final getterName = column.dartGetterName; final getterName = column.dartGetterName;

View File

@ -3,7 +3,7 @@ dart:
stages: stages:
- analyze: - analyze:
- dartanalyzer - dartanalyzer: --fatal-infos --fatal-warnings .
- dartfmt - dartfmt
- unit_test: - unit_test:
- test - test

10
tool/mono_repo_wrapper.sh Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
case $PKG in
sally_generator)
./tool/travis.sh dartfmt dartanalyzer test
;;
sally)
./tool/travis.sh dartfmt dartanalyzer command
;;
esac

View File

@ -19,10 +19,15 @@ EXIT_CODE=0
while (( "$#" )); do while (( "$#" )); do
TASK=$1 TASK=$1
case $TASK in case $TASK in
command) echo
echo -e '\033[1mTASK: command\033[22m'
echo -e 'pub run build_runner test'
pub run build_runner test || EXIT_CODE=$?
;;
dartanalyzer) echo dartanalyzer) echo
echo -e '\033[1mTASK: dartanalyzer\033[22m' echo -e '\033[1mTASK: dartanalyzer\033[22m'
echo -e 'dartanalyzer .' echo -e 'dartanalyzer --fatal-infos --fatal-warnings .'
dartanalyzer . || EXIT_CODE=$? dartanalyzer --fatal-infos --fatal-warnings . || EXIT_CODE=$?
;; ;;
dartfmt) echo dartfmt) echo
echo -e '\033[1mTASK: dartfmt\033[22m' echo -e '\033[1mTASK: dartfmt\033[22m'