mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-18 09:23:26 -05:00
fix: refuse validate_pr flags it would drop
Named files beside --changed were replaced by the git diff, and the run reported no changed files about files it never read; --json beside --markdown dropped the markdown. Both combinations are now refused, and an empty JSON run prints an empty list.
This commit is contained in:
1 parent
1df23e3f7d
commit
32d32e5718
2 files changed
+36
-3
No files matched your search
+12
-3
@@ -307,6 +307,10 @@ def _files_to_validate(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser
|
||||
) -> list:
|
||||
"""The files named on the command line, or the changed ones."""
|
||||
if args.changed and args.files:
|
||||
# Named files were dropped for the git diff, and the run reported
|
||||
# "No changed BIOS files detected" about files it never looked at.
|
||||
parser.error("--changed reads the git diff; name files or pass --changed, not both")
|
||||
if not args.changed:
|
||||
if not args.files:
|
||||
parser.error("No files specified. Use --changed or provide file paths.")
|
||||
@@ -316,7 +320,7 @@ def _files_to_validate(
|
||||
except (RuntimeError, OSError) as exc:
|
||||
print(f"Error: {exc}", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
if not files:
|
||||
if not files and not args.json:
|
||||
print("No changed BIOS files detected")
|
||||
return files
|
||||
|
||||
@@ -340,14 +344,19 @@ def main() -> None:
|
||||
parser.add_argument("--db", default=DEFAULT_DB, help="Path to database.json")
|
||||
parser.add_argument("--platforms-dir", default=DEFAULT_PLATFORMS_DIR)
|
||||
parser.add_argument("--emulators-dir", default=DEFAULT_EMULATORS_DIR)
|
||||
parser.add_argument(
|
||||
# One output format: --json beside --markdown printed JSON and dropped
|
||||
# the markdown without a word.
|
||||
output = parser.add_mutually_exclusive_group()
|
||||
output.add_argument(
|
||||
"--markdown", action="store_true", help="Output as markdown (for PR comments)"
|
||||
)
|
||||
parser.add_argument("--json", action="store_true", help="Output as JSON")
|
||||
output.add_argument("--json", action="store_true", help="Output as JSON")
|
||||
args = parser.parse_args()
|
||||
|
||||
files = _files_to_validate(args, parser)
|
||||
if not files:
|
||||
if args.json:
|
||||
print("[]")
|
||||
return
|
||||
|
||||
db = _load_database_if_any(args.db)
|
||||
|
||||
@@ -247,5 +247,29 @@ class PlatformHashLoading(_Fixture):
|
||||
self.assertIn("boot.bin", known["names"])
|
||||
|
||||
|
||||
class FlagsAreAppliedOrRefused(unittest.TestCase):
|
||||
"""Files named beside --changed were dropped for the git diff and the run
|
||||
said "No changed BIOS files detected" about files it never read; --json
|
||||
beside --markdown printed JSON and dropped the markdown."""
|
||||
|
||||
def _run(self, *argv: str):
|
||||
import subprocess # noqa: PLC0415
|
||||
|
||||
return subprocess.run(
|
||||
[sys.executable, "scripts/validate_pr.py", *argv], cwd=REPO_ROOT,
|
||||
capture_output=True, text=True, timeout=300, check=False,
|
||||
)
|
||||
|
||||
def test_files_beside_changed_are_refused(self):
|
||||
result = self._run("--changed", "bios/Sony/PlayStation/scph5501.bin", "--json")
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertIn("--changed", result.stderr)
|
||||
|
||||
def test_two_output_formats_are_refused(self):
|
||||
result = self._run("--json", "--markdown", "bios/Sony/PlayStation/scph5501.bin")
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertIn("not allowed with", result.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user