How to make a dependency on a command line parameter - scons

I have a command line variable (text string) which I inject into a file (the target file) using a builder. The question is, how to I trigger the building of the target file when the value of the the command line string changes?
One option might be to write the string to a text file, but I'd need to write that text file every time I build. Is there a cleaner way?

Not sure whether this really qualifies as "cleaner" way, but you can create a Value node:
mynode = env.Value(my_var_string)
and then use the Depends() method to let your target depend on this Value node:
env.Depends(final_target, mynode)
Please check the MAN page ( http://www.scons.org/doc/production/HTML/scons-man.html ) for a complete description of the Value method.

Related

Manipulate string in file using shell

I'm trying to modify a string in a file using shell script.
What in the file version.yaml:
Version: 1.0.0-ghjjh
What I expect:
Add a suffix -{given argument}to the version string given an argument if there is no suffix added yet. Otherwise modify the suffix using the given argument.
For a given argument 0:
For the above file I provided, there is no suffix, the expected result is Version: 1.0.0-ghjjh-0
After this string in the file already has the suffix. Next time for a given argument 6, the expected result is Version: 1.0.0-ghjjh-6
What's the simplest way to do this in shell script?
Store the version in a separate file and regenerate the YAML from a template.

Save responses to a file in JMeter with PostProcessor

I try to use following code in JSR223 PostProcessor to save response to CSV file in each iteration.
if(${__groovy(ctx.getPreviousResult().getResponseCode(),)} == "200"){
vars.put("response", prev.getResponseDataAsString());
String res="${response}";
FileWriter fstream = new FileWriter("logresult.csv",true);
fstream.write(res+"\n");
fstream.close();
}
I assume csv file should be created in same folder as jmx, but it isn't present after execution. I execute test in one thread.
Don't use ${} syntax in JSR223 script as part of JMeter best practices
if(prev.getResponseCode() == "200"){
String res=prev.getResponseDataAsString();
vars.put("response", res);
FileWriter fstream = new FileWriter("logresult.csv",true);
fstream.write(res+"\n");
fstream.close();
}
ensure the script does not use any variable using ${varName} as caching would take only first value of ${varName}. Instead use :
vars.get("varName")
Your syntax is not correct, you need to amend the first line to look like:
if(prev.getResponseCode().equals('200')){
also you don't need this line at all
String res="${response}";
instead use the following:
fstream.write(vars.get('response')+"\n");
see JSR223 Sampler documentation for comprehensive explanation, the relevant quote:
JMeter processes function and variable references before passing the script field to the interpreter, so the references will only be resolved once. Variable and function references in script files will be passed verbatim to the interpreter, which is likely to cause a syntax error.
In general you're going into wrong direction, in case if you run your test with > 1 thread you might run into the race condition when 2 threads will be writing into the same file resulting in garbage if not worse.
If you have to store the responses into a separate file I would recommend:
Extracting the whole response into a JMeter Variable using i.e. Regular Expression Extractor
Defining Sample Variable property to hold this value
Write the value into the file using Flexible File Writer

Executing functions stored in a string

Lets say that there is a function in my Delphi app:
MsgBox
and there is a string which has MsgBox in it.
I know what most of you are going to say is that its possible, but I think it is possible because I opened the compiled exe(compiled using delphi XE2) using a Resource Editor, and that resource editor was built for Delphi. In that, I could see most of the code I wrote, as I wrote it. So since the variables names, function names etc aren't changed during compile, there should a way to execute the functions from a string, but how? Any help will be appreciated.
EDIT:
What I want to do is to create a simple interpreter/scripting engine. And this is how its supposed to work:
There are two files, scr.txt and arg.txt
scr.txt contains:
msg_show
0
arg.txt contains:
"Message"
And now let me explain what that 0 is:
First, scr.txt's first line is function name
second line tells that at which line its arguments are in the arg.txt, i.e 0 tells that "Message" is the argument for msg_show.
I hope my question is now clear.
I want to make a simple scripting engine.
In order to execute arbitrary code stored as text, you need a compiler or an interpreter. Either you need to write one yourself, or embed one that already exists. Realistically, the latter option is your best option. There are a number available but in my view it's hard to look past dwscript.
I think I've already solved my problem! The answer is in this question's first answer.
EDIT:
But with that, as for a workaround of the problem mentioned in first comment, I have a very easy solution.
You don't need to pass all the arguments/parameters to it. Just take my example:
You have two files, as mentioned in the question. Now you need to execute the files. It is as simple as that:
read the first line of scr.txt
check if it's a function. If not, skip the line
If yes, read the next line which tells the index where it's arguments are in arg.txt
pass on the index(an integer) to the "Call" function.
Now to the function which has to be executed, it should know how many arguments it needs. i.e 2
Lets say that the function is "Sum(a,b : integer)".It needs 2 arguments
Now let the function read the two arguments from arg.txt.
And its done!
I hope it will help you all.
And I can get some rep :)

In Play Framework 1.2.x, how to use a render arg value in a path expression?

Let's say that I have a renderArg named xyz. In the groovy template, what's the syntax for using the value of the renderArg in a path expression?
For example:
href="##{'/public/stylesheets/whatever/${xyz}.css'}"
The above fails with a template compilation error (which is what I expected, really). How can I use the value of the render arg inside the path string?
I'll also need to use the arg in other path expressions (not just for a css file reference).
You cannot do it directly, but there is one workaround:
First you should have defined route to root of the application, for instance:
GET / Application.index
next you can use it in this way:
href="##{Application.index}public/stylesheets/whatever/${xyz}.css"
If you repeat the structure above very often, then you can use custom tag, to do so:
add file /app/views/tags/customlink.html(customlink is name of the tag, you can use another one),
fill the content:
##{Application.index}public/stylesheet/whatever/${_key}.css
You can use it now in this way:
href="#{customlink key:'xyz' /}"
More about custom tags you can read here

How to get the filename and line number of a particular JetBrains.ReSharper.Psi.IDeclaredElement?

I want to write a test framework extension for resharper. The docs for this are here: http://confluence.jetbrains.net/display/ReSharper/Test+Framework+Support
One aspect of this is indicating if a particular piece of code is part of a test. The piece of code is represented as a IDeclaredElement.
Is it possible to get the filename and line number of a piece of code represented by a particular IDeclaredElement?
Following up to the response below:
#Evgeny, thanks for the answer, I wonder if you can clarify one point for me.
Suppose the user has this test open in visual studio: https://github.com/fschwiet/DreamNJasmine/blob/master/NJasmine.Tests/SampleTest.cs
Suppose the user right clicks on line 48, the "player.Resume()" expression.
Will the IDeclaredElement tell me specifically they want to run at line 48? Or is it going to give me a IDeclaredElement corresponding to the entire class, and a filename/line number range for the entire class?
I should play with this myself, but I appreciate tapping into what you already know.
Yes.
The "IDeclaredElement" entity is the code symbol (class, method, variable, etc.). It could be loaded from assembly metadata, it could be declared in source code, it could come from source code implicitly.
You can use
var declarations = declaredElement.GetDeclarations()
to get all AST elements which declares it (this could return multiple declarations for partial class, for example)
Then, for any IDeclaration, you can use
var documentRange = declaration.GetDocumentRange()
if (documentRange.IsValid())
Console.WriteLine ("File: {0} Line:{1}",
DocumentManager.GetInstance(declaration.GetSolution()).GetProjectFile(documentRange.Document).Name,
documentRange.Document.GetCoordsByOffset(documentRange.TextRange.StartOffset).Line
);
By the way, which test framework extension are you developing?
Will the IDeclaredElement tell me specifically they want to run at
line 48?
Once more: IDeclaredElement has no positions in the file. Instead, it's declaration have them.
For every declaration (IDeclaration is a regular AST node) there is range in document which covers it. In my previous example, I used TextRange.StartOffset, though you can use TextRange.EndOffset.
If you need more prcise position in the file, please traverse AST tree, and check the coordinates in the document for specific expression/statement

Resources