Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:19:02+00:00 2026-06-10T19:19:02+00:00

I have similar code for writing unit test where I need to check the

  • 0

I have similar code for writing unit test where I need to check the value of a variable.

#first.tcl
proc test {a} {
   if {$a < 10} {
      set sig 0
   } else {
      set sig 1
   }
} 
#second.tcl unit testing script
source "first.tcl"
test 10
expect 1 equal to $sig
test 5
expect 0 equal to $sig

Is there any way, that I can access the value of the variable “sig” as I can not change the first script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:19:03+00:00Added an answer on June 10, 2026 at 7:19 pm

    You have a problem. The problem is that in the first script, sig is a local variable that vanishes when the call to test terminates. You can’t examine it afterwards. As it happens, the result of test is the value assigned to sig; I don’t know whether you can count on that for testing purposes. If that’s sufficient, you can do this (assuming you have Tcl 8.5; for 8.4 you need a helper procedure instead of the apply term):

    source first.tcl
    trace add execution test leave {apply {{cmd code result op} {
        # Copy the result of [test] to the global sig variable
        global sig
        set sig $result
    }}}
    

    This intercepts (just like with aspect-oriented programming) the result of test and saves it to the global sig variable. What it doesn’t do though is correct for the problem in the tested code: the assignment is to a variable that goes away immediately after.


    If you’re doing lots of testing, consider using the tcltest to do the work. That’s the package that is used to test Tcl itself, and it lets you write a test of the result of executing a script very easily:

    # Setup of test harness
    package require tcltest
    source first.tcl
    
    # The tests
    tcltest::test test-1.1 {check if larger} -body {
        test 10
    } -result 1
    tcltest::test test-1.2 {check if smaller} -body {
        test 5
    } -result 0
    
    # Produce the final report
    tcltest::cleanupTests
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a set of test scenarios for my code, and currently I have
I have code similar to: number_to_currency(line_item.price, :unit => £) littering my views in various
In the program I am writing, I have something similar to the code here:
I am maintaining several Perl scripts that all have similar code blocks for different
I have a similar code snippet like this class Search { public function search($for,
I have code similar to the following: <div class=container> <div class=overlay> // hover content
I have code similar to the following with a URL like this... If I
I have code similar to this: public List<string> Expected = new List<string>(); public int
In a CUDA kernel, I have code similar to the following. I am trying
I have a large JSON file that contains A LOT of similar code. It's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.