| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #library('FrogServerTest'); | |
| 6 | |
| 7 #import('dart:io'); | |
| 8 | |
| 9 #import('../../server/frog_server.dart', prefix: 'frogserver'); | |
| 10 | |
| 11 // TODO(jmesserly): more sane way to import JSON on the VM | |
| 12 #import('../../../lib/json/json.dart'); | |
| 13 | |
| 14 main() { | |
| 15 // TODO(jmesserly): This test must be run from 'frog' working directory. | |
| 16 var homedir = new File('.').fullPathSync(); | |
| 17 print('test: setting Frog home directory to $homedir'); | |
| 18 | |
| 19 // Start the compiler server. 0 causes it to grab any free port. | |
| 20 var host = '127.0.0.1'; | |
| 21 var compileSocket = frogserver.startServer(homedir, host, 0); | |
| 22 | |
| 23 // Connect to the compiler | |
| 24 var testSocket = new Socket(host, compileSocket.port); | |
| 25 | |
| 26 final testId = 'abc' + new Date.now().value; | |
| 27 | |
| 28 var bytes = new List<int>(); | |
| 29 testSocket.onData = () { | |
| 30 var pos = bytes.length; | |
| 31 var len = testSocket.available(); | |
| 32 bytes.insertRange(pos, len); | |
| 33 testSocket.readList(bytes, pos, len); | |
| 34 var response = frogserver.tryReadJson(bytes); | |
| 35 if (response == null) return; // wait for more data | |
| 36 | |
| 37 // Verify ID | |
| 38 Expect.equals(testId, response['id']); | |
| 39 if (response['kind'] == 'message') { | |
| 40 // Info and warnings are okay. But we shouldn't get errors! | |
| 41 print('test: got message ${JSON.stringify(response)}'); | |
| 42 Expect.notEquals(null, response['message']); | |
| 43 Expect.notEquals('error', response['prefix']); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 Expect.equals('done', response['kind']); | |
| 48 Expect.equals('compile', response['command']); | |
| 49 Expect.equals(true, response['result']); | |
| 50 print('test: PASS. Compile successful!'); | |
| 51 | |
| 52 // Trigger a clean shutdown | |
| 53 frogserver.writeJson(testSocket.outputStream, { 'command': 'close' }); | |
| 54 testSocket.close(); | |
| 55 compileSocket.close(); | |
| 56 }; | |
| 57 | |
| 58 // Try a hello world compile | |
| 59 frogserver.writeJson(testSocket.outputStream, { | |
| 60 'command': 'compile', | |
| 61 'id': testId, | |
| 62 'input': 'tests/hello.dart' | |
| 63 // Note: intentionally don't specify 'output' so nothing is written to disk | |
| 64 }); | |
| 65 } | |
| OLD | NEW |