  We consider scalar-tensor theories of gravity in an accelerating universe.
The equations for the background evolution and the perturbations are given in
full generality for any parametrization of the Lagrangian, and we stress that
apparent singularities are sometimes artifacts of a pathological choice of
variables. Adopting a phenomenological viewpoint, i.e., from the observations
back to the theory, we show that the knowledge of the luminosity distance as a
function of redshift up to z ~ (1-2), which is expected in the near future,
severely constrains the viable subclasses of scalar-tensor theories. This is
due to the requirement of positive energy for both the graviton and the scalar
partner. Assuming a particular form for the Hubble diagram, consistent with
present experimental data, we reconstruct the microscopic Lagrangian for
various scalar-tensor models, and find that the most natural ones are obtained
if the universe is (marginally) closed.
