Forum OpenACS Development: wrong use of aa_call_component?

Collapse
Posted by tammy m on
Hi

I'm using aa_call_component like this:

aa_register_component "my_component" {
  Chunk of reusable test code.
} {
  aa_false "Verify blah exists." [empty_string_p $blah]
}

aa_register_case -cats {
      script
} my_test {
  Tests something.
} {
  # aa_run_with_teardown ensures that all db inserts/deletes/updates are rolled back on test completion.
  aa_run_with_teardown  -rollback  -test_code  {
    set blah "hello"
    aa_call_component my_component
  }
  return
}
And I get an error as so:
my_test (body 0): Error during execution: Setup failed with error can't read "blah": no such variable 

 can't read "blah": no such variable
    while executing
"empty_string_p $blah"

I am supposed to be able to call aa_call_component from within a test case and still have access to existing variables or am I supposed to be passing them somehow? aa_export_vars says it passes the other direction: Called from a initialisation class constructor or a component to explicitly export the specified variables to the current testcase.  So that is not the right call to make.

Maybe this a bug given that this is new/unreleased code and I don't see any examples of aa_call_component that use existing vars from a calling test case when I grep existing source?

Collapse
Posted by Vinod Kurup on
This seems like a bug to me. The comments inside aa_call_component suggest that the component should be evaluated in the calling environments stack, but that doesn't seem to be happening.

Looking at the test code in the news package, I see that calling aa_export_vars inside the component allows you to access $blah, but I agree with you that aa_export_vars is not supposed to be used for this purpose. It seems like a side-effect.

IOW, this works:

aa_register_component "my_component" {
  Chunk of reusable test code.
} {
  aa_export_vars {blah}
  aa_false "Verify blah exists." [empty_string_p $blah]
}