forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated rollback of commit 72de1fe6bafa28fddcbc8cdc1ccbb59556996bfb.
*** Reason for rollback *** Roll-forward with fix *** Original change description *** Automated rollback of commit f5b8281f1f7599c67476663887db909a4206710e. *** Reason for rollback *** Read the wrong log, it is not timing out, actual failure. *** Original change description *** Open-source src/test/skylark/... This was means to be open-sourced from the beginning but an error in our set-up hide it from the open-source tree. PiperOrigin-RevId: 168526758
- Loading branch information
Showing
8 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
load( | ||
"//tools/build_rules:test_rules.bzl", | ||
"rule_test", | ||
"file_test", | ||
) | ||
|
||
package(default_visibility = ["//src:__subpackages__"]) | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = glob( | ||
["**"], | ||
exclude = ["testenv.py"], | ||
), | ||
) | ||
|
||
py_test( | ||
name = "skylark_test", | ||
srcs = [ | ||
"skylark_test.py", | ||
"testenv.py", | ||
], | ||
data = ["//src/main/java/com/google/devtools/skylark:Skylark"] + glob([ | ||
"testdata/*", | ||
]), | ||
) | ||
|
||
## Rest of the file should be moved somewhere else (under bazel/tools/). | ||
|
||
genrule( | ||
name = "tone_below", | ||
outs = [ | ||
"g1", | ||
"g2", | ||
], | ||
cmd = "echo 48.9994 > $(location :g1) ; echo 97.9989 > $(location :g2)", | ||
) | ||
|
||
rule_test( | ||
name = "assert_tone_below_1", | ||
generates = [ | ||
"g1", | ||
"g2", | ||
], | ||
rule = "tone_below", | ||
) | ||
|
||
file_test( | ||
name = "question_content", | ||
content = ("If you could ask a unique question to a computer during a Turing test, " + | ||
"what would you ask?\n"), | ||
file = "question.text", | ||
) | ||
|
||
file_test( | ||
name = "question_regexp", | ||
file = "question.text", | ||
regexp = "[eu]n[uchs questi]\\+on", | ||
) | ||
|
||
file_test( | ||
name = "question_regexp_1", | ||
file = "question.text", | ||
matches = 1, | ||
regexp = "what would you ask", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
If you could ask a unique question to a computer during a Turing test, what would you ask? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2017 The Bazel Authors. All rights reserved. | ||
# | ||
# 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. | ||
|
||
import os.path | ||
import subprocess | ||
import unittest | ||
|
||
from src.test.skylark import testenv | ||
|
||
|
||
class SkylarkTest(unittest.TestCase): | ||
|
||
def testSuccess(self): | ||
tests = ["int.sky", "equality.sky", "and_or_not.sky"] | ||
for t in tests: | ||
print subprocess.check_output( | ||
[testenv.SKYLARK_BINARY_PATH, | ||
os.path.join(testenv.SKYLARK_TESTDATA_PATH, t)]) | ||
|
||
# TODO(laurentlb): Add support for negative tests (e.g. syntax errors). | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
def assert_eq(x, y): | ||
if x != y: | ||
fail("%r != %r" % (x, y)) | ||
|
||
|
||
assert_eq(8 or 9, 8) | ||
assert_eq(0 or 9, 9) | ||
assert_eq(8 and 9, 9) | ||
assert_eq(0 and 9, 0) | ||
|
||
assert_eq(1 and 2 or 3, 2) | ||
assert_eq(0 and 2 or 3, 3) | ||
assert_eq(1 and 0 or 3, 3) | ||
|
||
assert_eq(1 or 2 and 3, 1) | ||
assert_eq(0 or 2 and 3, 3) | ||
assert_eq(0 or 0 and 3, 0) | ||
assert_eq(1 or 0 and 3, 1) | ||
|
||
assert_eq(None and 1, None) | ||
assert_eq("" or 9, 9) | ||
assert_eq("abc" or 9, "abc") | ||
|
||
# check that fail() is not evaluated | ||
assert_eq(8 or fail("do not execute"), 8) | ||
assert_eq(0 and fail("do not execute"), 0) | ||
|
||
assert_eq(not 1, False) | ||
assert_eq(not "", True) | ||
|
||
assert_eq(not 0 + 0, True) | ||
assert_eq(not 2 - 1, False) | ||
|
||
assert_eq(not (0 and 0), True) | ||
assert_eq(not (1 or 0), False) | ||
|
||
assert_eq(0 and not 0, 0) | ||
assert_eq(not 0 and 0, 0) | ||
|
||
assert_eq(1 and not 0, True) | ||
assert_eq(not 0 or 0, True) | ||
|
||
assert_eq(not 1 or 0, 0) | ||
assert_eq(not 1 or 1, 1) | ||
|
||
assert_eq(not [], True) | ||
assert_eq(not {"a": 1}, False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
def assert_eq(x, y): | ||
if x != y: | ||
fail("%r != %r" % (x, y)) | ||
|
||
|
||
# == operator | ||
assert_eq(1 == 1, True) | ||
assert_eq(1 == 2, False) | ||
assert_eq('hello' == 'hel' + 'lo', True) | ||
assert_eq('hello' == 'bye', False) | ||
assert_eq(None == None, True) | ||
assert_eq([1, 2] == [1, 2], True) | ||
assert_eq([1, 2] == [2, 1], False) | ||
assert_eq({'a': 1, 'b': 2} == {'b': 2, 'a': 1}, True) | ||
assert_eq({'a': 1, 'b': 2} == {'a': 1}, False) | ||
assert_eq({'a': 1, 'b': 2} == {'a': 1, 'b': 2, 'c': 3}, False) | ||
assert_eq({'a': 1, 'b': 2} == {'a': 1, 'b': 3}, False) | ||
|
||
# != operator | ||
assert_eq(1 != 1, False) | ||
assert_eq(1 != 2, True) | ||
assert_eq('hello' != 'hel' + 'lo', False) | ||
assert_eq('hello' != 'bye', True) | ||
assert_eq([1, 2] != [1, 2], False) | ||
assert_eq([1, 2] != [2, 1], True) | ||
assert_eq({'a': 1, 'b': 2} != {'b': 2, 'a': 1}, False) | ||
assert_eq({'a': 1, 'b': 2} != {'a': 1}, True) | ||
assert_eq({'a': 1, 'b': 2} != {'a': 1, 'b': 2, 'c': 3}, True) | ||
assert_eq({'a': 1, 'b': 2} != {'a': 1, 'b': 3}, True); | ||
|
||
# equality precedence | ||
assert_eq(1 + 3 == 2 + 2, True) | ||
assert_eq(not 1 == 2, True) | ||
assert_eq(not 1 != 2, False) | ||
assert_eq(2 and 3 == 3 or 1, True) | ||
assert_eq(2 or 3 == 3 and 1, 2); | ||
|
||
# < operator | ||
assert_eq(1 <= 1, True) | ||
assert_eq(1 < 1, False) | ||
assert_eq('a' <= 'b', True) | ||
assert_eq('c' < 'a', False); | ||
|
||
# <= and < operators | ||
assert_eq(1 <= 1, True) | ||
assert_eq(1 < 1, False) | ||
assert_eq('a' <= 'b', True) | ||
assert_eq('c' < 'a', False); | ||
|
||
# >= and > operators | ||
assert_eq(1 >= 1, True) | ||
assert_eq(1 > 1, False) | ||
assert_eq('a' >= 'b', False) | ||
assert_eq('c' > 'a', True); | ||
|
||
# list/tuple comparison | ||
assert_eq([] < [1], True) | ||
assert_eq([1] < [1, 1], True) | ||
assert_eq([1, 1] < [1, 2], True) | ||
assert_eq([1, 2] < [1, 2, 3], True) | ||
assert_eq([1, 2, 3] <= [1, 2, 3], True) | ||
|
||
assert_eq(['a', 'b'] > ['a'], True) | ||
assert_eq(['a', 'b'] >= ['a'], True) | ||
assert_eq(['a', 'b'] < ['a'], False) | ||
assert_eq(['a', 'b'] <= ['a'], False) | ||
|
||
assert_eq(('a', 'b') > ('a', 'b'), False) | ||
assert_eq(('a', 'b') >= ('a', 'b'), True) | ||
assert_eq(('a', 'b') < ('a', 'b'), False) | ||
assert_eq(('a', 'b') <= ('a', 'b'), True) | ||
|
||
assert_eq([[1, 1]] > [[1, 1], []], False) | ||
assert_eq([[1, 1]] < [[1, 1], []], True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Tests of Skylark 'int' | ||
|
||
def assert_eq(x, y): | ||
if x != y: | ||
fail("%r != %r" % (x, y)) | ||
|
||
def assert_(cond, msg="assertion failed"): | ||
if not cond: | ||
fail(msg) | ||
|
||
# basic arithmetic | ||
assert_eq(0 - 1, -1) | ||
assert_eq(1 + 1, 2) | ||
assert_eq(5 + 7, 12) | ||
assert_eq(5 * 7, 35) | ||
assert_eq(5 - 7, -2) | ||
|
||
# truth | ||
assert_(123) | ||
assert_(-1) | ||
assert_(not 0) | ||
|
||
# comparisons | ||
assert_(5 > 2) | ||
assert_(2 + 1 == 3) | ||
assert_(2 + 1 >= 3) | ||
assert_(not (2 + 1 > 3)) | ||
assert_(2 + 2 <= 5) | ||
assert_(not (2 + 1 < 3)) | ||
|
||
# division | ||
assert_eq(100 // 7, 14) | ||
assert_eq(100 // -7, -15) | ||
assert_eq(-100 // 7, -15) # NB: different from Go / Java | ||
assert_eq(-100 // -7, 14) # NB: different from Go / Java | ||
assert_eq(98 // 7, 14) | ||
assert_eq(98 // -7, -14) | ||
assert_eq(-98 // 7, -14) | ||
assert_eq(-98 // -7, 14) | ||
|
||
# remainder | ||
assert_eq(100 % 7, 2) | ||
assert_eq(100 % -7, -5) # NB: different from Go / Java | ||
assert_eq(-100 % 7, 5) # NB: different from Go / Java | ||
assert_eq(-100 % -7, -2) | ||
assert_eq(98 % 7, 0) | ||
assert_eq(98 % -7, 0) | ||
assert_eq(-98 % 7, 0) | ||
assert_eq(-98 % -7, 0) | ||
|
||
# precedence | ||
assert_eq(5 - 7 * 2 + 3, -6) | ||
assert_eq(4 * 5 / 2 + 5 / 2 * 4, 18) | ||
|
||
# compound assignment | ||
def compound(): | ||
x = 1 | ||
x += 1 | ||
assert_eq(x, 2) | ||
x -= 3 | ||
assert_eq(x, -1) | ||
x *= 10 | ||
assert_eq(x, -10) | ||
x /= -2 | ||
assert_eq(x, 5) | ||
x %= 3 | ||
assert_eq(x, 2) | ||
|
||
compound() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2017 The Bazel Authors. All rights reserved. | ||
# | ||
# 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. | ||
"""Test constants for src/test/skylark.""" | ||
|
||
SKYLARK_BINARY_PATH = "src/main/java/com/google/devtools/skylark/Skylark" | ||
SKYLARK_TESTDATA_PATH = "src/test/skylark/testdata/" |