#!/usr/bin/env python # coding: utf-8 # # Testing Configurations # # The behavior of a program is not only governed by its data. The _configuration_ of a program – that is, the settings that govern the execution of a program on its (regular) input data, as set by options or configuration files – just as well influences behavior, and thus can and should be tested. In this chapter, we explore how to systematically _test_ and _cover_ software configurations. By _automatically inferring configuration options_, we can apply these techniques out of the box, with no need for writing a grammar. Finally, we show how to systematically cover _combinations_ of configuration options, quickly detecting unwanted interferences. # In[1]: from bookutils import YouTubeVideo YouTubeVideo('L0ztoXVru2U') # **Prerequisites** # # * You should have read the [chapter on grammars](Grammars.ipynb). # * You should have read the [chapter on grammar coverage](GrammarCoverageFuzzer.ipynb). # In[2]: import bookutils.setup # In[3]: from typing import List, Union, Optional, Callable, Type # ## Synopsis # # # To [use the code provided in this chapter](Importing.ipynb), write # # ```python # >>> from fuzzingbook.ConfigurationFuzzer import # ``` # # and then make use of the following features. # # # This chapter provides two classes: # # * `OptionRunner` automatically extract command-line options from a Python program; # * `OptionFuzzer` uses these to automatically test a Python program with a large variety of options. # # `OptionRunner` runs a program up to the point where it parses its arguments, and then extracts a grammar that describes its invocations: # # ```python # >>> autopep8_runner = OptionRunner("autopep8", "foo.py") # ``` # The grammar can be extracted via the method `ebnf_grammar()`: # # ```python # >>> option_ebnf_grammar = autopep8_runner.ebnf_grammar() # >>> option_ebnf_grammar # {'': ['(