Skip to content

Commit

Permalink
Add test on download and install lib on usage.
Browse files Browse the repository at this point in the history
Both test that when user does not wnat to download install Sloeber does
not do it and the reverse.
  • Loading branch information
jan committed Nov 24, 2024
1 parent 6b02f9d commit a50ceea
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ArduinoLibraryVersion(JsonElement json, ArduinoLibrary arduinoLibrary) {
archiveFileName = getSafeString(jsonObject, "archiveFileName");
size = jsonObject.get("size").getAsInt();
checksum = getSafeString(jsonObject, "checksum");
calculateFQN();
myFQN=calculateFQN(getName());
} catch (Exception e) {
throw new JsonParseException("failed to parse json " + e.getMessage(),e);
}
Expand Down Expand Up @@ -205,9 +205,8 @@ public IPath getExamplePath() {
return getInstallPath().append(EXAMPLES_FOLDER);
}

private void calculateFQN() {
myFQN= Path.fromPortableString(SLOEBER_LIBRARY_FQN);
myFQN=myFQN.append(MANAGED).append(getName());
static public IPath calculateFQN(String libName) {
return Path.fromPortableString(SLOEBER_LIBRARY_FQN).append(MANAGED).append(libName);
}

@Override
Expand Down
40 changes: 40 additions & 0 deletions io.sloeber.tests/src/io/sloeber/core/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -792,4 +793,43 @@ public void NightlyBoardPatron(String name, MCUBoard boardID, Example example, C

}

@Test
public void onlyInstallLibraryWhenAllowed() throws Exception {
String libName="SD";

//set option not to install lib
ConfigurationPreferences.setInstallLibraries(false);

//uninstall lib
LibraryManager.uninstallLibrary( libName);

// create a project that uses a the lib
String testName = "onlyInstallLibraryWhenAllowed";
IProgressMonitor monitor=new NullProgressMonitor();
IPath templateFolder = Shared.getTemplateFolder(testName);
CodeDescription codeDescriptor = CodeDescription.createCustomTemplate(templateFolder);
MCUBoard unoboard = Arduino.uno();
IProject theTestProject = SloeberProject.createArduinoProject(testName, null, unoboard.getBoardDescriptor(), codeDescriptor,
new CompileDescription(), monitor);
//wait for indexer and so on
Shared.waitForAllJobsToFinish();


//Building the project should fail
assertNotNull( Shared.buildAndVerify(theTestProject,3,IncrementalProjectBuilder.FULL_BUILD ,monitor),"Sloeber wrongly installed lib "+libName);

//set option to install libs
ConfigurationPreferences.setInstallLibraries(true);

//trigger the indexer
ICProject cTestProject = CoreModel.getDefault().getCModel().getCProject(theTestProject.getName());
CCorePlugin.getIndexManager().reindex(cTestProject);
Shared.waitForIndexer(theTestProject);

//build should not fail
assertNull( Shared.buildAndVerify(theTestProject,3,IncrementalProjectBuilder.FULL_BUILD ,monitor),"Sloeber dit not install lib "+libName);



}
}
41 changes: 24 additions & 17 deletions io.sloeber.tests/src/io/sloeber/core/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -259,23 +260,9 @@ public static String buildAndVerifyGivenBuilders(String projectName, BoardDescri
autoDesc.setBuilder(curBuilder);
coreModel.setProjectDescription(theTestProject, projectDescription);

theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);

if (hasBuildErrors(theTestProject)!=null) {
Shared.waitForAllJobsToFinish();
Thread.sleep(2000);
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
if (hasBuildErrors(theTestProject)!=null) {
Shared.waitForAllJobsToFinish();
Thread.sleep(2000);
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
String buildError=hasBuildErrors(theTestProject);
if (buildError!=null) {
myLastFailMessage = myLastFailMessage + NEWLINE +buildError+ NEWLINE+ "Failed to compile the project:" + projectName
+ " with builder " + curBuilder;
}
}
}
buildAndVerify(theTestProject,3,IncrementalProjectBuilder.FULL_BUILD, monitor);



}
if (!myLastFailMessage.isBlank()) {
Expand All @@ -295,6 +282,26 @@ public static String buildAndVerifyGivenBuilders(String projectName, BoardDescri
return null;
}

static String buildAndVerify(IProject theTestProject, int maxTries, int buildType, IProgressMonitor monitor) throws Exception {
int curTry = 0;
String buildError=null;
while (curTry++ < maxTries) {
theTestProject.build(buildType, monitor);
Shared.waitForAllJobsToFinish();
Thread.sleep(2000);
buildError = hasBuildErrors(theTestProject);
if (buildError == null) {
return buildError;
}
}
IAutoBuildConfigurationDescription autoDesc = IAutoBuildConfigurationDescription
.getActiveConfig(theTestProject,false);
String builder=autoDesc.getBuilder().getId();
myLastFailMessage = myLastFailMessage + NEWLINE + buildError + NEWLINE + "Failed to compile the project:"
+ theTestProject.getName() + " with builder " + builder;
return buildError;
}

/*
* For some boards that do not run out of the box we know how to fix it. This
* code fixes these things
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Arduino.h"
#include "SD.h"
//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here
}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here
}

0 comments on commit a50ceea

Please sign in to comment.