The following code gives the error
Expected 'while' in 'do-while' loop
if let path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
do {
let stringFromFile = try String(contentsOfFile:path, encoding: NSUTF8StringEncoding)
var chapters: [String] = stringFromFile.componentsSeparatedByString("#")
chapters.removeAtIndex(0)
} catch {
print((error))
}
}
it was working fine before, but now it's giving me an error. Does anyone know why?
That code works for me as-is in the Playground with the appropriate Chapters.txt file in the Resources folder; XCode 7.1 Build 7B60. Did you try Shift-Command-K for a Clean Build?
Something does not seem right with your error message. With Swift 2.0, there are no more do-while loops. They have been replaced by repeat-while loops instead. As your code snippet shows, do has been repurposed for do-try-catch error handling.
this is a simple recursion function
func recursion(parameter : Double)
{
if parameter < 12
{
recursion(parameter + 1)
}
print(parameter)
}
when i am trying to put a simple value for example 0 or 1
recursion(0)
i get a compile error saying Missing argument for #1 in call any idea why this is happening?
btw if i change the function to
func recursion(parameter : Double)
{
if parameter > 1
{
recursion(parameter - 1)
}
print(parameter)
}
everything works fine
any ideas? i am using Xcode 7 beta
Your code works fine, just make a Clean & Build and then try it again and the initial compile error should disappear. Remember that Xcode 7 is still in Beta, Apple is working to fix this kind of false compile errors properly.
I hope this help you.
Is it possible to have Xcode run your unit tests multiple times?
I had an issue in several unit tests that caused intermittent failures. Now that I think I've fixed it, my only option appears to mash ⌘ + U until I'm 95% confident the bug is gone.
I know other unit testing frameworks make it quite easy to run a single test, test case, or test suite multiple times. Do we have this luxury in XCTest yet?
For me it works in swift
override func invokeTest() {
for time in 0...15 {
print("this test is being invoked: \(time) times")
super.invokeTest()
}
}
Try overriding invoke test: https://developer.apple.com/documentation/xctest/xctestcase/1496282-invoketest?language=objc
- (void)invokeTest
{
for (int i=0; i<100; i++) {
[super invokeTest];
}
}
It might help you to use
func testMultiple() {
self.measureBlock() {
...
XCTAssert(errMessage == nil, "no error expected")
}
}
This runs the code inside self.measureBlock() multiple times to measure the average time.
It is work to change the code, but you might want to know the execution time anyways.
This answer might be close enough to what you want and it is easy to do.
One alternative is to do this via the command line. You can run a single test using the -only-testing argument, and avoid building using test-without-building i.e. (new lines added for clarity)
for i in {1..10}; \
do xcodebuild \
test-without-building \
-workspace MyApp.xcworkspace \
-scheme Debug \
-destination 'platform=iOS Simulator,OS=11.2,name=iPhone 8' \
-only-testing:MyApp.Tests/TestFile/myTest;
done
Try using a for loop:
func testMultiple() {
for _ in 0...100 {
...
XCTAssert(errMessage == nil, "no error expected")
}
}
Note this doesn't work within a self.measureBlock(). You'll get an NSInternalConsistencyException: Cannot measure metrics while already measuring metrics
However, you can CALL this within a measureBlock():
func testMultiple() {
for _ in 0...100 {
...
XCTAssert(errMessage == nil, "no error expected")
}
}
func testPerformance() {
self.measureBlock() {
self.testMultiple()
}
}
Xcode 8 runs the measureBlock code 10 times.
I had used the invokeTest() override in the past (Xcode 10) with great success. But now in Xcode 11 its not working (for me at least). What I ended up doing was:
func test99Loop() {
for i in 0..<LOOP_COUNT {
if i > 0 { tearDown(); sleep(1); setUp() }
test3NineUrls()
do { tearDown(); sleep(1) }
setUp()
test6NineCombine()
print("Finished Loop \(i)")
}
}
I obviously use setup/teardown, and this is the proper way to do those multiple times (since the first and last are called by Xcode).
You can now do this in Xcode
Edit the Test Plan. In the Test Navigator, at the top you should see "Test Plan: MyAppName (Default)". Tap on this and select "Edit Test Plan".
In the editor, select Configurations, Configuration 1
Under Test Execution you can set Test Repetition Mode and Maximum Test Repetitions.
Run the tests from the menu Product > Test
Xcode has a built-in way you can do this:
Right-click the test and select Run <test> Repeatedly...
That menu has a few configurations, one of them is Stop After where you can select Failure which will stop the execution if it failed during one of the repetitions.
You can also run a test class or the whole test suite repeatedly.
My code looks like this:
-(void)setGuiDisplayMode:(id)mode
{
// constrain inputs
if ( [mode intValue] < 3 && [mode intValue] > -1 ) {
guiDisplayMode=[mode intValue];
} else {
guiDisplayMode=0;
}
NSString *titles[3]={
#"Narg",
#"Fubar",
#"Eep"};
[mView[0] setValue:titles[guiDisplayMode] forKey:#"inputTitle"];
}
When I build this in Xcode 4.6.3 using the Apple LLVM compiler 4.2, I get an "Unused Entity Issue" "Unused variable 'titles'" warning which is clearly incorrect. When I look at the compiler output, there is no warning there, so apparently the warning is coming from the post-compilation "indexing" that Xcode does.
Since this warning isn't coming from the compiler, is there anything I can do about it? Is this a known Xcode bug?
Thanks,
Chris
I have been writing a GCC inter procedural plugin where I have to insert GIMPLE statements
at certain points in the program. After this I perform a data flow analysis on the complete
program. When I am done with my analysis I am removing those newly inserted GIMPLE statements.
My analysis is getting completed but just before exiting from it the following message is generated:
internal compiler error: in execute_ipa_pass_list, at passes.c:1817
This is surely because of the insertion of GIMPLE statements, if I don't do that I won't get this error message.
Could anyone help me out and explain what is the problem and how to fix it?
This usually happens when GCC code contains an assertion which turns out to be false.
The line 1817 in passes.c (which is part of the GCC sources, in the gcc sub-directory of the GCC source tree) has a piece of code which looks like:
gcc_assert (some_condition);
In your case, some_condition was false, but the compiler expects it to be always true (this is why the author of the code wrote the assertion in the first place).
You did something in your plugin which made it false, and you need to fix it.
What did you do wrong? It really depends. Open up passes.c and find that line, and see what it is checking. In my copy of GCC, the relevant function reads:
void
execute_ipa_pass_list (struct opt_pass *pass)
{
do
{
/* An assertion. */
gcc_assert (!current_function_decl);
/* Another assertion. */
gcc_assert (!cfun);
/* Another assertion. */
gcc_assert (pass->type == SIMPLE_IPA_PASS || pass->type == IPA_PASS);
if (execute_one_pass (pass) && pass->sub)
{
if (pass->sub->type == GIMPLE_PASS)
{
invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_START, NULL);
do_per_function_toporder ((void (*)(void *))execute_pass_list,
pass->sub);
invoke_plugin_callbacks (PLUGIN_EARLY_GIMPLE_PASSES_END, NULL);
}
else if (pass->sub->type == SIMPLE_IPA_PASS
|| pass->sub->type == IPA_PASS)
execute_ipa_pass_list (pass->sub);
else
gcc_unreachable ();
}
/* Another assertion. */
gcc_assert (!current_function_decl);
cgraph_process_new_functions ();
pass = pass->next;
}
while (pass);
}
There are four gcc_assert statements. Your plugin caused one of them to become false. i.e. you messed with one of the variables:
current_function_decl
cfun
pass->type
This is probably what's wrong.