summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-01 18:02:50 +0800
committerGitHub <[email protected]>2026-04-01 18:02:50 +0800
commit75b084fa57f2fe00f369d9cac3878c03da43a68a (patch)
tree8ea62a9f04b88e9ae72a59a2fd58d1f7b976797e /tests
parentd7fcddd12197d427ad89d8967515f2e7afd16790 (diff)
parent57ef7e0332355a091abe1ee9eefe2a359aeb6f1a (diff)
Merge pull request #7443 from xmake-io/replace
add utils.replace rules
Diffstat (limited to 'tests')
-rw-r--r--tests/apis/add_files_replace/src/config.h2
-rw-r--r--tests/apis/add_files_replace/src/main.c9
-rw-r--r--tests/apis/add_files_replace/test.lua3
-rw-r--r--tests/apis/add_files_replace/xmake.lua16
4 files changed, 30 insertions, 0 deletions
diff --git a/tests/apis/add_files_replace/src/config.h b/tests/apis/add_files_replace/src/config.h
new file mode 100644
index 000000000..96d83f651
--- /dev/null
+++ b/tests/apis/add_files_replace/src/config.h
@@ -0,0 +1,2 @@
+#pragma once
+#define VERSION "1.0"
diff --git a/tests/apis/add_files_replace/src/main.c b/tests/apis/add_files_replace/src/main.c
new file mode 100644
index 000000000..d2ac8f8ae
--- /dev/null
+++ b/tests/apis/add_files_replace/src/main.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include "config.h"
+
+#define HELLO "original"
+
+int main(int argc, char** argv) {
+ printf("hello %s, %s!\n", HELLO, VERSION);
+ return 0;
+}
diff --git a/tests/apis/add_files_replace/test.lua b/tests/apis/add_files_replace/test.lua
new file mode 100644
index 000000000..b57362078
--- /dev/null
+++ b/tests/apis/add_files_replace/test.lua
@@ -0,0 +1,3 @@
+function main(t)
+ t:build()
+end
diff --git a/tests/apis/add_files_replace/xmake.lua b/tests/apis/add_files_replace/xmake.lua
new file mode 100644
index 000000000..ee890c9f8
--- /dev/null
+++ b/tests/apis/add_files_replace/xmake.lua
@@ -0,0 +1,16 @@
+add_rules("mode.debug", "mode.release")
+
+-- test table replaces
+target("test")
+ set_kind("binary")
+ add_files("src/main.c", {rules = "utils.replace", replaces = {
+ {'"original"', '"replaced"'},
+ }})
+
+-- test function replaces
+target("test2")
+ set_kind("binary")
+ add_files("src/main.c", {rules = "utils.replace", replaces = function (content)
+ content = content:gsub('"original"', '"func_replaced"')
+ return content
+ end})