Merge pull request #2085 from rachel-fenichel/feature/generator_tests_checkbox

Generator test improvements
This commit is contained in:
Rachel Fenichel
2018-10-19 10:14:00 -07:00
committed by GitHub
17 changed files with 99 additions and 40 deletions

View File

@@ -60,6 +60,7 @@
</statement>
</block>
<block type="unittest_main" x="-5" y="49">
<field name="SUITE_NAME">Colour</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test colour picker"></mutation>

View File

@@ -1,6 +1,7 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<!-- Do not include <variables> here to test backward compatibility. -->
<block type="unittest_main" x="0" y="1">
<field name="SUITE_NAME">Functions</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test procedure"></mutation>

View File

@@ -91,7 +91,7 @@ function start() {
}
/*
* Run this test to load all of the test files in all_test_names. The contents
* Run this test to load all of the tests in the selected suites. The contents
* will be loaded into the workspace in order. To test the generators:
* - select your language from the buttons above the text area
* - copy all of the generated code
@@ -101,20 +101,26 @@ function start() {
* If some tests are failing, load test suites individually to continue
* debugging.
*/
function loadAll() {
function loadSelected() {
var output = document.getElementById('importExport');
output.style.background = 'gray';
var loadingElem = document.getElementById('loading');
loadingElem.textContent = 'loading...';
var options = document.getElementById('testUrl').options;
for (var i = 0; i < options.length; i++) {
var testUrl = options[i].value;
if (testUrl) {
var xmlText = fetchFile(testUrl);
if (xmlText !== null) {
fromXml(testUrl, xmlText, /* opt_append */ true);
// Clear before adding all of the blocks.
demoWorkspace.clear();
var boxList = document.getElementById('checkboxes');
var inputChildren = boxList.getElementsByTagName('input');
for (var i = 0; i < inputChildren.length; i++) {
if (inputChildren[i].checked) {
var testUrl = inputChildren[i].value;
if (testUrl) {
var xmlText = fetchFile(testUrl);
if (xmlText !== null) {
fromXml(testUrl, xmlText, /* opt_append */ true);
}
}
}
}
@@ -122,14 +128,13 @@ function loadAll() {
loadingElem.textContent = 'done';
}
function loadXml() {
var dropdown = document.getElementById('testUrl');
var url = dropdown.options[dropdown.selectedIndex].value;
/**
* Ask the user for a file name, then load that file's contents.
*/
function loadOther() {
var url = window.prompt('Enter URL of test file.');
if (!url) {
url = window.prompt('Enter URL of test file.');
if (!url) {
return;
}
return;
}
var xmlText = fetchFile(url);
if (xmlText !== null) {
@@ -189,6 +194,22 @@ function fromXml(filename, xmlText, opt_append) {
}
}
function checkAll() {
var boxList = document.getElementById('checkboxes');
var inputChildren = boxList.getElementsByTagName('input');
for (var i = 0; i < inputChildren.length; i++) {
inputChildren[i].checked = true;
}
}
function uncheckAll() {
var boxList = document.getElementById('checkboxes');
var inputChildren = boxList.getElementsByTagName('input');
for (var i = 0; i < inputChildren.length; i++) {
inputChildren[i].checked = false;
}
}
function setOutput(text) {
var output = document.getElementById('importExport');
output.value = text;
@@ -369,26 +390,28 @@ h1 {
<p><a href="https://developers.google.com/blockly/guides/modify/web/unit-testing">See the docs</a> for details on running the tests.
<p>
<select id="testUrl">
<option value="logic.xml">Logic</option>
<option value="loops1.xml">Loops 1 (repeat, while, foreach)</option>
<option value="loops2.xml">Loops 2 (count)</option>
<option value="loops3.xml">Loops 3 (continue, break)</option>
<option value="math.xml">Math</option>
<option value="text.xml">Text</option>
<option value="lists.xml">Lists</option>
<option value="colour.xml">Colour</option>
<option value="variables.xml">Variables</option>
<option value="functions.xml">Functions</option>
<option value="">Other...</option>
</select>
<input type="button" value="Load" onclick="loadXml()">
</p>
<div id="checkboxes">
<input type="button" value="Check all" onclick="checkAll()">
<input type="button" value="Uncheck all" onclick="uncheckAll()"><br/>
<input type="checkbox" value="logic.xml">Logic</input><br/>
<input type="checkbox" value="loops1.xml">Loops 1 (repeat, while, foreach)</input><br/>
<input type="checkbox" value="loops2.xml">Loops 2 (count)</input><br/>
<input type="checkbox" value="loops3.xml">Loops 3 (continue, break)</input><br/>
<input type="checkbox" value="math.xml">Math</input><br/>
<input type="checkbox" value="text.xml">Text</input><br/>
<input type="checkbox" value="lists.xml">Lists</input><br/>
<input type="checkbox" value="colour.xml">Colour</input><br/>
<input type="checkbox" value="variables.xml">Variables</input><br/>
<input type="checkbox" value="functions.xml">Functions</input><br/>
</div>
<p>
<input type="button" value="Load all" id="loadAllBtn" onclick="loadAll()">
<label for="loadAllBtn" id="loading"></label>
<input type="button" value="Load selected" id="loadSelectedBtn" onclick="loadSelected()">
<label for="loadSelectedBtn" id="loading"></label>
</p>
<p>
<input type="button" value="Load by file name" onclick="loadOther()">
</p>
<p>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="13" y="13">
<field name="SUITE_NAME">Lists</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test create"></mutation>
@@ -8281,4 +8282,4 @@
</block>
</statement>
</block>
</xml>
</xml>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="-13" y="-13">
<field name="SUITE_NAME">Logic</field>
<statement name="DO">
<block type="unittest_assertvalue" inline="false">
<field name="EXPECTED">TRUE</field>
@@ -1015,4 +1016,4 @@
</block>
</statement>
</block>
</xml>
</xml>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="33" y="140">
<field name="SUITE_NAME">Loops 1</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test repeat"></mutation>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="66" y="-2">
<field name="SUITE_NAME">Loops 2</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test count"></mutation>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="19" y="106">
<field name="SUITE_NAME">Loops 3</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test break"></mutation>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="13" y="13">
<field name="SUITE_NAME">Math</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test arithmetic"></mutation>
@@ -1946,4 +1947,4 @@
</block>
</statement>
</block>
</xml>
</xml>

View File

@@ -1,5 +1,6 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="unittest_main" x="13" y="-63">
<field name="SUITE_NAME">Text</field>
<statement name="DO">
<block type="procedures_callnoreturn">
<mutation name="test length"></mutation>
@@ -4647,4 +4648,4 @@
</block>
</statement>
</block>
</xml>
</xml>

View File

@@ -29,7 +29,8 @@ Blockly.Blocks['unittest_main'] = {
init: function() {
this.setColour(65);
this.appendDummyInput()
.appendField('run tests');
.appendField('run test suite')
.appendField(new Blockly.FieldTextInput(''), 'SUITE_NAME');
this.appendStatementInput('DO');
this.setTooltip('Executes the enclosed unit tests,\n' +
'then prints a summary.');

View File

@@ -59,6 +59,11 @@ Blockly.Dart['unittest_main'] = function(block) {
'}']);
// Setup global to hold test results.
var code = resultsVar + ' = [];\n';
// Say which test suite this is.
code += 'print(\'\\n====================\\n\\n' +
'Running suite: ' +
block.getFieldValue('SUITE_NAME') +
'\');\n';
// Run tests (unindented).
code += Blockly.Dart.statementToCode(block, 'DO')
.replace(/^ /, '').replace(/\n /g, '\n');

View File

@@ -60,6 +60,11 @@ Blockly.JavaScript['unittest_main'] = function(block) {
'}']);
// Setup global to hold test results.
var code = resultsVar + ' = [];\n';
// Say which test suite this is.
code += 'console.log(\'\\n====================\\n\\n' +
'Running suite: ' +
block.getFieldValue('SUITE_NAME') +
'\')\n';
// Run tests (unindented).
code += Blockly.JavaScript.statementToCode(block, 'DO')
.replace(/^ /, '').replace(/\n /g, '\n');

View File

@@ -58,6 +58,11 @@ Blockly.Lua['unittest_main'] = function(block) {
'end']);
// Setup global to hold test results.
var code = resultsVar + ' = {}\n';
// Say which test suite this is.
code += 'print(\'\\n====================\\n\\n' +
'Running suite: ' +
block.getFieldValue('SUITE_NAME') +
'\')\n';
// Run tests (unindented).
code += Blockly.Lua.statementToCode(block, 'DO')
.replace(/^ /, '').replace(/\n /g, '\n');

View File

@@ -52,7 +52,7 @@ Blockly.PHP['unittest_main'] = function(block) {
' array_push($report, "Number of tests run: " . count(' + resultsVar + '));',
' array_push($report, "");',
' if ($fails) {',
' array_push($report, "FAILED (failures=" . $fails + ")");',
' array_push($report, "FAILED (failures=" . $fails . ")");',
' } else {',
' array_push($report, "OK");',
' }',
@@ -60,6 +60,11 @@ Blockly.PHP['unittest_main'] = function(block) {
'}']);
// Setup global to hold test results.
var code = resultsVar + ' = array();\n';
// Say which test suite this is.
code += 'print("\\n====================\\n\\n' +
'Running suite: ' +
block.getFieldValue('SUITE_NAME') +
'\\n");\n';
// Run tests (unindented).
code += Blockly.PHP.statementToCode(block, 'DO')
.replace(/^ /, '').replace(/\n /g, '\n');

View File

@@ -56,6 +56,11 @@ Blockly.Python['unittest_main'] = function(block) {
// Setup global to hold test results.
var code = resultsVar + ' = []\n';
// Say which test suite this is.
code += 'print(\'\\n====================\\n\\n' +
'Running suite: ' +
block.getFieldValue('SUITE_NAME') +
'\')\n';
// Run tests (unindented).
code += Blockly.Python.statementToCode(block, 'DO')
.replace(/^ /, '').replace(/\n /g, '\n');

View File

@@ -1,6 +1,7 @@
<xml xmlns="http://www.w3.org/1999/xhtml">
<!-- Do not include <variables> here to test backward compatibility. -->
<block type="unittest_main" x="0" y="0">
<field name="SUITE_NAME">Variables</field>
<statement name="DO">
<block type="variables_set" inline="false">
<field name="VAR">item</field>