aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/singlejar/options_test.cc
blob: 0e4e66de9d797314becc6a9af67f8cf02899fbf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2016 The Bazel Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <memory>

#include "src/tools/singlejar/options.h"
#include "src/tools/singlejar/test_util.h"

#include "src/main/cpp/util/port.h"
#include "googletest/include/gtest/gtest.h"

TEST(OptionsTest, Flags1) {
  const char *args[] = {"--exclude_build_data",
                        "--compression",
                        "--normalize",
                        "--no_duplicates",
                        "--output", "output_jar"};
  Options options;
  options.ParseCommandLine(arraysize(args), args);

  EXPECT_TRUE(options.exclude_build_data);
  EXPECT_TRUE(options.force_compression);
  EXPECT_TRUE(options.normalize_timestamps);
  EXPECT_TRUE(options.no_duplicates);
  EXPECT_FALSE(options.preserve_compression);
  EXPECT_FALSE(options.verbose);
  EXPECT_FALSE(options.warn_duplicate_resources);
  EXPECT_FALSE(options.check_desugar_deps);
  EXPECT_EQ("output_jar", options.output_jar);
}

TEST(OptionsTest, Flags2) {
  const char *args[] = {"--dont_change_compression",
                        "--verbose",
                        "--warn_duplicate_resources",
                        "--check_desugar_deps",
                        "--output", "output_jar"};
  Options options;
  options.ParseCommandLine(arraysize(args), args);

  ASSERT_FALSE(options.exclude_build_data);
  ASSERT_FALSE(options.force_compression);
  ASSERT_FALSE(options.normalize_timestamps);
  ASSERT_FALSE(options.no_duplicates);
  ASSERT_TRUE(options.preserve_compression);
  ASSERT_TRUE(options.verbose);
  ASSERT_TRUE(options.warn_duplicate_resources);
  ASSERT_TRUE(options.check_desugar_deps);
}

TEST(OptionsTest, SingleOptargs) {
  const char *args[] = {"--output", "output_jar",
                        "--main_class", "com.google.Main",
                        "--java_launcher", "//tools:mylauncher",
                        "--build_info_file", "build_file1",
                        "--extra_build_info", "extra_build_line1",
                        "--build_info_file", "build_file2",
                        "--extra_build_info", "extra_build_line2"};
  Options options;
  options.ParseCommandLine(arraysize(args), args);

  EXPECT_EQ("output_jar", options.output_jar);
  EXPECT_EQ("com.google.Main", options.main_class);
  EXPECT_EQ("//tools:mylauncher", options.java_launcher);
  ASSERT_EQ(2, options.build_info_files.size());
  EXPECT_EQ("build_file1", options.build_info_files[0]);
  EXPECT_EQ("build_file2", options.build_info_files[1]);
  ASSERT_EQ(2, options.build_info_lines.size());
  EXPECT_EQ("extra_build_line1", options.build_info_lines[0]);
  EXPECT_EQ("extra_build_line2", options.build_info_lines[1]);
}

TEST(OptionsTest, MultiOptargs) {
    const char *args[] = {"--output", "output_file",
                        "--sources", "jar1", "jar2",
                        "--resources", "res1", "res2",
                        "--classpath_resources", "cpres1", "cpres2",
                        "--sources", "jar3",
                        "--include_prefixes", "prefix1", "prefix2",
                        "--nocompress_suffixes", ".png", ".so"};
  Options options;
  options.ParseCommandLine(arraysize(args), args);

  ASSERT_EQ(3, options.input_jars.size());
  EXPECT_EQ("jar1", options.input_jars[0].first);
  EXPECT_EQ("jar2", options.input_jars[1].first);
  EXPECT_EQ("jar3", options.input_jars[2].first);
  ASSERT_EQ(2, options.resources.size());
  EXPECT_EQ("res1", options.resources[0]);
  EXPECT_EQ("res2", options.resources[1]);
  ASSERT_EQ(2, options.classpath_resources.size());
  EXPECT_EQ("cpres1", options.classpath_resources[0]);
  EXPECT_EQ("cpres2", options.classpath_resources[1]);
  ASSERT_EQ(2, options.include_prefixes.size());
  EXPECT_EQ("prefix1", options.include_prefixes[0]);
  EXPECT_EQ("prefix2", options.include_prefixes[1]);
  EXPECT_EQ(2, options.nocompress_suffixes.size());
  EXPECT_EQ(".png", options.nocompress_suffixes[0]);
  EXPECT_EQ(".so", options.nocompress_suffixes[1]);
}

TEST(OptionsTest, EmptyMultiOptargs) {
  const char *args[] = {"--output", "output_file",
                        "--sources",
                        "--resources",
                        "--classpath_resources",
                        "--sources",
                        "--include_prefixes", "prefix1",
                        "--resources"};
  Options options;
  options.ParseCommandLine(arraysize(args), args);

  EXPECT_EQ(0, options.input_jars.size());
  EXPECT_EQ(0, options.resources.size());
  EXPECT_EQ(0, options.classpath_resources.size());
  EXPECT_EQ(1, options.include_prefixes.size());
}