This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
115 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:oracle/oracle.dart' as oracle; | ||
import 'package:matcher/matcher.dart'; | ||
|
||
Matcher throwsSqlException(int code) => new SqlExceptionThrownMatcher(code); | ||
|
||
class SqlExceptionThrownMatcher extends Matcher { | ||
final int _code; | ||
|
||
const SqlExceptionThrownMatcher(this._code); | ||
|
||
bool matches(f, Map state) { | ||
try { | ||
f(); | ||
addStateInfo(state, {'failure_type': 'fuction retuned normally'}); | ||
return false; | ||
} catch (e) { | ||
if (e is! oracle.SqlException) { | ||
addStateInfo(state, { | ||
'failure_type': 'expected SqlException, got ${e.runtimeType}' | ||
}); | ||
return false; | ||
} else if (_code != e.code) { | ||
print('rawr'); | ||
addStateInfo(state, { | ||
'failure_type': | ||
'error code mismatch: expected <$_code>, got <${e.code}>' | ||
}); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
Description describe(Description description) => | ||
description.add('a SqlException with error code <$_code> to be thrown'); | ||
|
||
Description describeMismatch( | ||
item, Description mismatchDescription, Map matchState, bool verbose) { | ||
return mismatchDescription.add(matchState['failure_type']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters