Index: openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 15 Oct 2003 12:37:58 -0000 1.9 +++ openacs-4/packages/acs-lang/tcl/test/acs-lang-test-procs.tcl 16 Oct 2003 10:50:12 -0000 1.10 @@ -43,90 +43,93 @@ @author Peter Marklund (peter@collaboraid.biz) @creation-date 18 October 2002 } { - aa_run_with_teardown \ - -rollback \ - -test_code { + # Peter NOTE: cannot get this test case to work with the rollback code in automated testing + # and couldn't track down why. I'm threrefor resorting to manual teardown which is fragile and hairy - # The files involved in the test - set test_dir [lang::test::get_dir] - set catalog_dir [lang::catalog::package_catalog_dir acs-lang] - set catalog_file "${catalog_dir}/acs-lang.xxx_xx.ISO-8859-1.xml" - set backup_file_suffix ".orig" - set catalog_backup_file "${catalog_file}${backup_file_suffix}" - regexp {^.*(packages/.*)$} $test_dir match test_dir_rel - set tcl_file "${test_dir_rel}/test-message-tags.tcl" - set tcl_backup_file "${tcl_file}${backup_file_suffix}" - - # The test messages to use for the catalog file - array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3] - - # Write the test tcl file - set tcl_file_id [open "[acs_root_dir]/$tcl_file" w] - set new_key_1 "_" - set new_text_1 "Auto Key" - set new_key_2 "key_1" - set new_text_2 "text_1_different" - set new_key_3 "key_1" - set new_text_3 "$messages_array(key_1)" - puts $tcl_file_id "# The following key should be auto-generated and inserted - # <#${new_key_1} ${new_text_1}#> - # - # The following key should be made unique and inserted - # <#${new_key_2} ${new_text_2}#> - # - # The following key should not be inserted in the message catalog - # <#${new_key_3} ${new_text_3}#>" - close $tcl_file_id - - # Write the catalog file - lang::catalog::export_messages_to_file $catalog_file [array get messages_array] - - # We need to force the API to use the test catalog file - aa_stub lang::catalog::get_catalog_file_path " - return $catalog_file - " - - # Replace message tags in the tcl file and insert into catalog file - lang::util::replace_temporary_tags_with_lookups $tcl_file - - aa_unstub lang::catalog::get_catalog_file_path - - # Read the contents of the catalog file - array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]] - array set updated_messages_array [lindex [array get catalog_array messages] 1] - - #error "catalog_array=[array get catalog_array] updated_messages_array=[array get updated_messages_array]" - - # Assert that the old messages are unchanged - foreach old_message_key [array names messages_array] { - aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \ - $updated_messages_array($old_message_key)] - } - - # Check that the first new key was autogenerated - aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] - - # Check that the second new key was made unique and inserted - aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2] - - # Check that the third key was not inserted - aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \ - $messages_array($new_key_3)] - - # Check that there are no tags left in the tcl file - set tcl_file_id [open "[acs_root_dir]/$tcl_file" r] - set updated_tcl_contents [read $tcl_file_id] - close $tcl_file_id - aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0] - - # Delete the catalog files - file delete $catalog_backup_file - file delete $catalog_file - - # Delete the tcl files - file delete "[acs_root_dir]/$tcl_file" - file delete "[acs_root_dir]/$tcl_backup_file" + # The files involved in the test + set package_key acs-lang + set test_dir [lang::test::get_dir] + set catalog_dir [lang::catalog::package_catalog_dir $package_key] + set catalog_file "${catalog_dir}/acs-lang.xxx_xx.ISO-8859-1.xml" + set backup_file_suffix ".orig" + set catalog_backup_file "${catalog_file}${backup_file_suffix}" + regexp {^.*(packages/.*)$} $test_dir match test_dir_rel + set tcl_file "${test_dir_rel}/test-message-tags.tcl" + set tcl_backup_file "${tcl_file}${backup_file_suffix}" + + # The test messages to use for the catalog file + array set messages_array [list key_1 text_1 key_2 text_2 key_3 text_3] + # NOTE: must be kept up-to-date for teardown to work + set expected_new_keys [list Auto_Key key_1_1] + + # Write the test tcl file + set tcl_file_id [open "[acs_root_dir]/$tcl_file" w] + set new_key_1 "_" + set new_text_1 "Auto Key" + set new_key_2 "key_1" + set new_text_2 "text_1_different" + set new_key_3 "key_1" + set new_text_3 "$messages_array(key_1)" + puts $tcl_file_id "# The following key should be auto-generated and inserted + # <#${new_key_1} ${new_text_1}#> + # + # The following key should be made unique and inserted + # <#${new_key_2} ${new_text_2}#> + # + # The following key should not be inserted in the message catalog + # <#${new_key_3} ${new_text_3}#>" + close $tcl_file_id + + # Write the catalog file + lang::catalog::export_to_file $catalog_file [array get messages_array] + + # We need to force the API to export to the test catalog file + aa_stub lang::catalog::get_catalog_file_path " + return $catalog_file + " + + # Replace message tags in the tcl file and insert into catalog file + lang::util::replace_temporary_tags_with_lookups $tcl_file + + aa_unstub lang::catalog::get_catalog_file_path + + # Read the contents of the catalog file + array set catalog_array [lang::catalog::parse [lang::catalog::read_file $catalog_file]] + array set updated_messages_array [lindex [array get catalog_array messages] 1] + + # Assert that the old messages are unchanged + foreach old_message_key [array names messages_array] { + aa_true "old key $old_message_key should be unchanged" [string equal $messages_array($old_message_key) \ + $updated_messages_array($old_message_key)] } + + # Check that the first new key was autogenerated + aa_true "check autogenerated key" [string equal $updated_messages_array(Auto_Key) $new_text_1] + + # Check that the second new key was made unique and inserted + aa_true "check key made unique" [string equal $updated_messages_array(${new_key_2}_1) $new_text_2] + + # Check that the third key was not inserted + aa_true "third key not inserted" [string equal [lindex [array get updated_messages_array $new_key_3] 1] \ + $messages_array($new_key_3)] + + # Check that there are no tags left in the tcl file + set tcl_file_id [open "[acs_root_dir]/$tcl_file" r] + set updated_tcl_contents [read $tcl_file_id] + close $tcl_file_id + aa_true "tags in tcl file replaced" [expr [llength [lang::util::get_temporary_tags_indices $updated_tcl_contents]] == 0] + + # Delete the test message keys + foreach message_key [concat [array names messages_array] $expected_new_keys] { + lang::message::unregister $package_key $message_key + } + # Delete the catalog files + file delete $catalog_backup_file + file delete $catalog_file + + # Delete the tcl files + file delete "[acs_root_dir]/$tcl_file" + file delete "[acs_root_dir]/$tcl_backup_file" } aa_register_case util__get_hash_indices {