summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/suite/ctor_files/ctor.cc.bar58
-rw-r--r--test/suite/ctor_files/ctor.cc.base58
-rw-r--r--test/suite/hello.cc6
-rwxr-xr-xtest/suite/test.sh77
4 files changed, 199 insertions, 0 deletions
diff --git a/test/suite/ctor_files/ctor.cc.bar b/test/suite/ctor_files/ctor.cc.bar
new file mode 100644
index 0000000..2c9df2a
--- /dev/null
+++ b/test/suite/ctor_files/ctor.cc.bar
@@ -0,0 +1,58 @@
+// -*- c++ -*-
+// Distributed under the BSD 2-Clause License.
+// See accompanying file LICENSE for details.
+#include <libctor.h>
+//#include "config.h"
+
+namespace
+{
+BuildConfigurations ctorConfigs()
+{
+ return
+ {
+ {
+ .name = "hello",
+ .target = "hello",
+ .sources = {
+ "hello.cc",
+ },
+ .cxxflags = {
+ "-std=c++20",
+ "-O3",
+ "-g",
+ "-Wall",
+ "-Werror",
+ },
+ .externals = {"bar"},
+ }
+ };
+}
+
+ExternalConfigurations ctorExtConfigs()
+{
+ return
+ {
+ {
+ .name = "bar",
+ .cxxflags = { "-D_A_", "-DBAR"},
+ .cflags = { "-D_B_" },
+ .ldflags = { "-D_C_" },
+ .asmflags = { "-D_D_" },
+ // Creates --with-foo-prefix arg to configure which will be used for
+ // -L and -I flags.
+ // If not specified configure will try to find them in the system paths.
+ },
+// {
+// .name = "bar",
+// .type = TargetType::ExternalPkgConfig,
+// .min_version = "0.1",
+// .max_version = "0.9",
+// // cflags, cxxflags and ldflags deduced by pkg-config tool (or parsed
+// // directly from .pc if faster)
+// },
+ };
+}
+}
+
+REG(ctorConfigs);
+REG(ctorExtConfigs);
diff --git a/test/suite/ctor_files/ctor.cc.base b/test/suite/ctor_files/ctor.cc.base
new file mode 100644
index 0000000..d9b8e4d
--- /dev/null
+++ b/test/suite/ctor_files/ctor.cc.base
@@ -0,0 +1,58 @@
+// -*- c++ -*-
+// Distributed under the BSD 2-Clause License.
+// See accompanying file LICENSE for details.
+#include <libctor.h>
+//#include "config.h"
+
+namespace
+{
+BuildConfigurations ctorConfigs()
+{
+ return
+ {
+ {
+ .name = "hello",
+ .target = "hello",
+ .sources = {
+ "hello.cc",
+ },
+ .cxxflags = {
+ "-std=c++20",
+ "-O3",
+ "-g",
+ "-Wall",
+ "-Werror",
+ },
+ .externals = {"bar"},
+ }
+ };
+}
+
+ExternalConfigurations ctorExtConfigs()
+{
+ return
+ {
+ {
+ .name = "bar",
+ .cxxflags = { "-D_A_", "-DFOO"},
+ .cflags = { "-D_B_" },
+ .ldflags = { "-D_C_" },
+ .asmflags = { "-D_D_" },
+ // Creates --with-foo-prefix arg to configure which will be used for
+ // -L and -I flags.
+ // If not specified configure will try to find them in the system paths.
+ },
+// {
+// .name = "bar",
+// .type = TargetType::ExternalPkgConfig,
+// .min_version = "0.1",
+// .max_version = "0.9",
+// // cflags, cxxflags and ldflags deduced by pkg-config tool (or parsed
+// // directly from .pc if faster)
+// },
+ };
+}
+}
+
+REG(ctorConfigs);
+REG(ctorExtConfigs);
diff --git a/test/suite/hello.cc b/test/suite/hello.cc
new file mode 100644
index 0000000..06e3deb
--- /dev/null
+++ b/test/suite/hello.cc
@@ -0,0 +1,6 @@
+#include <iostream>
+
+int main()
+{
+ std::cout << "Hello\n";
+}
diff --git a/test/suite/test.sh b/test/suite/test.sh
new file mode 100755
index 0000000..8d22206
--- /dev/null
+++ b/test/suite/test.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+
+function fail
+{
+ echo "*** Failure at line $1"
+ exit 1
+}
+
+function ctor
+{
+ echo "*** Running: ./ctor $*"
+ ./ctor $*
+}
+
+# Wipe the board
+rm -Rf build
+rm -f configuration.cc
+rm -f ctor
+
+cp ctor_files/ctor.cc.base ctor.cc
+
+# Compile bootstrap binary
+g++ -pthread -std=c++20 -L../../build -lctor -I../../src ctor.cc -o ctor || fail ${LINENO}
+
+# No build files should have been created yet
+[ -d build ] && fail ${LINENO}
+
+# capture md5 sum of ctor binary before configure is called
+MD5=`md5sum ctor`
+ctor configure --ctor-includedir ../../src --ctor-libdir ../../build
+
+# ctor should be rebuilt at this point, so md5 sum should have changed
+(echo $MD5 | md5sum --status -c) && fail ${LINENO}
+
+# configuration.cc should have been generated now
+[ ! -f configuration.cc ] && fail ${LINENO}
+
+# Shouldn't compile anything yet - only configure
+[ -f build/hello-hello_cc.o ] && fail ${LINENO}
+
+MD5=`md5sum ctor`
+
+# Run normally to build project
+ctor -v
+
+# Compiled object should now exist
+[ ! -f build/hello-hello_cc.o ] && fail ${LINENO}
+
+# ctor should not have been rebuilt, so md5 sum should be the same
+(echo $MD5 | md5sum --status -c) || fail ${LINENO}
+
+MOD1=`stat -c %Y build/hello-hello_cc.o`
+touch hello.cc
+sleep 1.1
+
+# Run normally to rebuild hello.cc
+ctor -v
+
+# Object file should have been recompiled
+MOD2=`stat -c %Y build/hello-hello_cc.o`
+[[ $MOD1 == $MOD2 ]] && fail ${LINENO}
+
+# Replacve -DFOO with -DBAR in foo external.cxxflags
+cp ctor_files/ctor.cc.bar ctor.cc
+
+MD5C=`md5sum configuration.cc`
+MD5=`md5sum ctor`
+MOD1=`stat -c %Y build/hello-hello_cc.o`
+sleep 1.1
+
+# Run normally to reconfigure, rebuild ctor and rebuild hello.cc
+ctor -v
+
+MOD2=`stat -c %Y build/hello-hello_cc.o`
+[[ $MOD1 == $MOD2 ]] && fail ${LINENO}
+(echo $MD5C | md5sum --status -c) && fail ${LINENO}
+(echo $MD5 | md5sum --status -c) && fail ${LINENO}