From ff9bd3acecc2e1a8a7e73cf2fa186598197395e3 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin@gmail.com>
Date: Mon, 29 Jul 2019 14:50:20 -0700
Subject: Make sure binaryen.js tests validate (#2269)

Without `assert`, even if a test does not validate, the errors will only
show up in its corresponding `.txt` file while the test will succeed.
This makes sure it errors out when a test fails to validate. This also
adds validation checks if there is none.
---
 test/binaryen.js/optimize-levels.js | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

(limited to 'test/binaryen.js/optimize-levels.js')

diff --git a/test/binaryen.js/optimize-levels.js b/test/binaryen.js/optimize-levels.js
index f4fc998e2..e42bd5409 100644
--- a/test/binaryen.js/optimize-levels.js
+++ b/test/binaryen.js/optimize-levels.js
@@ -1,3 +1,7 @@
+function assert(x) {
+  if (!x) throw 'error!';
+}
+
 var wast = `
 (module
  (type $i (func (param i32) (result i32)))
@@ -25,13 +29,13 @@ function printOptions() {
 var module = Binaryen.parseText(wast);
 
 console.log("=== unoptimized ===");
-module.validate();
+assert(module.validate());
 console.log(module.emitText());
 
 module.optimize();
 console.log("=== optimized using defaults ===");
 printOptions();
-module.validate();
+assert(module.validate());
 console.log(module.emitText());
 module.dispose();
 
@@ -43,7 +47,7 @@ Binaryen.setShrinkLevel(0);
 module.optimize();
 console.log("=== optimized with -O0 ===");
 printOptions();
-module.validate();
+assert(module.validate());
 console.log(module.emitText());
 module.dispose();
 
@@ -55,6 +59,6 @@ Binaryen.setShrinkLevel(1);
 module.optimize();
 console.log("=== optimized with -Os ===");
 printOptions();
-module.validate();
+assert(module.validate());
 console.log(module.emitText());
 module.dispose();
-- 
cgit v1.2.3