mirror of
https://github.com/github/codeql.git
synced 2026-04-24 16:25:15 +02:00
Add a build system for the junit tests.
This is a bit more complicated than our usual setup, as we both need to unzip the typescript parser wrapper, and make node accessible on the path.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.semmle.js.extractor.FileExtractor;
|
||||
import com.semmle.js.extractor.FileExtractor.FileType;
|
||||
import com.semmle.js.extractor.VirtualSourceRoot;
|
||||
import com.semmle.util.data.StringUtil;
|
||||
import com.semmle.util.exception.Exceptions;
|
||||
import com.semmle.util.exception.UserError;
|
||||
import com.semmle.util.files.FileUtil;
|
||||
import com.semmle.util.files.FileUtil8;
|
||||
@@ -443,8 +444,12 @@ public class AutoBuildTests {
|
||||
|
||||
/** Hide {@code p} on using {@link DosFileAttributeView} if available; otherwise do nothing. */
|
||||
private void hide(Path p) throws IOException {
|
||||
try {
|
||||
DosFileAttributeView attrs = Files.getFileAttributeView(p, DosFileAttributeView.class);
|
||||
if (attrs != null) attrs.setHidden(true);
|
||||
} catch (IOException e) {
|
||||
Exceptions.ignore(e, "On Linux within the bazel sandbox, we get a DosFileAttributeView that then throws an exception upon use");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
java_test(
|
||||
name = "test_jar",
|
||||
srcs = glob(["**/*.java"]),
|
||||
test_class = "com.semmle.js.extractor.test.AllTests",
|
||||
deps = [
|
||||
"//javascript/extractor",
|
||||
"//javascript/extractor:deps",
|
||||
"@//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
|
||||
],
|
||||
)
|
||||
|
||||
# We need to unzip the typescript wrapper, and provide node on the path.
|
||||
# Therefore, we're wrapping the java_test inside a sh_test.
|
||||
sh_test(
|
||||
name = "test",
|
||||
size = "small",
|
||||
srcs = ["run_tests.sh"],
|
||||
args = [
|
||||
"$(execpath @nodejs//:node_bin)",
|
||||
"$(JAVABASE)/bin/java",
|
||||
"$(rootpath //javascript/extractor/lib/typescript)",
|
||||
"$(rootpath test_jar_deploy.jar)",
|
||||
],
|
||||
data = [
|
||||
":test_jar_deploy.jar",
|
||||
"//javascript/extractor/lib/typescript",
|
||||
"//javascript/extractor/parser-tests",
|
||||
"//javascript/extractor/tests",
|
||||
"@bazel_tools//tools/jdk:current_java_runtime",
|
||||
"@nodejs//:node_bin",
|
||||
],
|
||||
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
|
||||
)
|
||||
|
||||
31
javascript/extractor/test/com/semmle/js/extractor/test/run_tests.sh
Executable file
31
javascript/extractor/test/com/semmle/js/extractor/test/run_tests.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
NODE=$1
|
||||
JAVA=$2
|
||||
PARSER_WRAPPER=$3
|
||||
TEST_JAR=$4
|
||||
|
||||
TEMP=$(mktemp -d)
|
||||
|
||||
UNAME=$(uname -s)
|
||||
echo $UNAME
|
||||
# On Windows, the symlink set up by bazel that points at the test jar is a msys2/linux-style path
|
||||
# The JVM can't resolve that, therefore copy the jar to the temp directory, and then set the
|
||||
# windows path to it
|
||||
if [[ "$UNAME" =~ _NT ]]; then
|
||||
cp $TEST_JAR $TEMP/test.jar
|
||||
TEST_JAR=$(cygpath -w $TEMP/test.jar)
|
||||
echo "On Windows, new test jar: $TEST_JAR"
|
||||
fi
|
||||
|
||||
# unpack parser wrapper
|
||||
unzip -q $PARSER_WRAPPER -d $TEMP/parser_wrapper
|
||||
export SEMMLE_TYPESCRIPT_PARSER_WRAPPER=$TEMP/parser_wrapper/javascript/tools/typescript-parser-wrapper/main.js
|
||||
|
||||
# setup node on path
|
||||
NODE=$(realpath $NODE)
|
||||
export PATH="$PATH:$(dirname $NODE)"
|
||||
|
||||
$JAVA -Dbazel.test_suite=com.semmle.js.extractor.test.AllTests -jar $TEST_JAR
|
||||
EXIT_CODE=$?
|
||||
|
||||
rm -rf $TEMP
|
||||
exit $EXIT_CODE
|
||||
Reference in New Issue
Block a user