mirror of
https://github.com/google/blockly.git
synced 2026-06-17 00:25:14 +02:00
Merge pull request #2111 from rachel-fenichel/feature/run_gen_tests_in_browser
Run generator tests on Travis
This commit is contained in:
+6
-3
@@ -9,9 +9,12 @@ matrix:
|
||||
apt:
|
||||
packages:
|
||||
- google-chrome-stable
|
||||
- os: osx
|
||||
node_js: stable
|
||||
osx_image: xcode8.3
|
||||
# TODO (#2114): reenable osx build.
|
||||
# - os: osx
|
||||
# node_js: stable
|
||||
# osx_image: xcode8.3
|
||||
# addons:
|
||||
# firefox: latest
|
||||
|
||||
before_script:
|
||||
# Symlink closure library used by test/jsunit
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+16
-16
@@ -3,25 +3,25 @@
|
||||
<field name="SUITE_NAME">Lists</field>
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test create"></mutation>
|
||||
<mutation name="test create lists"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test empty"></mutation>
|
||||
<mutation name="test lists empty"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test length"></mutation>
|
||||
<mutation name="test lists length"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test find simple"></mutation>
|
||||
<mutation name="test find lists simple"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test find complex"></mutation>
|
||||
<mutation name="test find lists complex"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test get simple"></mutation>
|
||||
<mutation name="test get lists simple"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test get complex"></mutation>
|
||||
<mutation name="test get lists complex"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test getRemove"></mutation>
|
||||
@@ -57,7 +57,7 @@
|
||||
<mutation name="test sort numeric"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test reverse"></mutation>
|
||||
<mutation name="test lists reverse"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
@@ -134,7 +134,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="713">
|
||||
<field name="NAME">test create</field>
|
||||
<field name="NAME">test create lists</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "create list with" and "create empty list" blocks.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
@@ -298,7 +298,7 @@
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1238">
|
||||
<field name="NAME">test empty</field>
|
||||
<field name="NAME">test lists empty</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "is empty" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
@@ -391,7 +391,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1563">
|
||||
<field name="NAME">test length</field>
|
||||
<field name="NAME">test lists length</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "length" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
@@ -525,7 +525,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1988">
|
||||
<field name="NAME">test find simple</field>
|
||||
<field name="NAME">test find lists simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "find" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set">
|
||||
@@ -697,7 +697,7 @@
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="2563">
|
||||
<field name="NAME">test find complex</field>
|
||||
<field name="NAME">test find lists complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "find" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set">
|
||||
@@ -1067,7 +1067,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="3738">
|
||||
<field name="NAME">test get simple</field>
|
||||
<field name="NAME">test get lists simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
@@ -1391,7 +1391,7 @@
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="4663">
|
||||
<field name="NAME">test get complex</field>
|
||||
<field name="NAME">test get lists complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
@@ -8138,7 +8138,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="20463">
|
||||
<field name="NAME">test reverse</field>
|
||||
<field name="NAME">test lists reverse</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "list reverse" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set">
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<field name="SUITE_NAME">Loops 2</field>
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test count"></mutation>
|
||||
<mutation name="test count loops"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test count by"></mutation>
|
||||
@@ -580,7 +580,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="29" y="184">
|
||||
<field name="NAME">test count</field>
|
||||
<field name="NAME">test count loops</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2018 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Node.js script to run generator tests in Firefox, via webdriver.
|
||||
*/
|
||||
var webdriverio = require('webdriverio');
|
||||
var fs = require('fs');
|
||||
|
||||
/**
|
||||
* Run the generator for a given language and save the results to a file.
|
||||
* @param {Thenable} browser A Thenable managing the processing of the browser
|
||||
* tests.
|
||||
* @param {string} filename Where to write the output file.
|
||||
* @param {Function} codegenFn The function to run for code generation for this
|
||||
* language.
|
||||
* @return the Thenable managing the processing of the browser tests.
|
||||
*/
|
||||
function runLangGeneratorInBrowser(browser, filename, codegenFn) {
|
||||
return browser
|
||||
.pause(5000)
|
||||
.then(function() {
|
||||
this.execute(codegenFn)
|
||||
})
|
||||
.pause(10000)
|
||||
.getValue("#importExport")
|
||||
.then(function(result) {
|
||||
fs.writeFile(filename, result, function(err) {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the generator tests in Firefox. It uses webdriverio to
|
||||
* launch Firefox and load index.html. Outputs a summary of the test results
|
||||
* to the console and outputs files for later validation.
|
||||
* @return the Thenable managing the processing of the browser tests.
|
||||
*/
|
||||
function runGeneratorsInBrowser() {
|
||||
var options = {
|
||||
desiredCapabilities: {
|
||||
browserName: 'firefox'
|
||||
}
|
||||
};
|
||||
|
||||
var url = 'file://' + __dirname + '/index.html';
|
||||
var prefix = 'tests/generators/tmp/generated'
|
||||
console.log('Starting webdriverio...');
|
||||
return webdriverio
|
||||
.remote(options)
|
||||
.init()
|
||||
.then(function() {
|
||||
console.log('Initialized.\nLoading url: ' + url);
|
||||
})
|
||||
.url(url)
|
||||
.then(function() {
|
||||
console.log('about to load');
|
||||
this.execute(function() {
|
||||
checkAll();
|
||||
loadSelected();
|
||||
})
|
||||
})
|
||||
.pause(10000)
|
||||
.then(function() {
|
||||
return runLangGeneratorInBrowser(this, prefix + '.js', function() {
|
||||
toJavaScript();
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runLangGeneratorInBrowser(this, prefix + '.py', function() {
|
||||
toPython();
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runLangGeneratorInBrowser(this, prefix + '.dart', function() {
|
||||
toDart();
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runLangGeneratorInBrowser(this, prefix + '.lua', function() {
|
||||
toLua();
|
||||
});
|
||||
})
|
||||
.then(function() {
|
||||
return runLangGeneratorInBrowser(this, prefix + '.php', function() {
|
||||
toPhp();
|
||||
});
|
||||
})
|
||||
.pause(10000)
|
||||
.catch(function(e) {
|
||||
console.error('Error: ', e);
|
||||
|
||||
if (require.main === module) {
|
||||
// .catch() doesn't seem to work in the calling code,
|
||||
// even if the error is rethrown. To ensure the script
|
||||
// exit code is non-zero, shutdown the process here.
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// WARNING: Catching this outside of runJsUnitTestsInBrowser() is not
|
||||
// working. However, killing the process doesn't seem good, either.
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = runGeneratorsInBrowser;
|
||||
|
||||
if (require.main === module) {
|
||||
try {
|
||||
runGeneratorsInBrowser()
|
||||
.catch(function(e) {
|
||||
// TODO: Never called during errors. Fix.
|
||||
console.error('Error: ' + e);
|
||||
process.exit(1);
|
||||
})
|
||||
.endAll()
|
||||
.then(function() {
|
||||
console.log('JSUnit tests completed');
|
||||
process.exit(0);
|
||||
});
|
||||
} catch(e) {
|
||||
console.error('Uncaught error: ', e);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
+18
-18
@@ -3,28 +3,28 @@
|
||||
<field name="SUITE_NAME">Text</field>
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test length"></mutation>
|
||||
<mutation name="test text length"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test empty"></mutation>
|
||||
<mutation name="test empty text"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test create"></mutation>
|
||||
<mutation name="test create text"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test append"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test find simple"></mutation>
|
||||
<mutation name="test find text simple"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test find complex"></mutation>
|
||||
<mutation name="test find text complex"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test get simple"></mutation>
|
||||
<mutation name="test get text simple"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test get complex"></mutation>
|
||||
<mutation name="test get text complex"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test substring simple"></mutation>
|
||||
@@ -39,10 +39,10 @@
|
||||
<mutation name="test trim"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test count"></mutation>
|
||||
<mutation name="test count text"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test reverse"></mutation>
|
||||
<mutation name="test text reverse"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test replace"></mutation>
|
||||
@@ -114,7 +114,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="563">
|
||||
<field name="NAME">test create</field>
|
||||
<field name="NAME">test create text</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "create text with" block with varying number of inputs.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
@@ -333,7 +333,7 @@
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1338">
|
||||
<field name="NAME">test empty</field>
|
||||
<field name="NAME">test empty text</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "is empty" block".</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
@@ -425,7 +425,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="1663">
|
||||
<field name="NAME">test length</field>
|
||||
<field name="NAME">test text length</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "length" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
@@ -643,7 +643,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="2438">
|
||||
<field name="NAME">test find simple</field>
|
||||
<field name="NAME">test find text simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "find" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
@@ -775,7 +775,7 @@
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="2938">
|
||||
<field name="NAME">test find complex</field>
|
||||
<field name="NAME">test find text complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "find" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set">
|
||||
@@ -1145,7 +1145,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="4013">
|
||||
<field name="NAME">test get simple</field>
|
||||
<field name="NAME">test get text simple</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get letter" block with a variable.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
@@ -1432,7 +1432,7 @@
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="4938">
|
||||
<field name="NAME">test get complex</field>
|
||||
<field name="NAME">test get text complex</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "get letter" block with a function call.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
@@ -4108,7 +4108,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="12088">
|
||||
<field name="NAME">test count</field>
|
||||
<field name="NAME">test count text</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "trim" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set">
|
||||
@@ -4318,7 +4318,7 @@
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="12" y="12812">
|
||||
<field name="NAME">test reverse</field>
|
||||
<field name="NAME">test text reverse</field>
|
||||
<comment pinned="false" h="80" w="160">Tests the "trim" block.</comment>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
|
||||
@@ -49,7 +49,7 @@ run_test_command () {
|
||||
fi
|
||||
}
|
||||
|
||||
# Setup the environment (Chrome, Selenium, etc.)
|
||||
# Set up the environment (Chrome, Selenium, etc.)
|
||||
run_test_command "test_setup" "tests/scripts/test_setup.sh"
|
||||
|
||||
# Lint the codebase.
|
||||
@@ -59,8 +59,11 @@ run_test_command "eslint" "eslint ."
|
||||
run_test_command "jsunit" "node tests/jsunit/run_jsunit_tests_in_browser.js"
|
||||
# TODO: Make sure jsunit output is captured. Child process?
|
||||
|
||||
# Attempt advanced compilation of a Blockly app.
|
||||
run_test_command "compile" "tests/compile/compile.sh"
|
||||
# Run generator tests inside a browser and check the results.
|
||||
run_test_command "generators" "tests/scripts/run_generators.sh"
|
||||
|
||||
# # Attempt advanced compilation of a Blockly app.
|
||||
# run_test_command "compile" "tests/compile/compile.sh"
|
||||
|
||||
|
||||
# End of tests.
|
||||
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ANSI colors
|
||||
BOLD_GREEN='\033[1;32m'
|
||||
BOLD_RED='\033[1;31m'
|
||||
ANSI_RESET='\033[0m'
|
||||
SUCCESS_PREFIX="${BOLD_GREEN}SUCCESS:${ANSI_RESET}"
|
||||
FAILURE_PREFIX="${BOLD_RED}FAILED:${ANSI_RESET}"
|
||||
|
||||
TMP_DIR="tests/generators/tmp/"
|
||||
GOLDEN_DIR="tests/generators/golden/"
|
||||
|
||||
FAILURE_COUNT=0
|
||||
check_result() {
|
||||
local suffix=$1 # One of: js, py, dart, lua, php
|
||||
local tmp_filename="${TMP_DIR}generated.$suffix"
|
||||
|
||||
if [ -f $tmp_filename ]; then
|
||||
local golden_filename="${GOLDEN_DIR}generated.$suffix"
|
||||
if [ -f $golden_filename ]; then
|
||||
if cmp --silent $tmp_filename $golden_filename; then
|
||||
echo -e "$SUCCESS_PREFIX $suffix: $tmp_filename matches $golden_filename"
|
||||
else
|
||||
echo -e "$FAILURE_PREFIX $suffix: $tmp_filename does not match $golden_filename"
|
||||
FAILURE_COUNT=$((FAILURE_COUNT+1))
|
||||
fi
|
||||
else
|
||||
echo "File $golden_filename not found!"
|
||||
FAILURE_COUNT=$((FAILURE_COUNT+1))
|
||||
fi
|
||||
else
|
||||
echo "File $tmp_filename not found!"
|
||||
FAILURE_COUNT=$((FAILURE_COUNT+1))
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
mkdir $TMP_DIR
|
||||
|
||||
node tests/generators/run_generators_in_browser.js
|
||||
generator_suffixes=( "js" "py" "dart" "lua" "php" )
|
||||
for i in "${generator_suffixes[@]}"
|
||||
do
|
||||
check_result "$i"
|
||||
done
|
||||
|
||||
|
||||
# Clean up.
|
||||
rm -r $TMP_DIR
|
||||
|
||||
if [ "$FAILURE_COUNT" -eq "0" ]; then
|
||||
echo -e "${BOLD_GREEN}All generator tests passed.${ANSI_RESET}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "${BOLD_RED}Failures in ${FAILURE_COUNT} generator tests.${ANSI_RESET}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user