-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
The inline test framework incorrectly modifies the target statement when extracting tests for array element assignments. Instead of preserving the array indexing operation, it transforms array elements into flattened variable names, causing compilation issues.
For example, given the following code with inline tests:
private static final int[] MAX_SIZES
MAX_SIZES[i] = MAX_SIZES[i - 1] << 1; // target statement
itest("", 1).given(i, 2).given(MAX_SIZES, new int[]{1, 10, 2}).checkEq(MAX_SIZES[0], 1).checkEq(MAX_SIZES[1], 10).checkEq(MAX_SIZES[2], 20);
itest("", 2).given(MAX_SIZES[i - 1], 10).checkEq(MAX_SIZES[i], 20);The framework generates:
@Test
void testLine1() throws Exception {
int i = 2;
int[] MAX_SIZES = new int[] { 1, 10, 2 };
int MAX_SIZES__i = MAX_SIZES__i << 1; // Wrong variable, should be: MAX_SIZES[i] = MAX_SIZES[i - 1] << 1
assertEquals(1, MAX_SIZES__i); // Wrong variable, should be assertEquals(1, MAX_SIZES[0])
assertEquals(10, MAX_SIZES__i); // Wrong variable, should be assertEquals(10, MAX_SIZES[1])
assertEquals(20, MAX_SIZES__i); // Wrong variable, should be assertEquals(20, MAX_SIZES[2])
}
@Test
void testLine2() throws Exception {
int MAX_SIZES__iminus1 = 10;
int MAX_SIZES__i = MAX_SIZES__i << 1; // Wrong variable, should be: int MAX_SIZES__i = MAX_SIZES__iminus1 << 1;
assertEquals(20, MAX_SIZES__i);
}and the test code will not compile.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels