Skip to content

Commit

Permalink
Merge branch 'v0.17.x_bugfix' into v0.17.x
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Sep 27, 2018
2 parents adc1d27 + 5399c9d commit b976e94
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,7 @@ protected Object convertEncapsulatedValueToTargetType(Class<?> aTargetType, Clas
} else if (tempResult != null && tempResult.getClass().isArray()) {
// A slight variant of the collection case is an array (possibly filled with Integrity types)
// We just convert the individual elements in this case.
Object tempResultArray = Array.newInstance(tempResult.getClass().getComponentType(),
Array.getLength(tempResult));
Object tempResultArray = Array.newInstance(aTargetType, Array.getLength(tempResult));
for (int i = 0; i < Array.getLength(tempResult); i++) {
Array.set(tempResultArray, i, convertSingleValueToTargetType(aTargetType, aParameterizedType,
Array.get(tempResult, i), aConversionContext, someVisitedValues));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,10 @@ protected void initializeParameterizedConstants() {
String tempValue = (parameterizedConstantValues != null) ? parameterizedConstantValues.get(tempName)
: null;
try {
defineConstant(tempDefinition, tempValue, (tempDefinition.eContainer() instanceof SuiteDefinition)
? ((SuiteDefinition) tempDefinition.eContainer()) : null);
defineConstant(tempDefinition, tempValue,
(tempDefinition.eContainer() instanceof SuiteDefinition)
? ((SuiteDefinition) tempDefinition.eContainer())
: null);
} catch (ClassNotFoundException | InstantiationException | UnexecutableException exc) {
// Cannot happen - parameterized constants aren't evaluated
}
Expand Down Expand Up @@ -1182,19 +1184,17 @@ protected SuiteSummaryResult callSuiteSingle(Suite aSuiteCall) {
// TODO make this nicer, it's kind of ugly to create a fake object with null values
abortExecutionCause = new ExceptionWrapper(null, null);

if (tempResult == null && tempForkResultSummary == null) {
// We may not have any result at this point, as the fork has aborted without providing us
// one. In order to ensure that at least the exception that triggered the abortion is logged
// in the counts (and thus a user who typically only looks at the total counts is alerted to
// the problem), we generate a result here with one exception. This might be wrong actually
// (for example there could have been a successful test before the exception, which may not
// be counted in this case), but that's basically what's meant by "test result total numbers
// may be inaccurate" which is printed out in this case, and the current structure of the
// master-fork sync protocol makes it hard to perfectly fix this inaccuracy in cases of
// sudden execution path deviations. Thus, this "forced result" was deemed a good-enough
// solution. This fixes issue #145: https://github.com/integrity-tf/integrity/issues/145
tempResult = new SuiteSummaryResult(0, 0, 1, 0, tempSuiteDuration);
}
// We may not have any result at this point, as the fork has aborted without providing us
// one. In order to ensure that at least the exception that triggered the abortion is logged
// in the counts (and thus a user who typically only looks at the total counts is alerted to
// the problem), we generate a result here with one exception. This might be wrong actually
// (for example there could have been a successful test before the exception, which may not
// be counted in this case), but that's basically what's meant by "test result total numbers
// may be inaccurate" which is printed out in this case, and the current structure of the
// master-fork sync protocol makes it hard to perfectly fix this inaccuracy in cases of
// sudden execution path deviations. Thus, this "forced result" was deemed a good-enough
// solution. This fixes issue #145: https://github.com/integrity-tf/integrity/issues/145
tempResult = new SuiteSummaryResult(0, 0, 1, 0, tempSuiteDuration);
}

// and afterwards we'll switch back to real test mode
Expand Down Expand Up @@ -1508,7 +1508,17 @@ protected void defineConstant(final ConstantDefinition aDefinition, Object aValu
throws ClassNotFoundException, InstantiationException, UnexecutableException {
Object tempValue;
if (aValue == null) {
tempValue = parameterResolver.resolveStatically(aDefinition, variantInExecution);
if (isFork() && !shouldExecuteFixtures()) {
// Skip the value evaluation if we are on a fork AND the fork is not currently executing stuff.
// This complements a similar piece of code seen in the variable definition code that prevents
// the variable/constant to be defined if we're on a fork and the fork is in dry run mode.
// Values that are thrown away later anyway don't need to be computed, and if the are, this can
// even cause exceptions, because some input for those values might not be defined, as seen in
// issue #198, which this exception here intends to fix.
tempValue = null;
} else {
tempValue = parameterResolver.resolveStatically(aDefinition, variantInExecution);
}
} else {
tempValue = aValue;
}
Expand All @@ -1528,7 +1538,8 @@ protected void defineConstant(final ConstantDefinition aDefinition, Object aValu
protected void defineVariable(final VariableOrConstantEntity anEntity, Object anInitialValue,
final SuiteDefinition aSuite) {
final Object tempInitialValue = (anInitialValue instanceof Variable)
? variableManager.get(((Variable) anInitialValue).getName()) : anInitialValue;
? variableManager.get(((Variable) anInitialValue).getName())
: anInitialValue;

// We need to send variable updates to forks in the main phase here.
boolean tempSendToForks = (!isFork()) && shouldExecuteFixtures();
Expand Down Expand Up @@ -1731,7 +1742,17 @@ protected void executeVariableAssignment(VariableAssignment anAssignment, SuiteD
// run or test run mode.
try {
setVariableValueConverted(anAssignment.getTarget().getName(), anAssignment.getValue(), true);
} catch (InstantiationException | ClassNotFoundException | UnexecutableException exc) {
} catch (UnexecutableException exc) {
// This is expected to happen in some cases during dry run, namely on operations to be executed on
// assignment which use variables that are dynamically assigned from call results. But that is not a
// problem, we can safely ignore this, the variable will then not be assigned. In the real test run
// however it should not happen, so let's print it on stderr in that case.
// This fixes issue #197: Exception thrown before test runs in case of assigns having operations
// with variables filled via call (https://github.com/integrity-tf/integrity/issues/197)
if (shouldExecuteFixtures()) {
exc.printStackTrace();
}
} catch (InstantiationException | ClassNotFoundException exc) {
exc.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,7 @@ packagedef integrity.fixtures.basic.noop with
testdef throwAbortExceptionTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#throwAbortException

calldef generateCharacter uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#generateCharacter

calldef generateArray uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#generateArray

packageend
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ packagedef integrity.basic with

suiteend


suitedef simpleArrayCreationAndPassing with

// This failed because of issue 199
variable someVariable
call integrity.fixtures.basic.noop.generateArray -> someVariable
call integrity.fixtures.basic.noop.echoObject echo: someVariable

suiteend



packageend
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,19 @@ public void testSimpleFixtureCallWithTwoParams() throws ModelLoadException, IOEx
assertDocumentMatchesReference(tempResult);
}

/**
* Performs a suite which does tests and checks the resulting XML document.
*
* @throws ModelLoadException
* @throws IOException
* @throws JDOMException
*/
@Test
public void testSimpleArrayCreationAndPassing() throws ModelLoadException, IOException, JDOMException {
Document tempResult = executeIntegritySuite(
new String[] { "integrity/suites/basic/simpleFixtureCalls.integrity" },
"integrity.basic.simpleArrayCreationAndPassing", null);
assertDocumentMatchesReference(tempResult);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<integrity name="Integrity JUnit Testing" timestamp="27.09.18 15:05" isotimestamp="2018-09-27T15:05:32" duration="1.244">
<variables />
<suite id="0" name="integrity.basic.simpleArrayCreationAndPassing" timestamp="27.09.18 15:05:32.0137">
<setup />
<variables>
<variable name="someVariable" />
</variables>
<statements>
<call id="1" line="75" name="generateArray" description="Creates an array" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#generateArray" timestamp="27.09.18 15:05:32.0138">
<parameters />
<result duration="0.030" type="success">
<variableUpdate name="someVariable" value="0, 1, 2, 3, 4" />
</result>
</call>
<call id="2" line="76" name="echoObject" description="Echoes an object" fixture="de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoObject" timestamp="27.09.18 15:05:32.0138">
<parameters>
<parameter name="echo" value="0, 1, 2, 3, 4" />
</parameters>
<result duration="0.146" type="success" />
</call>
</statements>
<returns />
<teardown />
<result duration="1.081" successCount="0" failureCount="0" exceptionCount="0" testExceptionCount="0" callExceptionCount="0" />
</suite>
</integrity>

Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ public String generateCharacter(@FixtureParameter(name = "code") int aCharacterC
return tempChar;
}

@FixtureMethod(description = "Creates an array")
public Long[] generateArray() {
Long[] tempTestArray = new Long[5];
for (int i = 0; i < 5; i++) {
tempTestArray[i] = new Long(i);
}
return tempTestArray;
}

public enum Enum {

VALUE1,
Expand Down

0 comments on commit b976e94

Please sign in to comment.