In c++ code we can use the following code to check if valid x display has been set
if (!XOpenDisplay(NULL)) {
}
How to check in TCL if valid x display has been set. What is equivalent code for above code in TCL.
The simplest method is to see if package require Tk fails. Alas, this can fail for other reasons too, but even so.
if {[catch {package require Tk} msg]} {
puts stderr "No DISPLAY or PATH problem: $msg"
exit 1
}
Related
I am working on some code with unit tests using catch2 (and it will stay that way, for reasons).
Now, in the set of unit tests, there are a lot of (pairs of) lines which look like this:
T t1;
t1 = foo(some, params, here);
CHECK(my_compare(t1, T{some_literal}));
so, my_out_param is being set using a single function call, and then it's compared to a T literal.
Now, when this runs and fails, I get:
/path/to/test.cpp:493: Failure:
CHECK(my_compare(t1, T{some_literal}));
with expansion:
false
but obviously I don't get the "some, params, here". Well, I need it. Otherwise, I don't really know which test failed without reading the source code.
Since there's a reliance on macros here, I can't just wrap CHECK() in a function and do something fancy inside.
What would you suggest I do to make "some, params, here" get printed alongside "some_literal" when the check fails, while:
Keeping my test source code terse.
Not repeating myself
Still getting a valid file and line number
?
Note: The currently-used version of catch2 is 2.7.0, merged into a single header. If a version change would help, that may be doable.
Use the CAPTURE or INFO logging macros (see https://github.com/catchorg/Catch2/blob/devel/docs/logging.md#streaming-macros).
CAPTURE(some);
CAPTURE(params);
CAPTURE(here);
or
INFO("Params: some="<<some<<", params="<<params<<", here="<<here);
should do the trick.
BTW CAPTURE only logs variables that were captured in the same section as the failed test. Example:
SECTION("foo"){
int i = 1;
CAPTURE(i);
CHECK(i==1);
}
SECTION("bar"){
int j = 2;
CAPTURE(j);
CHECK(j==1);
}
outputs
foo.cpp:10: FAILED:
CHECK( j==1 )
with expansion:
2 == 1
with message:
j := 2
I have a testbench to test my VHDL device (DUT), but part of the DUT debug output is an ASSERT/REPORT message to the console, which I would like to check for correctness but I can't change the DUT. The only way I can think of is to post-process the output log file.
Is there any way of capturing the console output in the testbench, so I can check the DUT output directly?
I do this as part of the testbench. However, rather than Assert, I use OSVVM alerts, log, and print. OSVVM is both at osvvm.org and github.
Rather than Assert, I use AffirmIf for self-checking/result checking. I use AlertIf for parameter checking.
Step 1 is get OSVVM. Once you have the code, compile it using the script. In either Mentor or Aldec, run the script by doing:
vlib osvvm
vmap osvvm osvvm
do $PATH_TO_OSVVM/osvvm.do $PATH_TO_OSVVM
Use VHDL-2008 and include all of OSVVM in your program by doing:
library osvvm;
context osvvm.OsvvmContext;
Then rather than:
assert Data /= expected report "..." severity error;
Do:
AffirmIf(Data = Expected, "...") ;
Both assert and AffirmIf/AlertIf print. However, the advantage to AffirmIf/AlertIf is that internally it keeps a count of the errors and you can get a pass fail at the end of your test by doing:
ReportAlerts;
The next advantage of OSVVM AffirmIf/AlertIf/Log/Print is that if you want the results in a file, you simply do:
TranscriptOpen("./results/Test1.txt");
If you want to both print to the screen and a file, also do:
SetTranscriptMirror(TRUE);
That ought get you started. I will leave the rest to the user guides. Start by looking at both the AlertLog package user guide and the transcript package user guide.
We have a Tcl built in our C/C++ application, I found the place in our code where Tcl_EvalObjv is called if the command was not found. I have to admit that the code is pretty old and not many of our developers know what happens in this module.
It looks like this:
// ... there is some checking if command is registered etc., it fails and the code goes here:
std::vector<Tcl_Obj*> tclArgs = { NULL };
for (int i = 1; i < objc; ++i)
tclArgs.push_back(objv[i]);
tclArgs.shrink_to_fit();
// ...
tclArgs[0] = ::Tcl_NewStringObj(ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN_SIZE);
Tcl_IncrRefCount(tclArgs[0]);
::Tcl_ExposeCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
result = ::Tcl_EvalObjv(pInterp, objc, &tclArgs[0], TCL_EVAL_GLOBAL); //<--
::Tcl_HideCommand(pInterp, ORIGINAL_UNKNOWN, ORIGINAL_UNKNOWN);
// ORIGINAL_UNKNOWN is char* it is just "unknown"
We have handlers for commands in our application, while executing Tcl_EvalObjv in CmdUnknown() function Tcl sometimes calls different commands. Examples below:
List of existing commands: "banana", "applepie", "carpet", "card"
Command: "apple", Tcl calls "applepie" (wrong, "apple" is not "applepie")
Command: "blah", Tcl gives error (correctly).
Command: "car", Tcl gives error (correctly, maybe because of 2 similar commands).
Is there are some kind of mechanism that Tcl does when it fails in searching for command? The thing is that I can't find anything that is related to our code that would complete the commands so maybe Tcl does?
As glenn hinted at, Tcl in interactive (REPL) mode allows for dispatching commands using some minimal but unambiguous name prefix. I cannot tell how your embedded Tcl is configured, initialised, and ended up being run as in interactive mode. However, you may want to try to "turn off" (toggle) the interactive mode, by either:
unset ::tcl_interactive
or
set ::tcl_interactive 0
All of this is implemented by the default unknown handler. Watch out for how the list of cmds is looked up and how it is treated differently when tcl_interactive is true or false:
puts [info body unknown]
I have used the program command in Stata quite a few times now.
Today, I am trying to teach myself how to create a program that uses input. I've tried looking at the syntax help file and at page 71 of these lecture slides I found on the internet, but I can't figure out how to do this.
I would appreciate it if you could show me some documentation that covers this specific topic thoroughly. Or just point out what I'm doing wrong below.
As you can see, all I want is to create a short program that checks whether a file exists in the specified folder (capture confirm file), but I want to display my own dialogue box if there is an error (window stopbox note) and if so, then exit the do file in an orderly manner (exit 601).
cap program drop checkfile
program checkfile
syntax varlist, folder(varname) file(varname)
capture confirm file "`folder'/`file'"
if _rc == 601 {
window stopbox note `"`file' is not in `folder'"' // creates a dialogue box for the error
exit 601
}
end
checkfile folder(C:\Users\User\Documents) file(NIDSw5.dta)
Returns the error:
factor-variable and time-series operators not allowed
r(101);
I'm not sure how to use syntax in order to get the folder path and file name. Note that these are usually strings, but I'm guessing that:
"`folder'/`file'"
will result in, for example, ""C:\Users\User\Documents"/"NIDSw5.dta"" if the input is done with quotation marks, so that's why I thought I should use the local(input) method.
Also note that I will use a global variable ($DataIN) instead of putting the folder path string there, and the file name contains a global variable appended onto a string.
Removing varlist, results in the error:
invalid syntax
r(197);
The following works for me:
program checkfile
syntax, folder(string) file(string)
capture confirm file "`folder'/`file'"
if _rc == 601 {
window stopbox note `"`file' is not in `folder'"'
exit 601
}
end
You then simply need to type:
checkfile, folder(C:\Users\User\Documents) file(NIDSw5.dta)
EDIT:
You can also do it without using options as follows:
program checkfile
capture confirm file "`1'/`2'"
if _rc == 601 {
window stopbox note `"`2' is not in `1'"'
exit 601
}
end
checkfile C:\Users\User\Documents NIDSw5.dta
I'd like to disable the gdb behavior where typing a carriage return repeats execution of the last command entered. I'd just like it to do nothing. Is this possible?
It seems that repeating most commmands is a default gdb's behavior and there is no setting to change it. This is how it looks in gdb's source:
/* Handle a complete line of input. This is called by the callback
mechanism within the readline library. Deal with incomplete
commands as well, by saving the partial input in a global
buffer. */
static void
command_line_handler (char *rl)
{
...
int repeat = (instream == stdin);
So as you can see repeat is assigned 1 if instream is STDIN. There is no other way to assign repeat a different value.
So what you can do is to build your own gdb executable on your machine from gdb`s source (http://ftp.gnu.org/gnu/gdb/). But before building change a little the line 591 in gdb/event-top.c. Instead of
int repeat = (instream == stdin);
write
int repeat = 0;
One possible trick that might work -- I didn't try it -- would be to use Python to set the prompt callback to invoke "dont-repeat".
It seems like a reasonable feature request to me that gdb have a setting to disable command repetition.