Skip to content

Commit 2b7e5d4

Browse files
jbower-fbmeta-codesync[bot]
authored andcommitted
Use a regex for LIRGeneratorTest.CondBranchCheckTypeEmitsCallToSubclassCheck
Summary: The HIR keeps changing slightly and ideally we wouldn't have a variant for each Python version. It's a bit messy because C++. Reviewed By: yoney Differential Revision: D84124898 fbshipit-source-id: 1ac2e0547d9478c984a6489425bb07d4a79ec6cd
1 parent f710e0d commit 2b7e5d4

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

cinderx/RuntimeTests/lir_test.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <memory>
1818
#include <ostream>
19+
#include <regex>
1920
#include <string>
2021
#include <utility>
2122

@@ -454,26 +455,20 @@ fun foo {
454455
lir_func->sortBasicBlocks();
455456
ss << *lir_func << std::endl;
456457

457-
auto lir_expected = fmt::format(
458-
#if PY_VERSION_HEX >= 0x030C0000
459-
R"(
460-
# CondBranchCheckType<1, 3, Tuple> v1
461-
%8:8bit = Call {0}({0:#x}):64bit, %7:Object
462-
CondBranch %8:8bit, BB%10, BB%12
463-
)",
464-
#else
465-
R"(
466-
# CondBranchCheckType<1, 3, Tuple> v1
467-
%5:8bit = Call {0}({0:#x}):64bit, %4:Object
468-
CondBranch %5:8bit, BB%7, BB%9
469-
)",
470-
#endif
458+
std::string lir_str = ss.str();
459+
lir_str.erase(
460+
std::remove(lir_str.begin(), lir_str.end(), '\n'), lir_str.end());
461+
462+
std::string lir_expected_re = fmt::format(
463+
R"(# CondBranchCheckType<1, 3, Tuple> v1\s+%\d+:8bit = Call {0}\({0:#x}\):64bit, %\d+:Object\s+CondBranch %\d+:8bit, BB%\d+, BB%\d+)",
471464
reinterpret_cast<uint64_t>(__Invoke_PyTuple_Check));
472-
if (ss.str().find(lir_expected.c_str()) == std::string::npos) {
465+
466+
std::regex re(lir_expected_re);
467+
if (!std::regex_search(lir_str, re)) {
473468
FAIL() << "Couldn't find expected string " << std::endl
474-
<< lir_expected << std::endl
469+
<< lir_expected_re << std::endl
475470
<< "In:" << std::endl
476-
<< ss.str() << std::endl;
471+
<< lir_str << std::endl;
477472
}
478473
}
479474

0 commit comments

Comments
 (0)