| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Run this to automatically create a new auto_test. Example: |
| 4 | # |
| 5 | # ./auto_tests/misc/new_test.sh axis-labels |
| 6 | # |
| 7 | # This will produce a new file in auto_tests/tests/axis_labels.js including |
| 8 | # |
| 9 | # var AxisLabelsTestCase = TestCase("axis-labels"); |
| 10 | # ... |
| 11 | # |
| 12 | # It will also add a reference to this file to auto_tests/misc/local.html. |
| 13 | |
| 14 | set -o errexit |
| 15 | if [ -z $1 ]; then |
| 16 | echo Usage: $0 test-case-name-with-dashes |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | dashed_name=$1 |
| 21 | underscore_name=$(echo $1 | sed 's/-/_/g') |
| 22 | camelCaseName=$(echo $1 | perl -pe 's/-([a-z])/uc $1/ge') |
| 23 | testCaseName=${camelCaseName}TestCase |
| 24 | |
| 25 | test_file=auto_tests/tests/$underscore_name.js |
| 26 | |
| 27 | if [ -f $test_file ]; then |
| 28 | echo $test_file already exists |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | cat <<END > $test_file; |
| 33 | /** |
| 34 | * @fileoverview FILL THIS IN |
| 35 | * |
| 36 | * @author $(git config --get user.email) ($(git config --get user.name)) |
| 37 | */ |
| 38 | var $testCaseName = TestCase("$dashed_name"); |
| 39 | |
| 40 | $testCaseName.prototype.setUp = function() { |
| 41 | document.body.innerHTML = "<div id='graph'></div>"; |
| 42 | }; |
| 43 | |
| 44 | $testCaseName.prototype.tearDown = function() { |
| 45 | }; |
| 46 | |
| 47 | $testCaseName.prototype.testNameGoesHere = function() { |
| 48 | var opts = { |
| 49 | width: 480, |
| 50 | height: 320 |
| 51 | }; |
| 52 | var data = "X,Y\n" + |
| 53 | "0,-1\n" + |
| 54 | "1,0\n" + |
| 55 | "2,1\n" + |
| 56 | "3,0\n" |
| 57 | ; |
| 58 | |
| 59 | var graph = document.getElementById("graph"); |
| 60 | var g = new Dygraph(graph, data, opts); |
| 61 | |
| 62 | ... |
| 63 | assertEquals(1, 1); |
| 64 | }; |
| 65 | |
| 66 | END |
| 67 | |
| 68 | perl -pi -e 'next unless /update_options.js/; print " <script type=\"text/javascript\" src=\"../tests/'$underscore_name'.js\"></script>\n"' auto_tests/misc/local.html |
| 69 | |
| 70 | echo Wrote test to $test_file |