mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-15 09:11:33 +00:00
test(java): clarify overload coverage (#3791)
Separate unmodeled call-argument coverage from Java accessibility and confirm the accessible Object overload with an executed javac oracle. Give incomplete-attribution cases distinct titles: JSON formatting drops undefined properties and made three test identities collide in CI.
This commit is contained in:
parent
e774274245
commit
ca6bffe558
3 changed files with 55 additions and 7 deletions
|
|
@ -10,6 +10,38 @@ const javacAvailable =
|
|||
spawnSync('javac', [...compilerLocale, '-version'], { encoding: 'utf8' }).status === 0;
|
||||
|
||||
describe('javac oracle for Java overload resolution', () => {
|
||||
it.runIf(javacAvailable)(
|
||||
'selects the accessible Object overload for a declared method return and known arguments',
|
||||
() => {
|
||||
const root = mkdtempSync(path.join(tmpdir(), 'gitnexus-javac-accessible-'));
|
||||
try {
|
||||
const source = path.join(root, 'Oracle.java');
|
||||
writeFileSync(
|
||||
source,
|
||||
`class AccessFilter {
|
||||
private String accessFiltered(String value) { return "private"; }
|
||||
public String accessFiltered(Object value) { return "object"; }
|
||||
}
|
||||
public class Oracle {
|
||||
static Object external() { return null; }
|
||||
public static void main(String[] args) {
|
||||
AccessFilter value = new AccessFilter();
|
||||
Object argument = external();
|
||||
System.out.println(String.join(",", value.accessFiltered(external()),
|
||||
value.accessFiltered(argument), value.accessFiltered("x")));
|
||||
}
|
||||
}`,
|
||||
);
|
||||
execFileSync('javac', [...compilerLocale, '-d', root, source]);
|
||||
expect(execFileSync('java', ['-cp', root, 'Oracle'], { encoding: 'utf8' }).trim()).toBe(
|
||||
'object,object,object',
|
||||
);
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(javacAvailable)(
|
||||
'confirms enclosing-subclass access and protected receiver restrictions',
|
||||
() => {
|
||||
|
|
|
|||
|
|
@ -297,6 +297,7 @@ class Cases {
|
|||
void genericCall(Generic<String> value) { value.genericDispatch("x"); }
|
||||
void inaccessibleAlternate(AccessFilter value) { value.accessFiltered(external()); }
|
||||
void accessibleKnown(AccessFilter value) { value.accessFiltered("x"); }
|
||||
void accessibleObject(AccessFilter value, Object argument) { value.accessFiltered(argument); }
|
||||
<T> void genericAny(Generic<T> value, T item) { value.genericDispatch(item); }
|
||||
}`,
|
||||
'api/Service.java': `package api; public interface Service { void select(long value); void select(Integer value); }`,
|
||||
|
|
@ -356,6 +357,7 @@ class ObjectOverload {
|
|||
['trailingDimension', 'dimension', 'Cases.dimension#1~Object'],
|
||||
['nestedPrivate', 'nest', 'Nest.nest#1~long'],
|
||||
['accessibleKnown', 'accessFiltered', 'AccessFilter.accessFiltered#1~Object'],
|
||||
['accessibleObject', 'accessFiltered', 'AccessFilter.accessFiltered#1~Object'],
|
||||
['declaredReceiver', 'declared', 'Base.declared#1'],
|
||||
])('%s selects %s by the earliest applicable JLS phase', (caller, method, signature) => {
|
||||
expect(targets(result, caller, method)).toEqual([`Method:Cases.java:${signature}`]);
|
||||
|
|
@ -467,7 +469,6 @@ class ObjectOverload {
|
|||
['implicitObject', 'wait'],
|
||||
['staticTypeImport', 'select'],
|
||||
['equivalentPreferred', 'preferred'],
|
||||
['inaccessibleAlternate', 'accessFiltered'],
|
||||
])('records uncertainty for %s without a guessed overload edge', (caller, method) => {
|
||||
expect(targets(result, caller, method)).toEqual([]);
|
||||
expect(
|
||||
|
|
@ -481,6 +482,21 @@ class ObjectOverload {
|
|||
).toBe(true);
|
||||
});
|
||||
|
||||
it('reports unmodeled method-call arguments even when javac can select an overload', () => {
|
||||
expect(targets(result, 'inaccessibleAlternate', 'accessFiltered')).toEqual([]);
|
||||
expect(getResolutionOutcomes(result)).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
kind: 'suppressed',
|
||||
name: 'accessFiltered',
|
||||
reason: 'overload-unknown',
|
||||
callerId: expect.stringContaining('.inaccessibleAlternate#'),
|
||||
detail: 'Unsupported Java argument, generic constraint, or subtype evidence',
|
||||
}),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(['chain', 'assignedChain', 'nestedChain'])(
|
||||
'uses the selected compile-time return for %s',
|
||||
(caller) => {
|
||||
|
|
|
|||
|
|
@ -144,12 +144,12 @@ describe('persisted unresolved overload coverage', () => {
|
|||
});
|
||||
|
||||
it.each([
|
||||
{ candidateGraphIds: undefined },
|
||||
{ candidateGraphIds: [] },
|
||||
{ callerId: undefined },
|
||||
{ candidateSetComplete: undefined },
|
||||
{ candidateSetComplete: false },
|
||||
])('does not certify absent keys when attribution is incomplete: %j', (overrides) => {
|
||||
['missing candidate identities', { candidateGraphIds: undefined }],
|
||||
['empty candidate identities', { candidateGraphIds: [] }],
|
||||
['missing caller identity', { callerId: undefined }],
|
||||
['missing candidate completeness', { candidateSetComplete: undefined }],
|
||||
['incomplete candidates', { candidateSetComplete: false }],
|
||||
])('does not certify absent keys with %s', (_description, overrides) => {
|
||||
const summary = summarizeUnresolvedOverloads([suppressed(overrides)]);
|
||||
expect(summary.complete).toBe(false);
|
||||
expect(probe(summary, ['Method:elsewhere:unseen'])).toEqual({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue