diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 61cba20..5c42f26 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -95,27 +95,11 @@ jobs: uses: dlang-community/setup-dlang@v1 with: compiler: ${{ matrix.compiler }} - - - name: "Example: hello-world" - working-directory: examples - run: dub -q build --single hello-world.d - - - name: "Example: using-headers" - working-directory: examples - run: dub -q build --single using-headers.d - - name: "Example: file-upload" + - name: Test Examples working-directory: examples - run: dub -q build --single file-upload.d - - - name: "Example: handler-testing" + run: rdmd runner.d test + + - name: Clean Examples working-directory: examples - run: dub test --single handler-testing.d - - - name: "Example: static-content-server" - working-directory: examples/static-content-server - run: dub -q build --single content_server.d - - - name: "Example: websocket" - working-directory: examples/websocket - run: dub -q build --single server.d + run: rdmd runner.d clean diff --git a/examples/runner.d b/examples/runner.d index 0894b6b..7f06266 100755 --- a/examples/runner.d +++ b/examples/runner.d @@ -1,4 +1,6 @@ #!/usr/bin/env rdmd +module examples.runner; + import std.stdio; import std.process; import std.conv; @@ -13,6 +15,7 @@ import core.thread; interface Example { string name() const; Pid run(string[] args) const; + Pid test() const; string[] requiredFiles() const; } @@ -51,6 +54,18 @@ class DubSingleFileExample : Example { ); } + Pid test() const { + return spawnProcess( + ["dub", "build", "--single", filename], + std.stdio.stdin, + std.stdio.stdout, + std.stdio.stderr, + null, + Config.none, + workingDir + ); + } + string[] requiredFiles() const { if (workingDir == ".") { return [filename]; @@ -77,6 +92,10 @@ class DubSingleFileUnitTestExample : Example { ); } + Pid test() const { + return run([]); + } + string[] requiredFiles() const { return [filename]; } @@ -86,6 +105,7 @@ const Example[] EXAMPLES = [ new DubSingleFileExample("hello-world.d"), new DubSingleFileExample("file-upload.d"), new DubSingleFileExample("using-headers.d"), + new DubSingleFileExample("path-handler.d"), new DubSingleFileExample("static-content-server", "content_server.d"), new DubSingleFileExample("websocket", "server.d"), new DubSingleFileUnitTestExample("handler-testing.d") @@ -102,6 +122,8 @@ int main(string[] args) { return 0; } else if (args.length > 1 && toLower(args[1]) == "run") { return runExamples(args[2..$]); + } else if (args.length > 1 && toLower(args[1]) == "test") { + return testExamples(); } writeln("Nothing to run."); return 0; @@ -192,3 +214,14 @@ int runExamples(string[] args) { } } } + +int testExamples() { + foreach (example; EXAMPLES) { + int exitCode = example.test().wait(); + if (exitCode != 0) { + writefln!"Example %s failed with exit code %d."(example.name, exitCode); + return exitCode; + } + } + return 0; +}