(self)
| 3005 | self.assertEqual(pre_mtime, post_mtime) |
| 3006 | |
| 3007 | def test_cli_force(self): |
| 3008 | invalid_input = dedent(""" |
| 3009 | /*[clinic input] |
| 3010 | output preset block |
| 3011 | module test |
| 3012 | test.fn |
| 3013 | a: int |
| 3014 | [clinic start generated code]*/ |
| 3015 | |
| 3016 | const char *hand_edited = "output block is overwritten"; |
| 3017 | /*[clinic end generated code: output=bogus input=bogus]*/ |
| 3018 | """) |
| 3019 | fail_msg = ( |
| 3020 | "Checksum mismatch! Expected 'bogus', computed '2ed19'. " |
| 3021 | "Suggested fix: remove all generated code including the end marker, " |
| 3022 | "or use the '-f' option.\n" |
| 3023 | ) |
| 3024 | with os_helper.temp_dir() as tmp_dir: |
| 3025 | fn = os.path.join(tmp_dir, "test.c") |
| 3026 | with open(fn, "w", encoding="utf-8") as f: |
| 3027 | f.write(invalid_input) |
| 3028 | # First, run the CLI without -f and expect failure. |
| 3029 | # Note, we cannot check the entire fail msg, because the path to |
| 3030 | # the tmp file will change for every run. |
| 3031 | _, err = self.expect_failure(fn) |
| 3032 | self.assertEndsWith(err, fail_msg) |
| 3033 | # Then, force regeneration; success expected. |
| 3034 | out = self.expect_success("-f", fn) |
| 3035 | self.assertEqual(out, "") |
| 3036 | # Verify by checking the checksum. |
| 3037 | checksum = ( |
| 3038 | "/*[clinic end generated code: " |
| 3039 | "output=a2957bc4d43a3c2f input=9543a8d2da235301]*/\n" |
| 3040 | ) |
| 3041 | with open(fn, encoding='utf-8') as f: |
| 3042 | generated = f.read() |
| 3043 | self.assertEndsWith(generated, checksum) |
| 3044 | |
| 3045 | def test_cli_make(self): |
| 3046 | c_code = dedent(""" |
nothing calls this directly
no test coverage detected