Skip to content

'sk test' command upgrades #7308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
aa887bd
SkriptCommand - add tab completer for test scripts
ShaneBeee Dec 23, 2024
9905e89
SkriptCommand - add "all" option
ShaneBeee Dec 23, 2024
793645d
SkriptCommand - fix issue with not grabbing from sub directories
ShaneBeee Dec 23, 2024
e2637a3
SkriptCommand - fix a directory issue
ShaneBeee Dec 23, 2024
0b87211
SkriptCommand - change var name
ShaneBeee Dec 23, 2024
7e6143d
SkriptCommand - cleaned this up
ShaneBeee Dec 23, 2024
759bbb3
SkriptCommand - log results to file
ShaneBeee Dec 23, 2024
24fdb4c
SkriptCommand - Use suggested method
ShaneBeee Dec 23, 2024
9ffb7ce
Skript - easier to read output for tests
ShaneBeee Dec 23, 2024
0b913ca
SkriptCommand - fix unicode characters
ShaneBeee Dec 23, 2024
108b84f
Merge branch 'dev/feature' into shane/test-mode-auto-complete
Efnilite Dec 24, 2024
31aae88
Merge branch 'dev/feature' into shane/test-mode-auto-complete
Efnilite Dec 24, 2024
c481788
SkriptCommand - adjust how we're grabbing test scripts
ShaneBeee Dec 26, 2024
07702ce
Merge remote-tracking branch 'origin/shane/test-mode-auto-complete' i…
ShaneBeee Dec 26, 2024
b7b3418
TestResults - color updates
ShaneBeee Dec 26, 2024
d478942
TestResults - remove double append
ShaneBeee Dec 26, 2024
c2d45a1
Merge branch 'dev/feature' into shane/test-mode-auto-complete
cheeezburga Dec 27, 2024
233dc7e
SkriptCommand - requested changes
ShaneBeee Dec 27, 2024
18a2d3b
Merge remote-tracking branch 'origin/shane/test-mode-auto-complete' i…
ShaneBeee Dec 27, 2024
dcfb6dd
Merge branch 'dev/feature' into shane/test-mode-auto-complete
ShaneBeee Dec 29, 2024
9207ad2
Merge branch 'dev/feature' into shane/test-mode-auto-complete
Efnilite Dec 29, 2024
37272cf
Merge branch 'dev/feature' into shane/test-mode-auto-complete
Efnilite Dec 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.google.common.collect.Lists;
import com.google.gson.Gson;

import com.google.gson.GsonBuilder;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
import org.bukkit.*;
Expand Down Expand Up @@ -773,7 +774,10 @@ protected void afterErrors() {
EffObjectives.fail();

info("Collecting results to " + TestMode.RESULTS_FILE);
String results = new Gson().toJson(TestTracker.collectResults());
String results = new GsonBuilder()
.setPrettyPrinting() // Easier to read lines
.disableHtmlEscaping() // Fixes issue with "'" character in test strings going unicode
.create().toJson(TestTracker.collectResults());
try {
Files.write(TestMode.RESULTS_FILE, results.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
Expand Down
38 changes: 32 additions & 6 deletions src/main/java/ch/njol/skript/SkriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import ch.njol.skript.test.runner.SkriptTestEvent;
import ch.njol.skript.test.runner.TestMode;
import ch.njol.skript.test.runner.TestTracker;
import ch.njol.skript.test.utils.TestResults;
import ch.njol.skript.util.ExceptionUtils;
import ch.njol.skript.util.FileUtils;
import ch.njol.skript.util.SkriptColor;
import ch.njol.skript.util.Utils;
import ch.njol.util.OpenCloseable;
import ch.njol.util.StringUtils;
import com.google.gson.GsonBuilder;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -32,7 +34,7 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
Expand Down Expand Up @@ -406,10 +408,21 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}
} else {
scriptFile = TestMode.TEST_DIR.resolve(
Arrays.stream(args).skip(1).collect(Collectors.joining(" ")) + ".sk"
).toFile();
TestMode.lastTestFile = scriptFile;
if (args[1].equalsIgnoreCase("all")) {
scriptFile = TestMode.TEST_DIR.toFile();
} else {
String fileName = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));

// Add .sk if the file is not a directory and doesn't currently have .sk
if (!fileName.endsWith(".sk") && !fileName.endsWith("/"))
fileName += ".sk";

// Tab complete starts with a slash, let's get rid of it
if (fileName.startsWith("/"))
fileName = fileName.substring(1);
scriptFile = TestMode.TEST_DIR.resolve(fileName).toFile();
TestMode.lastTestFile = scriptFile;
}
}

if (!scriptFile.exists()) {
Expand All @@ -425,10 +438,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
ScriptLoader.unloadScripts(ScriptLoader.getLoadedScripts());

// Get results and show them
String[] lines = TestTracker.collectResults().createReport().split("\n");
TestResults testResults = TestTracker.collectResults();
String[] lines = testResults.createReport().split("\n");
for (String line : lines) {
Skript.info(sender, line);
}

// Log results to file
Skript.info(sender, "Collecting results to " + TestMode.RESULTS_FILE);
String results = new GsonBuilder()
.setPrettyPrinting() // Easier to read lines
.disableHtmlEscaping() // Fixes issue with "'" character in test strings going unicode
.create().toJson(testResults);
try {
Files.writeString(TestMode.RESULTS_FILE, results);
} catch (IOException e) {
Skript.exception(e, "Failed to write test results.");
}
})
);
} else if (args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("show")) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ch/njol/skript/SkriptCommandTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
if (args[0].equalsIgnoreCase("update") && args.length == 2) {
options.add("check");
options.add("changes");
} else if (args[0].matches("(?i)(reload|disable|enable)") && args.length >= 2) {
File scripts = Skript.getInstance().getScriptsFolder();
} else if (args[0].matches("(?i)(reload|disable|enable|test)") && args.length >= 2) {
File scripts = TestMode.DEV_MODE ? TestMode.TEST_DIR.toFile() : Skript.getInstance().getScriptsFolder();
String scriptsPathString = scripts.toPath().toString();
int scriptsPathLength = scriptsPathString.length();

Expand Down
Loading