Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .circleci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ check_clean_git()
check_run_individual()
{
local build_path=generated/linux/release/$MODEL
"${build_path}/dmd" -i -run ./test/run.d test/runnable/template2962.d ./test/compilable/test14275.d
"${build_path}/dmd" -I./test -i -run ./test/run.d test/runnable/template2962.d ./test/compilable/test14275.d
}

# Checks the D build.d script
Expand Down
9 changes: 2 additions & 7 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,14 @@ subPackage {
preGenerateCommands `
"$${DUB_EXE}" \
--arch=$${DUB_ARCH} \
--compiler=$${DC} \
--single "$${DUB_PACKAGE_DIR}config.d" \
-- "$${DUB_PACKAGE_DIR}generated/dub" \
"$${DUB_PACKAGE_DIR}VERSION" \
/etc
` platform="posix"

preGenerateCommands `
"%DUB_EXE%" ^
--arch=%DUB_ARCH% ^
--single "%DUB_PACKAGE_DIR%config.d" ^
-- "%DUB_PACKAGE_DIR%generated/dub" ^
"%DUB_PACKAGE_DIR%VERSION"
` platform="windows"
preGenerateCommands `"%DUB_EXE%" --arch=%DUB_ARCH% --compiler="%DC%" --single "%DUB_PACKAGE_DIR%config.d" -- "%DUB_PACKAGE_DIR%generated/dub" "%DUB_PACKAGE_DIR%VERSION"` platform="windows"

stringImportPaths "generated/dub"

Expand Down
12 changes: 11 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ $(RESULTS_DIR)/.created:
$(QUIET)if [ ! -d $(RESULTS_DIR)/fail_compilation ]; then mkdir $(RESULTS_DIR)/fail_compilation; fi
$(QUIET)touch $(RESULTS_DIR)/.created

run_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

unit_tests: $(RESULTS_DIR)/unit_test_runner$(EXE)
@echo "Running unit tests"
$<

run_runnable_tests: $(runnable_test_results)

Expand Down Expand Up @@ -193,3 +197,9 @@ $(RESULTS_DIR)/sanitize_json$(EXE): tools/sanitize_json.d $(RESULTS_DIR)/.create
@echo "PIC: '$(PIC_FLAG)'"
$(DMD) -conf= $(MODEL_FLAG) $(DEBUG_FLAGS) -od$(RESULTS_DIR) -of$(RESULTS_DIR)$(DSEP)sanitize_json$(EXE) -i $<

$(RESULTS_DIR)/unit_test_runner$(EXE): tools/unit_test_runner.d $(RESULTS_DIR)/.created | $(DMD)
@echo "Building unit_test_runner tool"
@echo "OS: '$(OS)'"
@echo "MODEL: '$(MODEL)'"
@echo "PIC: '$(PIC_FLAG)'"
$(DMD) -conf= $(MODEL_FLAG) $(DEBUG_FLAGS) -od$(RESULTS_DIR) -of$(RESULTS_DIR)$(DSEP)unit_test_runner$(EXE) -i $<
59 changes: 59 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,64 @@ Note:
- `AUTO_UPDATE` doesn't work with tests that have multiple `TEST_OUTPUT` segments
- `AUTO_UPDATE` can be set as an environment variable or as Makefile-like argument assignment

### Running the Unit Tests

The unit tests will automatically run when all tests are run using `./run.d` or
`make`. To only run the unit tests the `./run.d unit_tests` command can be used.
For a more finer grain control over the unit tests the `./run.d -u` command can
be used:

To run all unit tests:

```sh
./run.d -u
```

To only run the unit tests in one or more specific files:

```sh
./run.d -u unit/deinitialization.d
```

To only run a subset of the unit tests in a single file:

```sh
./run.d -u unit/deinitialization.d --filter Expression
```

In the above example, the `--filter` flag will filter to only run the tests with
a UDA matching the given value, in this case `Expression`.

```d
@("Target.deinitialize")
unittest {}

@("Expression.deinitialize")
unittest {}
```

Of the above unit tests, only the second one will be run, since
`--filter Expression` was specified.

The `--filter` flag works when no files are specified as well.

## Types of Tests

There are two types of tests in the DMD test suite:

* **End-to-end test**. These are tests that invokes the compiler as an external
process in some kind of way. Then it asserts either the exit code or the output
of the compiler. These tests are located in `compilable`, `fail_compilation` and
`runnable`.

* **Unit tests**. These tests are more of a unit test, integration or
functional style tests. These tests are using the compiler as a library. They
are more flexible because they can assert state internal to the compiler which
the end-to-end tests would never have access to. The unit test runner will
compile all files in the `unit` directory into a single executable and run the
tests. This should make it quick to run the tests since only a single process
need to be started.

Makefile targets
----------------

Expand All @@ -74,6 +132,7 @@ Makefile targets
run_runnable_tests: run just the runnable tests
run_compilable_tests: run just the compilable tests
run_fail_compilation_tests: run just the fail compilation tests
unit_test: run all unit tests (those in the "unit" directory)

quick: run all tests with no default permuted args
(individual test specified options still honored)
Expand Down
Loading