Skip to content

Commit

Permalink
test demo service messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tsharmaMW committed Nov 15, 2024
1 parent 63147dd commit 8776deb
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ public void unzipToTempDir(String zipName) throws IOException {
zipFile.extractAll(tempDirectory.toString());
}

public void copyTestPluginsToTempDir(String pluginName) throws IOException{
File pluginFileLocation = new File(this.tempDirectory, pluginName);

// Ensure the directory structure exists
File parentDir = pluginFileLocation.getParentFile();
if (!parentDir.exists()) {
if (!parentDir.mkdirs()) {
throw new IOException("Failed to create directories: " + parentDir);
}
}

copyFileToWorkspace(pluginName, pluginFileLocation);
}

public void copyFileToWorkspace(String sourceFile, File targetFile) throws IOException {
InputStream is = MatlabCommandRunner.class.getClassLoader().getResourceAsStream(sourceFile);
java.nio.file.Files.copy(is, targetFile.toPath(), REPLACE_EXISTING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
ProgramCommandLine value;
try {
value = this.runner.createCommand(getContext(), getMatlabCommand());
this.runner.copyTestPluginsToTempDir(MatlabConstants.TEST_VISUALIZATION_PLUGIN);
this.runner.copyTestPluginsToTempDir(MatlabConstants.TEST_VISUALIZATION_PLUGIN_SERVICE);
} catch (Exception e) {
throw new RunBuildException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
ProgramCommandLine value;
try {
this.runner.unzipToTempDir(MatlabConstants.MATLAB_SCRIPT_GENERATOR);
this.runner.copyTestPluginsToTempDir(MatlabConstants.TEST_VISUALIZATION_PLUGIN);
this.runner.copyTestPluginsToTempDir(MatlabConstants.TEST_VISUALIZATION_PLUGIN_SERVICE);
value = this.runner.createCommand(getContext(), runnerScript);
} catch (Exception e) {
throw new RunBuildException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
classdef TestVisualizationPlugin < matlab.unittest.plugins.TestRunnerPlugin

% Copyright 2024 The MathWorks, Inc.

methods (Access=protected)

% Write about covered edgecases as well for function based tests instead of class based tests

function runTest(plugin, pluginData)
classAndTestName = strrep(pluginData.Name,"/",".");
% fprintf("##teamcity[testStarted name='%s' captureStandardOutput='true']",pluginData.Name)
% fprintf("##teamcity[testStarted name='%s' captureStandardOutput='true']",pluginData.TestSuite.TestClass + "." + pluginData.TestSuite.ProcedureName)
% In the above method -> Test class becomes null for function based tests
fprintf("##teamcity[testStarted name='%s' captureStandardOutput='true']", classAndTestName)

% Invoke super class method to run the test
[email protected](plugin, pluginData);

result = pluginData.TestResult;

if result.Failed

% display(result.Details.DiagnosticRecord.Report);

% Not using fprintf as it treats / as a backslash escape character, which we recieve in the error logs like In L:\Projects\matlab-teamcity-plugin. (errors out)
% fprintf(result.Details.DiagnosticRecord.Report);

% fprintf("##teamcity[testFailed name='%s' errorDetails='%s' status='ERROR']", pluginData.Name, result.Details.DiagnosticRecord.Report); % possibly include error details here
% fprintf("##teamcity[testFailed name='%s' status='ERROR']", pluginData.Name);
fprintf("##teamcity[testFailed name='%s' status='ERROR']", classAndTestName);
elseif result.Incomplete
% fprintf("##teamcity[testIgnored name='%s']", pluginData.Name);
fprintf("##teamcity[testIgnored name='%s']", classAndTestName);
end

% fprintf("##teamcity[testFinished name='%s' duration='%f']", pluginData.Name, result.Duration)
fprintf("##teamcity[testFinished name='%s' duration='%f']", classAndTestName, result.Duration)
end

% pluginData.TestResult.Passed | pluginData.TestResult.Failed | pluginData.TestResult.Incomplete

% function runTestSuite(plugin, pluginData)
% fprintf("##teamcity[testSuiteStarted name='%s']","suiteName")

% groupNumber = pluginData.Group;
% totalGroups = pluginData.NumGroups;
% suiteSize = numel(pluginData.TestSuite);
% fprintf('### Running %d tests in Group %d of %d\n', suiteSize, groupNumber, totalGroups);

% % Invoke the super class method
% [email protected](plugin, pluginData)

% fprintf("##teamcity[testSuiteFinished name='%s']","suiteName")
% % pluginData.TestSuite.TestClass
% end

function runSession(plugin, pluginData)
% Introspect into pluginData to get TestSuite size
suiteSize = numel(pluginData.TestSuite);
fprintf('### Running a total of %d tests\n', suiteSize);
fprintf('test run session started\n');
% fprintf("##teamcity[testRetrySupport enabled='true']");
% Invoke the super class method
[email protected](plugin, pluginData)
fprintf("##teamcity[testRetrySupport enabled='true']");
fprintf('test run session ended');
end

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
classdef TestVisualizationPluginService < matlab.buildtool.internal.services.ciplugins.CITestRunnerPluginService
% Copyright 2024 The MathWorks, Inc.

methods
function plugins = providePlugins(~, ~)
plugins = ciplugins.teamcity.TestVisualizationPlugin();
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public interface MatlabConstants {
static final String RUN_EXE_MACI = "maci64/run-matlab-command";
static final String RUN_EXE_LINUX = "glnxa64/run-matlab-command";
static final String MATLAB_SCRIPT_GENERATOR = "matlab-script-generator.zip";

// MATLAB default plugin paths
static final String TEST_VISUALIZATION_PLUGIN = "+ciplugins/+teamcity/TestVisualizationPlugin.m";
static final String TEST_VISUALIZATION_PLUGIN_SERVICE = "+matlab/+unittest/+internal/+services/+plugins/TestVisualizationPluginService.m";

//Test runner file prefix
static final String MATLAB_TEST_RUNNER_FILE_PREFIX = "runner_";

Expand Down

0 comments on commit 8776deb

Please sign in to comment.