Skip to content

Commit

Permalink
Merge pull request #9848 from marler8997/dtests
Browse files Browse the repository at this point in the history
Start replacing bash tests with D
  • Loading branch information
thewilsonator authored Jul 15, 2019
2 parents 22113af + 0a483b3 commit 0858136
Show file tree
Hide file tree
Showing 18 changed files with 537 additions and 76 deletions.
19 changes: 16 additions & 3 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,12 @@ fail_compilation_tests=$(fail_compilation_tests_long) \
$(wildcard fail_compilation/*.html)
fail_compilation_test_results=$(addsuffix .out,$(addprefix $(RESULTS_DIR)/,$(fail_compilation_tests)))

dshell_tests=$(wildcard dshell/*.d)
dshell_test_results=$(addsuffix .out,$(addprefix $(RESULTS_DIR)/,$(dshell_tests)))

all: run_tests

test_tools=$(RESULTS_DIR)/d_do_test$(EXE) $(RESULTS_DIR)/sanitize_json$(EXE)
test_tools=$(RESULTS_DIR)/d_do_test$(EXE) $(RESULTS_DIR)/dshell_prebuilt$(OBJ) $(RESULTS_DIR)/sanitize_json$(EXE)

$(RESULTS_DIR)/%.out: % $(RESULTS_DIR)/.created $(test_tools) $(DMD)
$(QUIET) $(RESULTS_DIR)/d_do_test $<
Expand All @@ -165,9 +168,10 @@ $(RESULTS_DIR)/.created:
$(QUIET)if [ ! -d $(RESULTS_DIR)/runnable ]; then mkdir $(RESULTS_DIR)/runnable; fi
$(QUIET)if [ ! -d $(RESULTS_DIR)/compilable ]; then mkdir $(RESULTS_DIR)/compilable; fi
$(QUIET)if [ ! -d $(RESULTS_DIR)/fail_compilation ]; then mkdir $(RESULTS_DIR)/fail_compilation; fi
$(QUIET)if [ ! -d $(RESULTS_DIR)/dshell ]; then mkdir $(RESULTS_DIR)/dshell; fi
$(QUIET)touch $(RESULTS_DIR)/.created

run_tests: unit_tests start_runnable_tests start_compilable_tests start_fail_compilation_tests
run_tests: unit_tests start_runnable_tests start_compilable_tests start_fail_compilation_tests start_dshell_tests

unit_tests: $(RESULTS_DIR)/unit_test_runner$(EXE)
@echo "Running unit tests"
Expand All @@ -191,7 +195,13 @@ start_fail_compilation_tests: $(RESULTS_DIR)/.created $(test_tools)
@echo "Running fail compilation tests"
$(QUIET)$(MAKE) $(DMD_TESTSUITE_MAKE_ARGS) --no-print-directory run_fail_compilation_tests

run_all_tests: unit_tests run_runnable_tests run_compilable_tests run_fail_compilation_tests
run_dshell_tests: $(dshell_test_results)

start_dshell_tests: $(RESULTS_DIR)/.created $(test_tools)
@echo "Running dshell tests"
$(QUIET)$(MAKE) $(DMD_TESTSUITE_MAKE_ARGS) --no-print-directory run_dshell_tests

run_all_tests: unit_tests run_runnable_tests run_compilable_tests run_fail_compilation_tests run_dshell_tests

start_all_tests: $(RESULTS_DIR)/.created
$(QUIET)$(MAKE) $(DMD_TESTSUITE_MAKE_ARGS) --no-print-directory $(test_tools)
Expand All @@ -208,6 +218,9 @@ $(RESULTS_DIR)/d_do_test$(EXE): tools/d_do_test.d $(RESULTS_DIR)/.created
$(DMD) -conf= $(MODEL_FLAG) $(DEBUG_FLAGS) -lowmem -od$(RESULTS_DIR) -of$(RESULTS_DIR)$(DSEP)d_do_test$(EXE) $<
@wait $(pid)

$(RESULTS_DIR)/dshell_prebuilt$(OBJ): tools/dshell_prebuilt/dshell_prebuilt.d
$(DMD) -conf= $(MODEL_FLAG) -of$(RESULTS_DIR)/dshell_prebuilt$(OBJ) -c $< $(PIC_FLAG)

$(RESULTS_DIR)/sanitize_json$(EXE): tools/sanitize_json.d $(RESULTS_DIR)/.created
@echo "Building sanitize_json tool"
@echo "OS: '$(OS)'"
Expand Down
18 changes: 18 additions & 0 deletions test/dshell/depsprot.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import dshell;
void main()
{
Vars.set("deps_file", "$OUTPUT_BASE/compile.deps");
run("$DMD -m$MODEL -deps=$deps_file -Idshell/imports -o- $EXTRA_FILES/$TEST_NAME.d");
Vars.deps_file
.grep("^$TEST_NAME.*${TEST_NAME}_default")
.grep("private")
.enforceMatches("Default import protection in dependency file should be 'private'");
Vars.deps_file
.grep("^$TEST_NAME.*${TEST_NAME}_public")
.grep("public")
.enforceMatches("Public import protection in dependency file should be 'public'");
Vars.deps_file
.grep("^$TEST_NAME.*${TEST_NAME}_private")
.grep("private")
.enforceMatches("Private import protection in dependency file should be 'private'");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions test/dshell/test9377.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import dshell;
void main()
{
Vars.set("libname", "$OUTPUT_BASE/a$LIBEXT");

run("$DMD -m$MODEL -I$EXTRA_FILES -of$libname -c $EXTRA_FILES/mul9377a.d $EXTRA_FILES/mul9377b.d -lib");
run("$DMD -m$MODEL -I$EXTRA_FILES -of$OUTPUT_BASE/a$EXE $EXTRA_FILES/multi9377.d $libname");
}
14 changes: 14 additions & 0 deletions test/dshell/test_shared.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dshell;
void main()
{
if (OS != "linux")
{
writefln("Skipping shared library test on %s.", OS);
return;
}

run("$DMD -m$MODEL -of$OUTPUT_BASE/a$EXE -defaultlib=libphobos2.so $EXTRA_FILES/test_shared.d");
run("$OUTPUT_BASE/a$EXE", stdout, [
"LD_LIBRARY_PATH" : "../../phobos/generated/"~OS~"/release/"~MODEL
]);
}
77 changes: 64 additions & 13 deletions test/run.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import tools.paths;
const scriptDir = __FILE_FULL_PATH__.dirName.buildNormalizedPath;
auto testPath(R)(R path) { return buildNormalizedPath(scriptDir, path); }
string resultsDir = testPath("test_results");
immutable testDirs = ["runnable", "compilable", "fail_compilation"];
immutable testDirs = ["runnable", "compilable", "fail_compilation", "dshell"];
shared bool verbose; // output verbose logging
shared bool force; // always run all tests (ignores timestamp checking)
shared string hostDMD; // path to host DMD binary (used for building the tools)
Expand All @@ -33,7 +33,8 @@ enum TestTools
{
unitTestRunner = TestTool("unit_test_runner", [toolsDir.buildPath("paths")]),
testRunner = TestTool("d_do_test"),
jsonSanitizer = TestTool("sanitize_json")
jsonSanitizer = TestTool("sanitize_json"),
dshellPrebuilt = TestTool("dshell_prebuilt", null, Yes.linksWithTests),
}

immutable struct TestTool
Expand All @@ -44,6 +45,9 @@ immutable struct TestTool
/// Extra arguments that should be supplied to the compiler when compiling the tool.
string[] extraArgs;

/// Indicates the tool is a binary that links with tests
Flag!"linksWithTests" linksWithTests;

alias name this;
}

Expand Down Expand Up @@ -92,7 +96,7 @@ Options:
if (runUnitTests)
{
verifyCompilerExists(env);
ensureToolsExists(TestTools.unitTestRunner);
ensureToolsExists(env, TestTools.unitTestRunner);
return spawnProcess(unitTestRunnerCommand ~ args).wait();
}

Expand Down Expand Up @@ -120,7 +124,7 @@ Options:
int ret;
auto taskPool = new TaskPool(jobs);
scope(exit) taskPool.finish();
ensureToolsExists(EnumMembers!TestTools);
ensureToolsExists(env, EnumMembers!TestTools);
foreach (target; taskPool.parallel(targets, 1))
{
log("run: %-(%s %)", target.args);
Expand All @@ -147,27 +151,56 @@ void verifyCompilerExists(string[string] env)
Builds the binary of the tools required by the testsuite.
Does nothing if the tools already exist and are newer than their source.
*/
void ensureToolsExists(const TestTool[] tools ...)
void ensureToolsExists(string[string] env, const TestTool[] tools ...)
{
resultsDir.mkdirRecurse;

shared uint failCount = 0;
foreach (tool; tools.parallel(1))
{
const targetBin = resultsDir.buildPath(tool).exeName;
const sourceFile = toolsDir.buildPath(tool ~ ".d");
string targetBin;
string sourceFile;
if (tool.linksWithTests)
{
targetBin = resultsDir.buildPath(tool).objName;
sourceFile = toolsDir.buildPath(tool, tool ~ ".d");
}
else
{
targetBin = resultsDir.buildPath(tool).exeName;
sourceFile = toolsDir.buildPath(tool ~ ".d");
}
if (targetBin.timeLastModified.ifThrown(SysTime.init) >= sourceFile.timeLastModified)
writefln("%s is already up-to-date", tool);
else
{
const command = [
hostDMD,
"-of"~targetBin,
sourceFile
] ~ tool.extraArgs;
string[] command;
string[string] commandEnv = null;
if (tool.linksWithTests)
{
// This will compile the dshell library thus needs the actual
// DMD compiler under test
command = [
env["DMD"],
"-conf=",
"-m"~env["MODEL"],
"-of" ~ targetBin,
"-c",
sourceFile
] ~ getPicFlags(env);
commandEnv = env;
}
else
{
command = [
hostDMD,
"-of"~targetBin,
sourceFile
] ~ tool.extraArgs;
}

writefln("Executing: %-(%s %)", command);
if (spawnProcess(command).wait)
if (spawnProcess(command, commandEnv).wait)
{
stderr.writefln("failed to build '%s'", targetBin);
atomicOp!"+="(failCount, 1);
Expand Down Expand Up @@ -431,3 +464,21 @@ auto exeName(T)(T name)
name ~= ".exe";
return name;
}

// Add the object filename extension to the given `name` for the current OS.
auto objName(T)(T name)
{
version(Windows)
return name ~ ".obj";
else
return name ~ ".o";
}

/// Return the correct pic flags as an array of strings
string[] getPicFlags(string[string] env)
{
const picFlags = env["PIC_FLAGS"];
if (picFlags.length)
return picFlags.split();
return cast(string[])[];
}
35 changes: 0 additions & 35 deletions test/runnable/depsprot.sh

This file was deleted.

7 changes: 0 additions & 7 deletions test/runnable/test9377.sh

This file was deleted.

12 changes: 0 additions & 12 deletions test/runnable/test_shared.sh

This file was deleted.

Loading

0 comments on commit 0858136

Please sign in to comment.