domcleal / rspec-puppet-augeas

RSpec tests for Augeas resources inside Puppet manifests
MIT License
14 stars 9 forks source link

rspec-puppet-augeas expects empty results from augparse #10

Open mcallaway opened 10 years ago

mcallaway commented 10 years ago

In rspec-puppet-augeas test_utils.rb, we have:

raise RSpec::Puppet::Augeas::Error, "augparse failed:\n#{output}" unless res == 0 && output.empty?

But the test that it performs produces output even if it's correct and exits 0.

> cat /tmp/rpa-augparse20140423-31379-vdz5tf/test_rspec_puppet_augeas.aug
module Test_Rspec_Puppet_Augeas =
  test Automaster.lns get Sys.read_file "/tmp/rpa-augparse20140423-31379-vdz5tf/input" =
    ?

> augparse --notypecheck /tmp/rpa-augparse20140423-31379-vdz5tf/test_rspec_puppet_augeas.aug
Test result: /tmp/rpa-augparse20140423-31379-vdz5tf/test_rspec_puppet_augeas.aug:2.2-3.5:
  { "#comment" = "This is a test empty auto.master file" }
  { "1" = "/gapp"
    { "map" = "/etc/auto.gapp" }
    { "opt" = "--timeout"
      { "value" = "300" }
    }
    { "opt" = "intr" }
    { "opt" = "tcp" }
  }

> echo $?
0

As you can see, the test passes, but not silently, and so the rspec test fails.

This is in:

augeas-tools 1.0.0-0ubuntu1~raphink1~lucid1

Failure exits 1, that should be enough.

domcleal commented 9 years ago

Sorry for the extremely late reply.

This is kind of by design, as the idea with the augparse() function is that you'd supply a result tree as a string in the first argument and the generated tree will be compared against the expected string. The default of '?' is a shortcut (IIRC) so the test will fail, but will output the expected tree, which you can copy and paste so it passes next time.

I could add an option in if you like to make the behaviour configurable? That way we could keep the above, and also allow just using '?' if you want to simply check the file parses, not that it matches a specific tree.