Skip to content

Commit

Permalink
Fix: report non-preferred games as IGNORED when no game found (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored May 8, 2024
1 parent 57d166d commit 825d608
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/types/datStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class DATStatus {
[...parentsToReleaseCandidates.entries()]
.filter(([, releaseCandidates]) => releaseCandidates.every((rc) => !rc.isPatched()))
.forEach(([parent, releaseCandidates]) => {
parent.getGames().forEach((game) => {
parent.getGames().forEach((game, gameIdx) => {
DATStatus.pushValueIntoMap(this.allRomTypesToGames, game, game);

const gameReleaseCandidates = releaseCandidates
Expand Down Expand Up @@ -95,11 +95,15 @@ export default class DATStatus {
return;
}

// When running in 1G1R mode, if this Parent has at least one ReleaseCandidate, but no
// matching ReleaseCandidate was found for this Game (above), then report it as IGNORED.
// When running in 1G1R mode, if no ReleaseCandidate was found for this Game (would have
// already returned above), and:
// 1. This Parent has at least one ReleaseCandidate, then one of the other Games must
// have a ReleaseCandidate, so this Game should be considered IGNORED
// 2. This parent has zero ReleaseCandidates and this Game is not the first Game, then
// consider this Game IGNORED (only the first Game should be considered MISSING)
// We can't know if this Game had matching input files, they would have already been
// discarded, so those files will be reported as UNUSED.
if (options.getSingle() && releaseCandidates.length > 0) {
if (options.getSingle() && (releaseCandidates.length > 0 || gameIdx > 0)) {
this.ignoredHashCodesToGames.set(game.hashCode(), game);
}
});
Expand Down
67 changes: 63 additions & 4 deletions test/modules/statusGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,21 @@ async function candidateGenerator(

describe('toConsole', () => {
describe('no candidates', () => {
test.each([true, false, undefined])('should print games without ROMs as found when single:%s', async (single) => {
it('should print games without ROMs as found when single:true', async () => {
const options = new Options({
...defaultOptions,
single,
single: true,
preferParent: true,
});
const map = await candidateGenerator(options, []);
const datStatus = new StatusGenerator(options, new ProgressBarFake())
.generate(dummyDat, map);
expect(stripAnsi(datStatus.toConsole(options))).toEqual('2/5 games, 0/1 BIOSes, 1/1 devices, 2/5 retail releases found');
});
it('should print games without ROMs as found when single:false', async () => {
const options = new Options({
...defaultOptions,
single: false,
preferParent: true,
});
const map = await candidateGenerator(options, []);
Expand Down Expand Up @@ -198,6 +209,19 @@ describe('toConsole', () => {
expect(stripAnsi(datStatus.toConsole(options))).toEqual('6/6 games, 1/1 BIOSes, 1/1 devices, 5/5 retail releases found');
});

it('should print only the preferred game as found when none are present and single:true', async () => {
const options = new Options({
...defaultOptions,
single: true,
preferParent: true,
});
let map = await candidateGenerator(options, []);
map = await new CandidatePreferer(options, new ProgressBarFake()).prefer(dummyDat, map);
const datStatus = new StatusGenerator(options, new ProgressBarFake())
.generate(dummyDat, map);
expect(stripAnsi(datStatus.toConsole(options))).toEqual('2/5 games, 0/1 BIOSes, 1/1 devices, 2/5 retail releases found');
});

it('should print only the preferred game as found when all are present and single:true', async () => {
const options = new Options({
...defaultOptions,
Expand All @@ -219,10 +243,27 @@ describe('toConsole', () => {

describe('toCSV', () => {
describe('no candidates', () => {
test.each([true, false, undefined])('should report games without ROMs as found', async (single) => {
it('should report games without ROMs as found when single:true', async () => {
const options = new Options({
...defaultOptions,
single,
single: true,
preferParent: true,
});
const map = await candidateGenerator(options, []);
const datStatus = new StatusGenerator(options, new ProgressBarFake())
.generate(dummyDat, map);
await expect(datStatus.toCsv(options)).resolves.toEqual(`DAT Name,Game Name,Status,ROM Files,Patched,BIOS,Retail Release,Unlicensed,Debug,Demo,Beta,Sample,Prototype,Program,Aftermarket,Homebrew,Bad
dat,bios,MISSING,,false,true,true,false,false,false,false,false,false,false,false,false,false
dat,device,FOUND,,false,false,true,false,false,false,false,false,false,false,false,false,false
dat,game prototype (proto),IGNORED,,false,false,false,false,false,false,false,false,true,false,false,false,false
dat,game with multiple roms,MISSING,,false,false,true,false,false,false,false,false,false,false,false,false,false
dat,game with single rom,MISSING,,false,false,true,false,false,false,false,false,false,false,false,false,false
dat,no roms,FOUND,,false,false,true,false,false,false,false,false,false,false,false,false,false`);
});
it('should report games without ROMs as found when single:false', async () => {
const options = new Options({
...defaultOptions,
single: false,
preferParent: true,
});
const map = await candidateGenerator(options, []);
Expand Down Expand Up @@ -413,6 +454,24 @@ dat,game with single rom,FOUND,game.rom,false,false,true,false,false,false,false
dat,no roms,FOUND,,false,false,true,false,false,false,false,false,false,false,false,false,false`);
});

it('should print only the preferred game as found when none are present and single:true', async () => {
const options = new Options({
...defaultOptions,
single: true,
preferParent: true,
});
const map = await candidateGenerator(options, []);
const datStatus = new StatusGenerator(options, new ProgressBarFake())
.generate(dummyDat, map);
await expect(datStatus.toCsv(options)).resolves.toEqual(`DAT Name,Game Name,Status,ROM Files,Patched,BIOS,Retail Release,Unlicensed,Debug,Demo,Beta,Sample,Prototype,Program,Aftermarket,Homebrew,Bad
dat,bios,MISSING,,false,true,true,false,false,false,false,false,false,false,false,false,false
dat,device,FOUND,,false,false,true,false,false,false,false,false,false,false,false,false,false
dat,game prototype (proto),IGNORED,,false,false,false,false,false,false,false,false,true,false,false,false,false
dat,game with multiple roms,MISSING,,false,false,true,false,false,false,false,false,false,false,false,false,false
dat,game with single rom,MISSING,,false,false,true,false,false,false,false,false,false,false,false,false,false
dat,no roms,FOUND,,false,false,true,false,false,false,false,false,false,false,false,false,false`);
});

it('should print only the preferred game as found when all are present and single:true', async () => {
const options = new Options({
...defaultOptions,
Expand Down

0 comments on commit 825d608

Please sign in to comment.