Skip to content

Commit

Permalink
[canvaskit] Add catchException everywhere
Browse files Browse the repository at this point in the history
This should make the logs in the bots more actionable by showing
the error and trace.

This also fixes the API change causing mysterious red.

Bug: skia:
Change-Id: I38df2bb4557041f8bdfefcae5c8d95b58e770033
Reviewed-on: https://skia-review.googlesource.com/c/168180
Reviewed-by: Kevin Lubick <[email protected]>
  • Loading branch information
kjlubick committed Nov 5, 2018
1 parent 5191608 commit e71e9ef
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 68 deletions.
12 changes: 6 additions & 6 deletions experimental/canvaskit/tests/path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('CanvasKit\'s Path Behavior', function() {
}

it('can draw a path', function(done) {
LoadCanvasKit.then(() => {
LoadCanvasKit.then(catchException(done, () => {
// This is taken from example.html
const surface = CanvasKit.MakeCanvasSurface('test');
expect(surface).toBeTruthy('Could not make surface')
Expand All @@ -72,7 +72,7 @@ describe('CanvasKit\'s Path Behavior', function() {
paint.setStrokeWidth(1.0);
paint.setAntiAlias(true);
paint.setColor(CanvasKit.Color(0, 0, 0, 1.0));
paint.setStyle(CanvasKit.PaintStyle.STROKE);
paint.setStyle(CanvasKit.PaintStyle.Stroke);

const path = new CanvasKit.SkPath();
path.moveTo(20, 5);
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('CanvasKit\'s Path Behavior', function() {
paint.delete();

reportSurface(surface, 'path_api_example', done);
});
}));
// See CanvasKit for more tests, since they share implementation
});

Expand All @@ -122,7 +122,7 @@ describe('CanvasKit\'s Path Behavior', function() {
}

it('can apply an effect and draw text', function(done) {
LoadCanvasKit.then(() => {
LoadCanvasKit.then(catchException(done, () => {
const surface = CanvasKit.MakeCanvasSurface('test');
expect(surface).toBeTruthy('Could not make surface')
if (!surface) {
Expand All @@ -142,7 +142,7 @@ describe('CanvasKit\'s Path Behavior', function() {
const dpe = CanvasKit.MakeSkDashPathEffect([15, 5, 5, 10], 1);

paint.setPathEffect(dpe);
paint.setStyle(CanvasKit.PaintStyle.STROKE);
paint.setStyle(CanvasKit.PaintStyle.Stroke);
paint.setStrokeWidth(5.0);
paint.setAntiAlias(true);
paint.setColor(CanvasKit.Color(66, 129, 164, 1.0));
Expand All @@ -156,6 +156,6 @@ describe('CanvasKit\'s Path Behavior', function() {
path.delete();

reportSurface(surface, 'effect_and_text_example', done);
});
}));
});
});
17 changes: 8 additions & 9 deletions modules/pathkit/tests/effects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('PathKit\'s Path Behavior', function() {

describe('Dash Path Effect', function() {
it('performs dash in-place with start, stop, phase', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawStar();
let dashed = drawStar();
let notACopy = dashed.dash(10, 3, 0);
Expand All @@ -46,13 +46,13 @@ describe('PathKit\'s Path Behavior', function() {
dashed.delete();
phased.delete();
});
});
}));
});
});

describe('Trim Path Effect', function() {
it('performs trim in-place with start, stop, phase', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawStar();
let trimmed = drawStar();
let notACopy = trimmed.trim(0.25, .8);
Expand All @@ -69,14 +69,13 @@ describe('PathKit\'s Path Behavior', function() {
trimmed.delete();
complement.delete();
});

});
}));
});
});

describe('Transform Path Effect', function() {
it('performs matrix transform in-place', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawStar();
let scaled = drawStar();
let notACopy = scaled.transform(3, 0, 0,
Expand All @@ -97,13 +96,13 @@ describe('PathKit\'s Path Behavior', function() {
scaled.delete();
scaled2.delete();
});
});
}));
});
});

describe('Stroke Path Effect', function() {
it('creates a stroked path in-place', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawStar();
let stroked = drawStar();
let notACopy = stroked.stroke({
Expand Down Expand Up @@ -131,7 +130,7 @@ describe('PathKit\'s Path Behavior', function() {
stroked.delete();
rounded.delete();
});
});
}));
});
});

Expand Down
28 changes: 14 additions & 14 deletions modules/pathkit/tests/path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('PathKit\'s Path Behavior', function() {
}

it('supports.equals()', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let path = drawSimplePath();
let otherPath = drawSimplePath();
let blank = PathKit.NewPath();
Expand All @@ -44,11 +44,11 @@ describe('PathKit\'s Path Behavior', function() {
otherPath.delete();
blank.delete();
done();
});
}));
});

it('has a copy constructor', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawSimplePath();
let copy = new PathKit.SkPath(orig);

Expand All @@ -58,11 +58,11 @@ describe('PathKit\'s Path Behavior', function() {
orig.delete();
copy.delete();
done();
});
}));
});

it('has a copy method', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawSimplePath();
let copy = orig.copy();

Expand All @@ -72,11 +72,11 @@ describe('PathKit\'s Path Behavior', function() {
orig.delete();
copy.delete();
done();
});
}));
});

it('can create a copy with MakePath', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let orig = drawSimplePath();
let copy = PathKit.NewPath(orig);

Expand All @@ -86,7 +86,7 @@ describe('PathKit\'s Path Behavior', function() {
orig.delete();
copy.delete();
done();
});
}));
});
});

Expand All @@ -109,7 +109,7 @@ describe('PathKit\'s Path Behavior', function() {

describe('bounds and rect', function(){
it('dynamically updates getBounds()', function(done){
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
// Based on test_bounds_crbug_513799
let path = PathKit.NewPath();
expect(path.getBounds()).toEqual(PathKit.LTRBRect(0, 0, 0, 0));
Expand All @@ -121,11 +121,11 @@ describe('PathKit\'s Path Behavior', function() {
expect(path.getBounds()).toEqual(PathKit.LTRBRect(-5, -8, 3, 4));
path.delete();
done();
});
}));
});

it('has getBounds() and computeTightBounds()', function(done){
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
// Based on PathOpsTightBoundsIllBehaved
let path = PathKit.NewPath();
path.moveTo(1, 1);
Expand All @@ -138,7 +138,7 @@ describe('PathKit\'s Path Behavior', function() {
path.delete();

done();
});
}));
});
});

Expand All @@ -159,7 +159,7 @@ describe('PathKit\'s Path Behavior', function() {

describe('Command arrays', function(){
it('does NOT approximates conics when dumping as toCmds', function(done){
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let path = PathKit.NewPath();
path.moveTo(20, 120);
path.arc(20, 120, 18, 0, 1.75 * Math.PI);
Expand All @@ -178,7 +178,7 @@ describe('PathKit\'s Path Behavior', function() {

path.delete();
done();
});
}));
});
});

Expand Down
20 changes: 10 additions & 10 deletions modules/pathkit/tests/path2d.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('PathKit\'s Path2D API', function() {
});

it('can do everything in the Path2D API w/o crashing', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
// This is taken from example.html
let path = PathKit.NewPath();

Expand Down Expand Up @@ -85,11 +85,11 @@ describe('PathKit\'s Path2D API', function() {
done();
}).catch(reportError(done));
}).catch(reportError(done));
});
}));
});

it('can chain by returning the same object', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let path = PathKit.NewPath();

let p1 = path.moveTo(20, 5)
Expand All @@ -109,11 +109,11 @@ describe('PathKit\'s Path2D API', function() {
// all is well
}
done();
});
}));
});

it('does not leak path objects when chaining', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
// By default, we have 16 MB of memory assigned to our PathKit
// library. This can be configured by -S TOTAL_MEMORY=NN
// and defaults to 16MB (we likely don't need to touch this).
Expand All @@ -129,7 +129,7 @@ describe('PathKit\'s Path2D API', function() {
path.delete();
}
done();
});
}));
});

function drawTriangle() {
Expand All @@ -142,7 +142,7 @@ describe('PathKit\'s Path2D API', function() {
}

it('has multiple overloads of addPath', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let basePath = PathKit.NewPath();
let otherPath = drawTriangle();
// These add path call can be chained.
Expand All @@ -159,11 +159,11 @@ describe('PathKit\'s Path2D API', function() {
reportPath(basePath, 'add_path_3x', done);
basePath.delete();
otherPath.delete();
});
}));
});

it('approximates arcs (conics) with quads', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
let path = PathKit.NewPath();
path.moveTo(50, 120);
path.arc(50, 120, 45, 0, 1.75 * Math.PI);
Expand All @@ -187,7 +187,7 @@ describe('PathKit\'s Path2D API', function() {
reportCanvas(canvas, 'conics_quads_approx').then(() => {
done();
}).catch(reportError(done));
});
}));
});

});
26 changes: 13 additions & 13 deletions modules/pathkit/tests/pathops.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ describe('PathKit\'s PathOps Behavior', function() {
}).then((_PathKit) => {
PathKit = _PathKit;
PATHOP_MAP = {
'kIntersect_SkPathOp':PathKit.PathOp.INTERSECT,
'kDifference_SkPathOp':PathKit.PathOp.DIFFERENCE,
'kUnion_SkPathOp': PathKit.PathOp.UNION,
'kXOR_SkPathOp': PathKit.PathOp.XOR,
'kXOR_PathOp': PathKit.PathOp.XOR,
'kIntersect_SkPathOp': PathKit.PathOp.INTERSECT,
'kDifference_SkPathOp': PathKit.PathOp.DIFFERENCE,
'kUnion_SkPathOp': PathKit.PathOp.UNION,
'kXOR_SkPathOp': PathKit.PathOp.XOR,
'kXOR_PathOp': PathKit.PathOp.XOR,
'kReverseDifference_SkPathOp': PathKit.PathOp.REVERSE_DIFFERENCE,
};
FILLTYPE_MAP = {
'kWinding_FillType':PathKit.FillType.WINDING,
'kEvenOdd_FillType':PathKit.FillType.EVENODD,
'kWinding_FillType': PathKit.FillType.WINDING,
'kEvenOdd_FillType': PathKit.FillType.EVENODD,
'kInverseWinding_FillType': PathKit.FillType.INVERSE_WINDING,
'kInverseEvenOdd_FillType': PathKit.FillType.INVERSE_EVENODD,
};
Expand All @@ -118,11 +118,11 @@ describe('PathKit\'s PathOps Behavior', function() {
}

it('combines two paths with .op() and matches what we see from C++', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
// Test JSON created with:
// ./out/Clang/pathops_unittest -J ./modules/pathkit/tests/PathOpsOp.json -m PathOpsOp$
fetch('/base/tests/PathOpsOp.json').then((r) => {
r.json().then((json)=>{
r.json().then((json) => {
expect(json).toBeTruthy();
let testNames = Object.keys(json);
// Assert we loaded a non-zero amount of tests, i.e. the JSON is valid.
Expand Down Expand Up @@ -172,15 +172,15 @@ describe('PathKit\'s PathOps Behavior', function() {
done();
});
});
});
}));
});

it('simplifies a path with .simplify() and matches what we see from C++', function(done) {
LoadPathKit.then(() => {
LoadPathKit.then(catchException(done, () => {
// Test JSON created with:
// ./out/Clang/pathops_unittest -J ./modules/pathkit/tests/PathOpsSimplify.json -m PathOpsSimplify$
fetch('/base/tests/PathOpsSimplify.json').then((r) => {
r.json().then((json)=>{
r.json().then((json) => {
expect(json).toBeTruthy();
let testNames = Object.keys(json);
// Assert we loaded a non-zero amount of tests, i.e. the JSON is valid.
Expand Down Expand Up @@ -225,6 +225,6 @@ describe('PathKit\'s PathOps Behavior', function() {
done();
});
});
});
}));
});
});
Loading

0 comments on commit e71e9ef

Please sign in to comment.