(testCase: TestCase)
| 67 | } |
| 68 | |
| 69 | export function executeTestCase(testCase: TestCase) { |
| 70 | const fs = require("fs-extra") |
| 71 | |
| 72 | function reportingFailures(f: () => void): void { |
| 73 | try { |
| 74 | f() |
| 75 | } catch (e) { |
| 76 | const data = JSON.stringify(testCase) + "\n\n" |
| 77 | if (!existsSync("generative-test-errors.log")) { |
| 78 | writeFileSync("generative-test-errors.log", data) |
| 79 | } else { |
| 80 | appendFileSync("generative-test-errors.log", data) |
| 81 | } |
| 82 | throw e |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | const tmpDir = tmp.dirSync({ unsafeCleanup: true, mode: 0o100777 }) |
| 87 | |
| 88 | spawnSafeSync("git", ["init"], { cwd: tmpDir.name }) |
| 89 | |
| 90 | writeFiles(tmpDir.name, testCase.cleanFiles) |
| 91 | |
| 92 | spawnSafeSync("git", ["add", "-A"], { cwd: tmpDir.name }) |
| 93 | spawnSafeSync("git", ["commit", "--allow-empty", "-m", "blah"], { |
| 94 | cwd: tmpDir.name, |
| 95 | }) |
| 96 | if (Object.keys(testCase.cleanFiles).length > 0) { |
| 97 | spawnSafeSync("git", ["rm", "-rf", "*"], { |
| 98 | cwd: tmpDir.name, |
| 99 | }) |
| 100 | } |
| 101 | |
| 102 | writeFiles(tmpDir.name, testCase.modifiedFiles) |
| 103 | spawnSafeSync("git", ["add", "-A"], { cwd: tmpDir.name }) |
| 104 | |
| 105 | const patchResult = spawnSafeSync( |
| 106 | "git", |
| 107 | ["diff", "--color=never", "--cached"], |
| 108 | { |
| 109 | cwd: tmpDir.name, |
| 110 | logStdErrOnError: true, |
| 111 | throwOnError: true, |
| 112 | }, |
| 113 | ) |
| 114 | |
| 115 | const patchFileContents = patchResult.stdout.toString() |
| 116 | |
| 117 | const patchFileContentsWithBlankLines = removeLeadingSpaceOnBlankLines( |
| 118 | patchFileContents, |
| 119 | ) |
| 120 | |
| 121 | // skipping because we add source to the hunks now, so we need to strip that out before comparing |
| 122 | it.skip("looks the same whether parsed with blank lines or not", () => { |
| 123 | reportingFailures(() => { |
| 124 | expect(parsePatchFile(patchFileContents)).toEqual( |
| 125 | parsePatchFile(patchFileContentsWithBlankLines), |
| 126 | ) |
no test coverage detected
searching dependent graphs…