]> rtime.felk.cvut.cz Git - omk.git/blobdiff - tests/programs-cflags
Add failing test
[omk.git] / tests / programs-cflags
index 96faf2192c28453a38be342d09d239a31ceefb92..73d0b361c5dfa3704da53c8623f0752dc5eae3d3 100755 (executable)
@@ -1,9 +1,91 @@
 #!/bin/bash
 
-. ./functions.sh
+. ./wvtest.sh
 
-touch config.omk-default
-echo "CFLAGS=-DNUMBER=123" > config.omk
-make||error "Can't compile"
-[ $OMK_RULES != linux ] && canttest "Should work only with Linux rules"
-_compiled/bin/test|grep 123 || error "Custom CFLAGS didn't influence the output"
+create_files() {
+    cat > 'test.c' <<'EOF'
+#include <stdio.h>
+
+int main()
+{
+#ifdef NUMBER
+        printf("NUMBER is %d\n", NUMBER);
+#endif
+        return 0;
+}
+EOF
+    cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = test
+test_SOURCES = test.c
+EOF
+}
+
+grepbinout() {
+    if [ $OMK_RULES = linux ]; then
+       # The following should work only with Linux rules
+       local bin=$1
+       shift
+       _compiled/bin/$bin|grep $@
+    fi
+}
+grepout() {
+    grepbinout test $@
+}
+
+set -o pipefail
+
+WVSTART "OMK_CFLAGS"
+create_files
+needs_valid_CC
+WVPASS make OMK_CFLAGS=-DNUMBER=123
+WVPASS grepout 123
+
+WVSTART "CFLAGS override OMK_CFLAGS"
+create_files
+WVPASS make OMK_CFLAGS=-DNUMBER=123 CFLAGS=-DNUMBER=321
+WVPASS grepout 321
+
+
+WVSTART "OMK_CFLAGS in config.omk"
+create_files
+echo "OMK_CFLAGS=-DNUMBER=123" > config.omk
+WVPASS make
+WVPASS grepout 123
+
+WVSTART "Target specific CFLAGS"
+create_files
+cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = test
+test_SOURCES = test.c
+test_CFLAGS = -DNUMBER=123
+EOF
+WVPASS make V=1
+WVPASS grepout 123
+
+WVSTART "Target specific CFLAGS override OMK_CFLAGS"
+create_files
+cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = test
+test_SOURCES = test.c
+test_CFLAGS = -DNUMBER=123
+OMK_CFLAGS   = -DNUMBER=456
+EOF
+WVPASS make V=1
+WVPASS grepout 123
+
+WVSTART "Same source compiled twice with different CFLAGS"
+create_files
+cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = a b
+a_SOURCES = test.c
+a_CFLAGS = -DNUMBER=123
+b_SOURCES = test.c
+b_CFLAGS = -DNUMBER=456
+EOF
+WVPASS make V=1
+WVPASS grepbinout a 123
+WVPASS grepbinout b 456
+
+WVSTART "CFLAGS is not set by default"
+create_files
+WVPASS sh -c '! make -qp|grep "^CFLAGS ="'