mirror of
https://github.com/github/codeql.git
synced 2026-05-14 11:19:27 +02:00
These tests consist of various Python constructions (hopefully a somewhat comprehensive set) with specific timestamp annotations scattered throughout. When the tests are run using the Python 3 interpreter, these annotations are checked and compared to the "current timestamp" to see that they are in agreement. This is what makes the tests "self-validating". There are a few different kinds of annotations: the basic `t[4]` style (meaning this is executed at timestamp 4), the `t[dead(4)]` variant (meaning this _would_ happen at timestamp 4, but it is in a dead branch), and `t[never]` (meaning this is never executed at all). In addition to this, there is a query, MissingAnnotations, which checks whether we have applied these annotations maximally. Many expression nodes are not actually annotatable, so there is a sizeable list of excluded nodes for that query.
54 lines
791 B
Python
54 lines
791 B
Python
"""Augmented assignment evaluation order."""
|
|
|
|
from timer import test
|
|
|
|
|
|
@test
|
|
def test_plus_equals(t):
|
|
x = 1 @ t[0]
|
|
x += 2 @ t[1]
|
|
y = x @ t[2]
|
|
|
|
|
|
@test
|
|
def test_sub_mul_div(t):
|
|
x = 20 @ t[0]
|
|
x -= 5 @ t[1]
|
|
x *= 2 @ t[2]
|
|
x /= 6 @ t[3]
|
|
x = 17 @ t[4]
|
|
x //= 3 @ t[5]
|
|
x %= 3 @ t[6]
|
|
y = x @ t[7]
|
|
|
|
|
|
@test
|
|
def test_power_equals(t):
|
|
x = 2 @ t[0]
|
|
x **= 3 @ t[1]
|
|
y = x @ t[2]
|
|
|
|
|
|
@test
|
|
def test_bitwise_equals(t):
|
|
x = 0b1111 @ t[0]
|
|
x &= 0b1010 @ t[1]
|
|
x |= 0b0101 @ t[2]
|
|
x ^= 0b0011 @ t[3]
|
|
y = x @ t[4]
|
|
|
|
|
|
@test
|
|
def test_shift_equals(t):
|
|
x = 1 @ t[0]
|
|
x <<= 4 @ t[1]
|
|
x >>= 2 @ t[2]
|
|
y = x @ t[3]
|
|
|
|
|
|
@test
|
|
def test_list_extend(t):
|
|
x = [1 @ t[0], 2 @ t[1]] @ t[2]
|
|
x += [3 @ t[3], 4 @ t[4]] @ t[5]
|
|
y = x @ t[6]
|