diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-11 21:48:28 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-05-14 18:08:06 +0300 |
commit | cbd7cabcc3e6b24e80521bfec230e905f420ff4f (patch) | |
tree | f30aa2cd077fcb6a1939a7fdb79a80346d44d350 /tests | |
parent | 61cdde35094fc655eac2e6968b465f217e91d0ac (diff) |
Add some tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.gitignore | 2 | ||||
-rw-r--r-- | tests/build/.gitignore | 1 | ||||
-rw-r--r-- | tests/build/bootstrap.build | 9 | ||||
-rw-r--r-- | tests/build/root.build | 17 | ||||
-rw-r--r-- | tests/buildfile | 10 | ||||
-rw-r--r-- | tests/common.test | 43 | ||||
-rw-r--r-- | tests/fetch.test | 43 | ||||
-rw-r--r-- | tests/init.test | 95 | ||||
-rw-r--r-- | tests/new.test | 45 | ||||
-rw-r--r-- | tests/project.test | 26 | ||||
-rw-r--r-- | tests/status.test | 80 | ||||
-rw-r--r-- | tests/sync.test | 66 |
12 files changed, 437 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..35ec43f --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,2 @@ +test/ +test-*/ diff --git a/tests/build/.gitignore b/tests/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/tests/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/tests/build/bootstrap.build b/tests/build/bootstrap.build new file mode 100644 index 0000000..355a05a --- /dev/null +++ b/tests/build/bootstrap.build @@ -0,0 +1,9 @@ +# file : tests/build/bootstrap.build +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +project = # Unnamed subproject. + +using config +using dist +using test diff --git a/tests/build/root.build b/tests/build/root.build new file mode 100644 index 0000000..58b2eaf --- /dev/null +++ b/tests/build/root.build @@ -0,0 +1,17 @@ +# file : tests/build/root.build +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# We need to configure C++ module to pass the compiler path to some of bdep +# test commands. +# +using cxx + +# Setup the bdep that we are testing. +# +import bdep = bdep%exe{bdep} +test{*}: test = $bdep + +# Specify the test target for cross-testing. +# +test.target = $cxx.target diff --git a/tests/buildfile b/tests/buildfile new file mode 100644 index 0000000..4caf55d --- /dev/null +++ b/tests/buildfile @@ -0,0 +1,10 @@ +# file : tests/buildfile +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +define common: file +common{*}: extension = test + +commons = common project + +./: test{* -{$commons}} common{$commons} $bdep diff --git a/tests/common.test b/tests/common.test new file mode 100644 index 0000000..8e83b23 --- /dev/null +++ b/tests/common.test @@ -0,0 +1,43 @@ +# file : tests/common.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Commonly-used variables setup and driver command line. +# + +# Use the same build system driver as the one running the tests (as opposed +# to one that may or may not be found via PATH). A common approach will be to +# run build2 as a sanity check in a directory produced/updated by the bdep +# command being tested. +# +build = $recall($build.path) +test.options += --build $build + +# Helper commands that can be used by tests to prepare the testing environment +# or validate an outcome of the command being tested. They are likely to get +# additional options and redirects appended prior to use. A common approach +# will be to redirect output to the null device for commands that are used for +# test setup, and to match it for commands being tested or performing teardown +# (for example, to make sure that configuration post-test state is valid and is +# as expected). +# +new = $* new +status = $* status +init = $* init +sync = $* sync +fetch = $* fetch + +# All testscripts are named after bdep commands, for example sync.test. So the +# testscript scope id is a name of the command being tested. +# +cmd = [string] $@ +test.arguments = $cmd + +# Convenience variables for supporting Windows/POSIX testscript variants. +# +win32 = ($cxx.target.class == 'windows') +exe = ($win32 ? '.exe' : '') + +# @@ It would be nice to query bdep for the bpkg path it uses. +# +bpkg = ("$config.bdep.test.bpkg" != '' ? "$config.bdep.test.bpkg" : "bpkg$exe") diff --git a/tests/fetch.test b/tests/fetch.test new file mode 100644 index 0000000..ad0640e --- /dev/null +++ b/tests/fetch.test @@ -0,0 +1,43 @@ +# file : tests/fetch.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include common.test project.test + +new += 2>! +init += cc "config.cxx=$config.cxx" -d prj 2>! +status += --all + +: add-dependency +: +{ + $clone_prj; + $init -C prj-cfg @cfg &prj/build/bootstrap/*** &prj-cfg/***; + + $new -t lib --vcs none libfoo &libfoo/*** 2>!; + $new -t lib --vcs none libbar &libbar/*** 2>!; + + cat <<EOI >+prj/repositories.manifest; + : + role: prerequisite + location: ../libfoo + type: dir + : + role: complement + location: ../libbar + type: dir + EOI + + $* 2>>/"EOE"; + fetching dir:$~/libbar \(complements dir:$~/prj\) + fetching dir:$~/libfoo \(prerequisite of dir:$~/prj\) + EOE + + $status -d prj >'prj configured 0.1.0-a.0.19700101000000'; + + $bpkg list --complements --prerequisites -d prj-cfg >>/"EOO" + dir:$~/prj $~/prj + complement dir:$~/libbar $~/libbar + prerequisite dir:$~/libfoo $~/libfoo + EOO +} diff --git a/tests/init.test b/tests/init.test new file mode 100644 index 0000000..0200277 --- /dev/null +++ b/tests/init.test @@ -0,0 +1,95 @@ +# file : tests/init.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include common.test project.test + +new += 2>! +status += --all + +test.cleanups += &prj/build/bootstrap/*** &?prj-cfg/*** + +: cfg-create +: +: We will also test that the configuration variables are properly persisted and +: the project is properly built in the source tree. +: +{ + $clone_prj; + + $* -C prj-cfg @cfg cc "config.cxx=$config.cxx" 'config.cc.poptions=-DTEST' 2>>/~"%EOE%"; + initializing in project $~/prj/ + created configuration @cfg $~/prj-cfg/ \(1, default, forwarded, auto-synchronized\) + synchronizing: + % new prj.0\.1\.0-a\.0\.19700101000000% + EOE + + sed -n -e 's/^config.cc.poptions = (.+)$/\1/p' prj-cfg/build/config.build \ + >'-DTEST'; + + $status --directory prj >'prj configured 0.1.0-a.0.19700101000000'; + + $build prj/ 2>>/EOE &prj/prj/prj$exe; + mkdir prj-cfg/prj/fsdir{prj/} + c++ prj/prj/cxx{prj}@prj-cfg/prj/prj/ + ld prj-cfg/prj/prj/exe{prj} + ln prj-cfg/prj/prj/exe{prj} -> prj/prj/ + EOE + + $build prj-cfg/ 2>>/EOE + info: dir{prj-cfg/} is up to date + EOE +} + +: cfg-add +: +{ + create_cfg = $bpkg create cc "config.cxx=$config.cxx" -d 2>! + + $clone_prj; + + $create_cfg prj-cfg1/ &prj-cfg1/***; + $create_cfg prj-cfg2/ &prj-cfg2/***; + + $* -A prj-cfg1 @cfg1 2>>/~"%EOE%"; + initializing in project $~/prj/ + added configuration @cfg1 $~/prj-cfg1/ \(1, default, forwarded, auto-synchronized\) + synchronizing: + % new prj.0\.1\.0-a\.0\.19700101000000% + EOE + + $* -A prj-cfg2 @cfg2 2>>/~"%EOE%"; + initializing in project $~/prj/ + added configuration @cfg2 $~/prj-cfg2/ \(2, auto-synchronized\) + synchronizing: + % new prj.0\.1\.0-a\.0\.19700101000000% + EOE + + $status --directory prj >>EOO; + in configuration @cfg1: + prj configured 0.1.0-a.0.19700101000000 + + in configuration @cfg2: + prj configured 0.1.0-a.0.19700101000000 + EOO + + $build prj-cfg1/ 2>>/EOE; + mkdir prj-cfg1/prj/fsdir{prj/} + c++ prj/prj/cxx{prj}@prj-cfg1/prj/prj/ + ld prj-cfg1/prj/prj/exe{prj} + EOE + + $build prj-cfg2/ 2>>/EOE; + mkdir prj-cfg2/prj/fsdir{prj/} + c++ prj/prj/cxx{prj}@prj-cfg2/prj/prj/ + ld prj-cfg2/prj/prj/exe{prj} + EOE + + $build prj/ 2>>/EOE &prj/prj/prj$exe + ln prj-cfg1/prj/prj/exe{prj} -> prj/prj/ + info: prj-cfg1/dir{prj/} is up to date + EOE +} + +# @@ Test initializing a package rather than project. +# diff --git a/tests/new.test b/tests/new.test new file mode 100644 index 0000000..96cb4c5 --- /dev/null +++ b/tests/new.test @@ -0,0 +1,45 @@ +# file : tests/new.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include common.test + +: exe +{ + $* -t exe hello 2>>/"EOE" &hello/***; + created new executable project hello in $~/hello/ + EOE + + $build hello/ 2>>/EOE + c++ hello/hello/cxx{hello} + ld hello/hello/exe{hello} + EOE +} + +: lib +{ + $* -t lib libhello 2>>/"EOE" &libhello/***; + created new library project libhello in $~/libhello/ + EOE + + # We build the project by chunks to make sure the output is reproducible (no, + # -s doesn't really help). + # + echo "#include <libhello/version.hxx>" >+libhello/libhello/hello.hxx; + + $build libhello/libhello/libs{hello} 2>>/EOE; + ver libhello/libhello/version.hxx.in + c++ libhello/libhello/cxx{hello} + ld libhello/libhello/libs{hello} + EOE + + $build libhello/libhello/ 2>>/EOE; + c++ libhello/libhello/cxx{hello} + ld libhello/libhello/liba{hello} + EOE + + $build libhello/ 2>>/EOE + c++ libhello/tests/basics/cxx{driver} + ld libhello/tests/basics/exe{driver} + EOE +} diff --git a/tests/project.test b/tests/project.test new file mode 100644 index 0000000..06d6ccc --- /dev/null +++ b/tests/project.test @@ -0,0 +1,26 @@ +# file : tests/project.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +# Create and initialize a sample build2 C++ executable project that will be +# copied by subsequent tests and scopes setup commands. The common approach +# will be that group scopes copy and modify the parent scope project as +# required by the nested tests and scopes. Tests will also clone the parent +# scope project to optionally modify it, use and cleanup at the end. Note that +# project can not be shared between multiple bdep processes. Also we need to +# make sure that projects are not cloned while being used by bdep. +# ++$new prj 2>- &prj/*** # By default: -t exe -l c++. + +# The most commonly used project cloning command that copies it from the +# parent scope working directory. +# +clone_prj = cp -p -r ../prj ./ + +# Clones the original project from the root scope working directory. +# +clone_root_prj = cp -p -r $~/prj ./ + +# Setup a test command to use a cloned project directory by default. +# +test.arguments += -d prj diff --git a/tests/status.test b/tests/status.test new file mode 100644 index 0000000..bdf3434 --- /dev/null +++ b/tests/status.test @@ -0,0 +1,80 @@ +# file : tests/status.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include common.test project.test + +new += 2>! +init += cc "config.cxx=$config.cxx" -d prj 2>! +sync += -d prj 2>! + +: basic +: +{ + $clone_prj; + $init -C prj-cfg @cfg &prj/build/bootstrap/*** &prj-cfg/***; + + $* >'prj configured 0.1.0-a.0.19700101000000' +} + +: no-config +: +{ + $clone_prj; + + $* 2>>/"EOE" != 0 + error: no default configuration in project $~/prj/ + info: use \(@<cfg-name> | --config|-c <cfg-dir> | --all|-a\) to specify configuration explicitly + EOE +} + +: two-configs +: +{ + $clone_prj; + $init -C prj-cfg1 @cfg1 &prj-cfg1/*** &prj/build/bootstrap/***; + $init -C prj-cfg2 @cfg2 &prj-cfg2/***; + + $* @cfg2 >'prj configured 0.1.0-a.0.19700101000000'; + + $* --all >>EOO + in configuration @cfg1: + prj configured 0.1.0-a.0.19700101000000 + + in configuration @cfg2: + prj configured 0.1.0-a.0.19700101000000 + EOO +} + +: dependency +: +{ + $clone_prj; + $init -C prj-cfg @cfg &prj/build/bootstrap/*** &prj-cfg/***; + + $new -t lib --vcs none libhello &libhello/***; + + cat <<EOI >+prj/repositories.manifest; + : + role: prerequisite + location: ../libhello + type: dir + EOI + + cat <<EOI >+prj/manifest; + depends: libhello + EOI + + $* --recursive >>EOO 2>>/"EOE"; + prj configured 0.1.0-a.0.19700101000000 available 0.1.0-a.0.19700101000000#1 + EOO + fetching dir:$~/libhello \(prerequisite of dir:$~/prj\) + EOE + + $sync; + + $* --recursive >>~%EOO% + prj configured 0.1.0-a.0.19700101000000#1 + % libhello configured 0\.1\.0-a\.0\..+% + EOO +} diff --git a/tests/sync.test b/tests/sync.test new file mode 100644 index 0000000..1e044b2 --- /dev/null +++ b/tests/sync.test @@ -0,0 +1,66 @@ +# file : tests/sync.test +# copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +.include common.test project.test + +new += 2>! +init += cc "config.cxx=$config.cxx" -d prj 2>! +status += --all --recursive + +: dependency +: +{ + $clone_prj; + $init -C prj-cfg @cfg &prj/build/bootstrap/*** &prj-cfg/***; + + $new -t lib --vcs none libhello &libhello/***; + + cat <<EOI >+prj/repositories.manifest; + : + role: prerequisite + location: ../libhello + type: dir + EOI + + cat <<EOI >+prj/manifest; + depends: libhello + EOI + + sed -i -e 's/^(#import .+)$/import libs += libhello%lib{hello}/' \ + prj/prj/buildfile; + + cat <<EOI >=prj/prj/prj.cxx; + #include <iostream> + + #include <libhello/hello.hxx> + + using namespace std; + + int main (int argc, char* argv[]) + { + if (argc < 2) + { + cerr << "error: missing name" << endl; + return 1; + } + + hello::say_hello (cout, argv[1]); + } + EOI + + $* 2>>/~"%EOE%"; + fetching dir:$~/libhello \(prerequisite of dir:$~/prj\) + synchronizing: + % new libhello.0\.1\.0-a\.0\..+ \\\(required by prj\\\)% + % upgrade prj.0\.1\.0-a\.0\.19700101000000#1% + EOE + + $status -d prj >>~%EOO%; + prj configured 0.1.0-a.0.19700101000000#1 + % libhello configured 0\.1\.0-a\.0\..+% + EOO + + $build prj/ 2>! &prj/prj/prj$exe &?prj/prj/prj.exe.dlls/***; + prj/prj/prj 'testscript' >'Hello, testscript!' +} |