tools/disable_tests/gtest.py
def canonicalise(parsed_condition) -> Condition:
  """Make a Condition from a raw preprocessor AST.

  Take the raw form of the condition we've parsed from the file and convert it
  into its canonical form, replacing any domain-specific stuff with its generic
  form.
  """

  if not isinstance(parsed_condition, tuple):
    return parsed_condition

  # Convert logical operators into their canonical Condition form.
  op, args = parsed_condition
  if op == '!':
    # Just one arg in this case, not wrapped in a list.
    return ('not', canonicalise(args))

  if (logical_fn := {'&&': 'and', '||': 'or'}.get(op, None)) is not None:
    return (logical_fn, [canonicalise(arg) for arg in args])

  # If not a logical operator, this must a be a function-style macro used to
  # express a condition. Find the Terminal it represents.
  assert len(args) == 1
  term = next((t for t in conditions.TERMINALS if t.gtest_info.name == args[0]),
              None)
  if term is None:
    # TODO: Should probably produce with a nicer error message here, as this is
    # a somewhat expected case where we can't parse the existing condition.
    raise Exception(f"Couldn't find any terminal corresponding to {args[0]}")

  if op == 'defined':
    assert term.gtest_info.type == MACRO_TYPE
  elif op == 'BUILDFLAG':
    assert term.gtest_info.type == BUILDFLAG_TYPE
  else:
    raise Exception(f"Don't know what to do with expr {parsed_condition}")

  return term
Make a Condition from a raw preprocessor AST.

  Take the raw form of the condition we've parsed from the file and convert it
  into its canonical form, replacing any domain-specific stuff with its generic
  form.
  
Make a Condition from a raw preprocessor AST.
Take the raw form of the condition we've parsed from the file and convert it
into its canonical form, replacing any domain-specific stuff with its generic
form.
Make a Condition from a raw preprocessor AST . Take the raw form of the condition we ' ve parsed from the file and convert it into its canonical form replacing any domain - specific stuff with its generic form .
def canonicalise(parsed_condition) -> Condition:
  if not isinstance(parsed_condition, tuple):
    return parsed_condition
  op, args = parsed_condition
  if op == '!':
    return ('not', canonicalise(args))
  if (logical_fn := {'&&': 'and', '||': 'or'}.get(op, None)) is not None:
    return (logical_fn, [canonicalise(arg) for arg in args])
  assert len(args) == 1
  term = next((t for t in conditions.TERMINALS if t.gtest_info.name == args[0]),
              None)
  if term is None:
    raise Exception(f"Couldn't find any terminal corresponding to {args[0]}")
  if op == 'defined':
    assert term.gtest_info.type == MACRO_TYPE
  elif op == 'BUILDFLAG':
    assert term.gtest_info.type == BUILDFLAG_TYPE
  else:
    raise Exception(f"Don't know what to do with expr {parsed_condition}")
  return term
def canonicalise ( parsed_condition ) -> Condition : if not isinstance ( parsed_condition , tuple ) : return parsed_condition op , args = parsed_condition if op == '!' : return ( 'not' , canonicalise ( args ) ) if ( logical_fn := { '&&' : 'and' , '||' : 'or' } . get ( op , None ) ) is not None : return ( logical_fn , [ canonicalise ( arg ) for arg in args ] ) assert len ( args ) == 1 term = next ( ( t for t in conditions . TERMINALS if t . gtest_info . name == args [ 0 ] ) , None ) if term is None : raise Exception ( f"Couldn't find any terminal corresponding to {args[0]}" ) if op == 'defined' : assert term . gtest_info . type == MACRO_TYPE elif op == 'BUILDFLAG' : assert term . gtest_info . type == BUILDFLAG_TYPE else : raise Exception ( f"Don't know what to do with expr {parsed_condition}" ) return term
Make a Condition from a raw preprocessor AST.
Make a Condition from a raw preprocessor AST .
"""Make a Condition from a raw preprocessor AST.

  Take the raw form of the condition we've parsed from the file and convert it
  into its canonical form, replacing any domain-specific stuff with its generic
  form.
  """ # Convert logical operators into their canonical Condition form. # Just one arg in this case, not wrapped in a list. # If not a logical operator, this must a be a function-style macro used to # express a condition. Find the Terminal it represents. # TODO: Should probably produce with a nicer error message here, as this is # a somewhat expected case where we can't parse the existing condition.
parsed_condition